Skip to content

Instantly share code, notes, and snippets.

@jeffreycamealy
Last active April 3, 2017 13:45
Show Gist options
  • Save jeffreycamealy/5104279 to your computer and use it in GitHub Desktop.
Save jeffreycamealy/5104279 to your computer and use it in GitHub Desktop.
Urban Airship AppDelegate initialization code
#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];
}
@DanByDay
Copy link

DanByDay commented Mar 6, 2013

This is the shit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment