GDTCORPlatform.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #if !TARGET_OS_WATCH
  18. #import <SystemConfiguration/SystemConfiguration.h>
  19. #endif
  20. #if TARGET_OS_IOS || TARGET_OS_TV
  21. #import <UIKit/UIKit.h>
  22. #elif TARGET_OS_OSX
  23. #import <AppKit/AppKit.h>
  24. #endif // TARGET_OS_IOS || TARGET_OS_TV
  25. NS_ASSUME_NONNULL_BEGIN
  26. /** The GoogleDataTransport library version. */
  27. FOUNDATION_EXPORT NSString *const kGDTCORVersion;
  28. /** A notification sent out if the app is backgrounding. */
  29. FOUNDATION_EXPORT NSString *const kGDTCORApplicationDidEnterBackgroundNotification;
  30. /** A notification sent out if the app is foregrounding. */
  31. FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillEnterForegroundNotification;
  32. /** A notification sent out if the app is terminating. */
  33. FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillTerminateNotification;
  34. #if !TARGET_OS_WATCH
  35. /** Compares flags with the WWAN reachability flag, if available, and returns YES if present.
  36. *
  37. * @param flags The set of reachability flags.
  38. * @return YES if the WWAN flag is set, NO otherwise.
  39. */
  40. BOOL GDTCORReachabilityFlagsContainWWAN(SCNetworkReachabilityFlags flags);
  41. #endif
  42. /** A typedef identify background identifiers. */
  43. typedef volatile NSUInteger GDTCORBackgroundIdentifier;
  44. /** A background task's invalid sentinel value. */
  45. FOUNDATION_EXPORT const GDTCORBackgroundIdentifier GDTCORBackgroundIdentifierInvalid;
  46. #if TARGET_OS_IOS || TARGET_OS_TV
  47. /** A protocol that wraps UIApplicationDelegate or NSObject protocol, depending on the platform. */
  48. @protocol GDTCORApplicationDelegate <UIApplicationDelegate>
  49. #elif TARGET_OS_OSX
  50. @protocol GDTCORApplicationDelegate <NSApplicationDelegate>
  51. #else
  52. @protocol GDTCORApplicationDelegate <NSObject>
  53. #endif // TARGET_OS_IOS || TARGET_OS_TV
  54. @end
  55. /** A cross-platform application class. */
  56. @interface GDTCORApplication : NSObject <GDTCORApplicationDelegate>
  57. /** Flag to determine if the application is running in the background. */
  58. @property(atomic, readonly) BOOL isRunningInBackground;
  59. /** Creates and/or returns the shared application instance.
  60. *
  61. * @return The shared application instance.
  62. */
  63. + (nullable GDTCORApplication *)sharedApplication;
  64. /** Creates a background task with the returned identifier if on a suitable platform.
  65. *
  66. * @name name The name of the task, useful for debugging which background tasks are running.
  67. * @param handler The handler block that is called if the background task expires.
  68. * @return An identifier for the background task, or GDTCORBackgroundIdentifierInvalid if one
  69. * couldn't be created.
  70. */
  71. - (GDTCORBackgroundIdentifier)beginBackgroundTaskWithName:(NSString *)name
  72. expirationHandler:(void (^__nullable)(void))handler;
  73. /** Ends the background task if the identifier is valid.
  74. *
  75. * @param bgID The background task to end.
  76. */
  77. - (void)endBackgroundTask:(GDTCORBackgroundIdentifier)bgID;
  78. @end
  79. NS_ASSUME_NONNULL_END