Search code examples
iosios6ios7apple-push-notifications

Push notifications don't work in iOS7 but they work in iOS6


I'm having problems with push notifications in iOS7.

I have developed an application for iOS6 and push notifications works very well. But, when I put that app in a iOS7 device, it doesn't run.

But something very strange happen. If I use Development key, my iOS7 device can receive push, but with Production key, It can't.

I can get my devide token for push but it is not able to receive anything.

Any idea?

This is my code:

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // PUSH-CODE
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    ....
}

// PUSH-CODE
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{    
    NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"Token: %@", token);

    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"deviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

Solution

  • Just did a Google search for "ios7 push notification not working" since your question was only the 3rd I know already the response. It is not your fault, but Apple's one. The user need to connect they phone to iTunes to receive pushes. Sometimes hard factory reset, sometimes just turn off the device.

    • iOSX.0 is a "come test it"
    • iOSX.1 is a "we tried to fix some bugs, based on your flames"
    • iOSX.2 stable, you are free to develop, anyhow in 3 month we have the next X.0 version :)