iOS推送通知 - 删除并重新安装后无需推送

时间:2014-05-19 13:58:25

标签: ios apple-push-notifications

我已经在我的应用程序中进行了工作,它正处于开发阶段,可以在应用程序启动后从存储在数据库中的PHP脚本发送推送。 但是在禁用并重新启用push in den Message-Center(在iPhone上测试)或删除并重新安装(在iPad上测试)应用程序后,我无法再次推送到这些设备。我收到了这些设备的新令牌,并从我的数据库中删除了旧令牌。 我的用于接收可删除令牌的php脚本(feedback.sandbox.push.apple.com:2196)不会向我返回任何信息,虽然连接似乎没问题。

我打电话

[[UIApplication sharedApplication]  registerForRemoteNotificationTypes:
    (UIRemoteNotificationTypeBadge |
    UIRemoteNotificationTypeSound |
    UIRemoteNotificationTypeAlert)];

每次应用启动时,应用程序始终在

中顺利注册
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)aDeviceToken;

我可以看到它,因为我当时是一个NSLog,wichs会显示令牌

这是我的代码:

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

-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Registered device with token %@", deviceToken); //Here i'm writing token into Database if not exists
}

-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"Registering device failed: %@", error);
}

我该怎么办?

Thnx&此致

德克

1 个答案:

答案 0 :(得分:0)

每次应用程序完成启动时,您应该要求推送注册:

[[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert)];

然后检查回调是否返回此函数:

 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)aDeviceToken;

或此功能:

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

如果没有注册,请检查原因并发表评论