Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation AppDelegate
- - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Step 1: Register for user notifications
- UIUserNotificationType types= UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
- UIUserNotificationSettings *mySettings= [UIUserNotificationSettings settingsForTypes:types categories:nil];
- [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
- }
- - (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
- // Step 2: Register for remote notifications
- [application registerForRemoteNotifications];
- }
- - (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- // Step 3: Convert the token to a string
- NSString *token= [[[deviceToken description]
- stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
- stringByReplacingOccurrencesOfString:@" " withString:@""];
- /* Step 4: This call will:
- * - Check on LSUserDefaults if a previous token has been saved
- * - Save the current token on LSUserDefaults
- * - Initialize the LSMPNDevice object with the previous and current tokens
- */
- LSMPNDevice *device= [[LSMPNDevice alloc] initWithDeviceToken:token];
- // The LSMPNDevice object is initialized and ready for use
- }
- - (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- // Something went wrong
- }
- @end
Add Comment
Please, Sign In to add comment