Apple 推送通知:未收到设备令牌? [英] Apple Push Notifications: Not receiving device token?

查看:33
本文介绍了Apple 推送通知:未收到设备令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在涉及推送通知的应用程序中,我收到设备令牌就好了,但我客户端的设备没有收到设备令牌(因此导致无法接收推送通知).我正在使用 Parse 进行推送通知.这是我在 AppDelegate 中的内容:

In an app which involves push notifications, I am receiving device tokens just fine but the my client's device doesn't receive device token (hence causing failure to receive push notifications). I am using Parse for push notifications. This is what I have in my AppDelegate:

-(void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:newDeviceToken];
    PFACL *objectACL = [[PFACL alloc] init];
    [objectACL setPublicReadAccess:YES];
    [objectACL setPublicWriteAccess:YES];

    [currentInstallation saveInBackground];
}

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

    NSString *errorString = [NSString stringWithFormat:@"%@", error];
    UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [errorAlertView show];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [application registerForRemoteNotifications];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [Parse setApplicationId:PARSE_APPLICATION_ID
                  clientKey:PARSE_CUSTOMER_KEY];
    [PFFacebookUtils initializeFacebook];

    [self.window makeKeyAndVisible];

    // create the Login controller instance:

    [application registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeSound];
}

客户端没有收到任何表示注册 APN 失败的 UIAlert,这意味着 didFailToRegisterForRemoteNotificationsWithError 没有被调用.我已经尝试从我的解析服务器中删除所有安装,删除应用程序 &按照 Apple 技术说明 TN2265 的指南重新安装.该应用程序不会在首次启动时提示客户端授权推送通知也不会出现在通知中心(这很令人困惑,因为 didRegisterUserNotificationSettings: 也在那里).但是这一切在我的 iPad、iPhone 5S、iPod 5、iPhone 4s 上都运行良好.任何想法可能导致此设备在应用程序中设备变量行为?!这是 sc 客户端发送给我的.通知中心屏幕截图

Client doesn't receive any UIAlert representing failure of registration with APN so that means didFailToRegisterForRemoteNotificationsWithError is not being called. I have tried removing all installations from my parse server, removing the app & reinstalling again as per guidelines of Apple technical note TN2265. The application doesn't prompt the client for authorization of push notifications on first launch & doesn't appear in notification center either (Which is baffling because didRegisterUserNotificationSettings: is there too). But all this is working fine on my iPad, iPhone 5S, iPod 5, iPhone 4s. Any ideas what Might be causing this device to device variable behavior in the app?!This is the sc client sent me.notificationCenterScreenShot

推荐答案

试试下面的代码

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法在你的 AppDelegate 类中

within - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method in your AppDelegate class

这篇关于Apple 推送通知:未收到设备令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆