iOS 设备 token 回调从未被调用

标签 ios xcode

在尝试在我的应用程序中提取设备 token 时,我遇到了一些重大麻烦。到目前为止,我已经

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    //register for push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

然后

-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWith:DeviceToken:(NSData *)deviceToken 
{
    NSString *str = [deviceToken description]; 
    NSLog(@"%@", str); 
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

这是交易。

我的 iOS 模拟器:我明白了

 Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x5813d20 {NSLocalizedDescription=remote notifications are not supported in the simulator}

正如预期的那样。

在我的运行 iOS 4.2 的第二代 iPod Touch 上,两个回调都没有被调用。我的同事运行 iOS 5.1.1 的 iPhone 4s 也出现了同样的情况

最后,在另一位同事运行 iOS.5.1.1 的 iPhone 4 上,似乎返回设备 token 是“com.apple.mobileconfig”...这很奇怪。

我已验证我的设备上的应用已启用通知。我还验证了我的应用程序标识符包在 xCode 中设置正确。

编辑:我不知道发生了什么,但是,发布此帖子几天后,我将 iPhone 4 插入我的 Mac,设备 token 回调刚刚开始在 Debug模式下工作,并且然后也在其他人的设备上。我对配置文件做了一些更改(必须添加新设备的 UDID 等),这样可能会消除一些小问题。不太确定。

EDIT2: didRegister 回调中似乎有一个额外的冒号,位于 DeviceToken ...

之前

最佳答案

来自Technical Note TN2265 Troubleshooting Push Notifications (强调我的):

No Delegate Callbacks

When the first push-capable app is installed, iOS or Mac OS X attempts to establish a persistent network connection to the push service that will be shared by all push-capable apps on the system. If neither delegate callback application:didRegisterForRemoteNotificationsWithDeviceToken: nor application:didFailToRegisterForRemoteNotificationsWithError: is called, that means that this connection has not yet been established.

This is not necessarily an error condition. The system may not have Internet connectivity at all because it is out of range of any cell towers or Wi-Fi access points, or it may be in airplane mode. Instead of treating this as an error, your app should continue normally, disabling only that functionality that relies on push notifications.

Keep in mind that network availability can change frequently. Once the persistent connection to the push service succeeds, one of the previously-mentioned application delegate methods will be called.

关于iOS 设备 token 回调从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10873877/

相关文章:

iphone - 在 Progress View 上绘制图像

iphone - iPhone 视频通话/ session API

swift - 导航 Controller 未释放内存,内存泄漏?

ios - xcode-命令行生成-平台watchOS所需的内容丢失了IBBuildSupport

cocoa - NSMenuItem 自定义 View 不响应 keyEquivalent

ios - UITextField 中的生日日期并检查年龄

iphone - 如何在所有应用程序上接收重大位置更改,而不是仅在一个 View 上接收?

ios - xcode 6 应用程序提交失败,出现 iTunes 商店操作问题

ios - HTML5 视频标签在 iOS 上不可靠

xcode - XCode- objective-c :删除表行崩溃