Last active
April 3, 2017 13:45
-
-
Save jeffreycamealy/5104279 to your computer and use it in GitHub Desktop.
Urban Airship AppDelegate initialization code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UAirship.h" | |
#import "UAPush.h" | |
============================ | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[self setupUrbanAirshipForApplication:application withLaunchOptions:launchOptions]; | |
return YES; | |
} | |
- (void)applicationWillTerminate:(UIApplication *)application { | |
[UAirship land]; | |
} | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
// Updates the device token and registers the token with UA | |
[[UAPush shared] registerDeviceToken:deviceToken]; | |
} | |
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { | |
NSLog(@"Application failed to register for remote notifications with error: %@", error); | |
} | |
- (void)setupUrbanAirshipForApplication:(UIApplication *)application withLaunchOptions:(NSDictionary *)launchOptions { | |
// Create UA dict and add required UIApplication launchOptions | |
// Note: setValue:forKey: because launchOptions may be nil | |
NSMutableDictionary *takeOffOptions = [NSMutableDictionary dictionary]; | |
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey]; | |
// takeOff creates UA singleton | |
// launch options notify server if launch is from push notification | |
[UAirship takeOff:takeOffOptions]; | |
// Set icon badge to zero | |
[[UAPush shared] resetBadge]; | |
// Required | |
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; | |
// Handle incoming push notificaiton | |
// Will call 'handleBackgroundNotificaiton' on my UAPushNotificationDelegate | |
[[UAPush shared] handleNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] | |
applicationState:application.applicationState]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the shit!