Guest User

Untitled

a guest
Jan 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. @implementation AppDelegate
  2.  
  3. - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  4.  
  5. // Step 1: Register for user notifications
  6. UIUserNotificationType types= UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
  7. UIUserNotificationSettings *mySettings= [UIUserNotificationSettings settingsForTypes:types categories:nil];
  8.  
  9. [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
  10. }
  11.  
  12. - (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  13.  
  14. // Step 2: Register for remote notifications
  15. [application registerForRemoteNotifications];
  16. }
  17.  
  18. - (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  19.  
  20. // Step 3: Convert the token to a string
  21. NSString *token= [[[deviceToken description]
  22. stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
  23. stringByReplacingOccurrencesOfString:@" " withString:@""];
  24.  
  25. /* Step 4: This call will:
  26. * - Check on LSUserDefaults if a previous token has been saved
  27. * - Save the current token on LSUserDefaults
  28. * - Initialize the LSMPNDevice object with the previous and current tokens
  29. */
  30. LSMPNDevice *device= [[LSMPNDevice alloc] initWithDeviceToken:token];
  31.  
  32. // The LSMPNDevice object is initialized and ready for use
  33. }
  34.  
  35. - (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  36.  
  37. // Something went wrong
  38. }
  39.  
  40. @end
Add Comment
Please, Sign In to add comment