GDTCORPlatform.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #import <SystemConfiguration/SystemConfiguration.h>
  18. #if TARGET_OS_IOS || TARGET_OS_TV
  19. #import <UIKit/UIKit.h>
  20. #elif TARGET_OS_OSX
  21. #import <AppKit/AppKit.h>
  22. #endif // TARGET_OS_IOS || TARGET_OS_TV
  23. NS_ASSUME_NONNULL_BEGIN
  24. /** The GoogleDataTransport library version. */
  25. FOUNDATION_EXPORT NSString *const kGDTCORVersion;
  26. /** A notification sent out if the app is backgrounding. */
  27. FOUNDATION_EXPORT NSString *const kGDTCORApplicationDidEnterBackgroundNotification;
  28. /** A notification sent out if the app is foregrounding. */
  29. FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillEnterForegroundNotification;
  30. /** A notification sent out if the app is terminating. */
  31. FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillTerminateNotification;
  32. /** Compares flags with the WWAN reachability flag, if available, and returns YES if present.
  33. *
  34. * @param flags The set of reachability flags.
  35. * @return YES if the WWAN flag is set, NO otherwise.
  36. */
  37. BOOL GDTCORReachabilityFlagsContainWWAN(SCNetworkReachabilityFlags flags);
  38. /** A typedef identify background identifiers. */
  39. typedef volatile NSUInteger GDTCORBackgroundIdentifier;
  40. /** A background task's invalid sentinel value. */
  41. FOUNDATION_EXPORT const GDTCORBackgroundIdentifier GDTCORBackgroundIdentifierInvalid;
  42. #if TARGET_OS_IOS || TARGET_OS_TV
  43. /** A protocol that wraps UIApplicationDelegate or NSObject protocol, depending on the platform. */
  44. @protocol GDTCORApplicationDelegate <UIApplicationDelegate>
  45. #elif TARGET_OS_OSX
  46. @protocol GDTCORApplicationDelegate <NSApplicationDelegate>
  47. #else
  48. @protocol GDTCORApplicationDelegate <NSObject>
  49. #endif // TARGET_OS_IOS || TARGET_OS_TV
  50. @end
  51. /** A cross-platform application class. */
  52. @interface GDTCORApplication : NSObject <GDTCORApplicationDelegate>
  53. /** Flag to determine if the application is running in the background. */
  54. @property(atomic, readonly) BOOL isRunningInBackground;
  55. /** Creates and/or returns the shared application instance.
  56. *
  57. * @return The shared application instance.
  58. */
  59. + (nullable GDTCORApplication *)sharedApplication;
  60. /** Creates a background task with the returned identifier if on a suitable platform.
  61. *
  62. * @name name The name of the task, useful for debugging which background tasks are running.
  63. * @param handler The handler block that is called if the background task expires.
  64. * @return An identifier for the background task, or GDTCORBackgroundIdentifierInvalid if one
  65. * couldn't be created.
  66. */
  67. - (GDTCORBackgroundIdentifier)beginBackgroundTaskWithName:(NSString *)name
  68. expirationHandler:(void (^__nullable)(void))handler;
  69. /** Ends the background task if the identifier is valid.
  70. *
  71. * @param bgID The background task to end.
  72. */
  73. - (void)endBackgroundTask:(GDTCORBackgroundIdentifier)bgID;
  74. @end
  75. NS_ASSUME_NONNULL_END