简体   繁体   中英

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);
}

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 :)

I solve this problem by changing the app's push setting in push center. just close and then open

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM