-1

In the notifications app is not registred for son and badge.

This is my code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
{
    //-- Set Notification
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.000000) {
        UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
        //[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }

Someone has an explanation? Thank you

wjl
  • 7,143
  • 1
  • 30
  • 49
dev1001
  • 23
  • 7

3 Answers3

1

iOS 8 need some change in push notification delegate methods and explained clearly in this link

Also don't call registerForRemoteNotifications for iOS 8 because its deprecated.

Community
  • 1
  • 1
0

Hi please use this code,

       #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
        } else {
            [[UIApplication sharedApplication]
             registerForRemoteNotificationTypes:
             (UIRemoteNotificationTypeAlert |
              UIRemoteNotificationTypeBadge |
              UIRemoteNotificationTypeSound)];
        }
    #else
        [[UIApplication sharedApplication]
         registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeAlert |
          UIRemoteNotificationTypeBadge |


 UIRemoteNotificationTypeSound)];
#endif

and for delegate methods,

  #pragma mark - Push Notification

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    // Prepare the Device Token for Registration (remove spaces and < >)
    NSString *TokenID = [[[[deviceToken description]
                           stringByReplacingOccurrencesOfString:@"<"withString:@""]
                          stringByReplacingOccurrencesOfString:@">" withString:@""]
                         stringByReplacingOccurrencesOfString: @" " withString: @""];


    [ApplicationPreferences setTokenId:TokenID];
    if (DEBUG_MODE) {
        NSLog(@"device token - %@",[NSString stringWithFormat:@"Device Token = %@",TokenID]);
        NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
        NSLog(@"Vendor token - %@",[NSString stringWithFormat:@"Device Token = %@",[oNSUUID UUIDString]]);
    }

}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    if (DEBUG_MODE) {
        NSLog(@"Push Error- %@",[NSString stringWithFormat: @"Error: %@", err]);
    }
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

}
Banker Mittal
  • 1,918
  • 14
  • 26
-1

In the iOS 8 version you forgot the brackets

(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)
Beninho85
  • 3,273
  • 27
  • 22
  • I already tried like that. That changes nothing. In notification i dont have sounds and badges enable. – dev1001 Sep 23 '14 at 19:55