开发Apple推送通知不适用于iOS; didRegisterForRemoteNotificationsWithDeviceToken未调用

时间:2016-04-27 05:47:15

标签: ios ios7 push-notification apple-push-notifications devicetoken

我有一个适用于iOS 7及更高版本的应用。 Apple Push Notifications昨天在开发模式下工作,但现在还没有。

我正在注册这样的推送通知:

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        //enabled =  [application isRegisteredForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
        //UIRemoteNotificationType types = [application enabledRemoteNotificationTypes];
        //enabled = types & UIRemoteNotificationTypeAlert;

    }

// Delegate methods are

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications

    [application registerForRemoteNotifications];
}

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

    NSString *newToken = [deviceToken description];

    newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];

    newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];

    self.myDeviceToken = newToken;
    [CLServerDataManager setDeviceToken:newToken];

}

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

#if TARGET_IPHONE_SIMULATOR
    NSLog(@"Failed to get token, error: %@", error);
    [CLServerDataManager setDeviceToken:@"dummy"];
    self.myDeviceToken = @"dummy";
#endif

}

推送通知一直工作到最后一天。证书是根据www.raywenderlich.com网站制作的。

但现在我注意到了这些方法:

didRegisterForRemoteNotificationsWithDeviceToken:
didFailToRegisterForRemoteNotificationsWithError

没有被调用,我没有获得设备令牌。

我也在尝试这段代码:

NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
NSString *deviceId = [identifierForVendor UUIDString];

......两者都不起作用。

请让我知道可能是什么问题。提前谢谢。

0 个答案:

没有答案