Advertisement
slxl

UCAppDelegate (Notifications)

Jan 15th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  2.    
  3.     if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) ) {
  4.        
  5.         [[UIApplication sharedApplication] registerForRemoteNotifications];
  6.        
  7.     } else {
  8.        
  9.         UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  10.         center.delegate = self;
  11.         [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
  12.          {
  13.              if( !error ) {
  14.                  [[UIApplication sharedApplication] registerForRemoteNotifications];  // required to get the app to do anything at all about push notifications
  15.               } else {
  16.                  NSLog( @"Push registration FAILED" );
  17.                  NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
  18.                  NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
  19.              }
  20.          }];
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement