繁体   English   中英

无法在iOS 8中获取设备令牌

[英]Not able to get Device Token in ios 8

我没有方法

didRegisterForRemoteNotificationsWithDeviceToken

实际上我想获取设备令牌,并且我尝试遵循此问题在iOS 8中获取设备令牌,但仍然面临相同的问题。请帮助我解决此问题

尝试这个。

用你的方法。

  • (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

使用此代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }

然后将日志或断点

didRegisterForRemoteNotificationsWithDeviceToken

被叫与否。

而且,如果您的应用已正确注册了远程通知设置,但仍未获得设备令牌,则

校验

didFailToRegisterForRemoteNotificationsWithError

会告诉您哪个错误的方法。

注意:仅当在设备上运行时,设备令牌才会返回。 OS Simulator不支持推送通知

然后,如果您无法调用此方法,请查看本教程

http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

并按照创建供应配置文件和证书的步骤进行操作。 我尝试使用现有证书。 按照本教程系列中的说明使用有效配置文件运行应用程序之后,您将能够调用该方法。

在iOS 8中有多种获取设备令牌的方法。

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else{
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }

问题是我的公司网络中存在某种限制,因此当我使用不在公司网络中的wifi设备时,我的代码可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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