gpt4 book ai didi

从未调用过 iOS 设备 token 回调

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:25 24 4
gpt4 key购买 nike

在我的应用程序中尝试提取设备 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}

正如预期的那样。

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

最后,在另一个运行 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com