gpt4 book ai didi

objective-c - 为什么不调用 didRegisterForRemoteNotificationsWithDeviceToken

转载 作者:IT老高 更新时间:2023-10-28 11:22:23 28 4
gpt4 key购买 nike

我正在制作一个我想在其中实现苹果推送通知服务的应用程序。我正在按照 this tutorial 中给出的分步说明进行操作。 .

但是,这些方法仍然没有被调用。我不知道是什么导致了问题。谁能帮帮我?

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
//NSString * token = [[NSString alloc] initWithData:deviceTokenencoding:NSUTF8StringEncoding];
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"Device Token:%@",str);

//NSLog(@"Device token is called");
//const void *devTokenBytes = [deviceToken bytes];
//NSLog(@"Device Token");
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error:%@",str);
}

最佳答案

我遇到了同样的问题:调用 registerForRemoteNotificationTypes: 既没有调用 application:didRegisterForRemoteNotificationsWithDeviceToken: 也没有调用 application:didFailToRegisterForRemoteNotificationsWithError:

我最终在 Apple 的技术说明 TN2265 的帮助下解决了这个问题.

这就是我所做的:

首先,我再次确认我确实是 registering correctly for Push Notifications ,包括验证我的“aps-environment” key 的配置文件和 .app 文件本身的代码签名。我都设置正确了。

然后我不得不在控制台中调试推送通知状态消息(您需要在您的设备上安装 PersistentConnectionLogging.mobileconfig 配置文件并重新启动它。参见“观察推送状态消息”下的 TN2265)。我注意到 apns 进程启动了一个计时器并计算了一个最小触发日期,这让我怀疑通常此时呈现的 Push-Notification 注册确认消息被 APNS 抑制,如 TN2265 所示:

Resetting the Push Notifications Permissions Alert on iOS

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.

因此,我从设备中删除了该应用,然后在“设置”中手动更改了 iPhone 的日期,重新启动了设备,然后重新安装了该应用。

下次我的代码调用 registerForRemoteNotificationTypes 时,它按预期收到了回调。

这为我解决了这个问题。希望对您有所帮助。

关于objective-c - 为什么不调用 didRegisterForRemoteNotificationsWithDeviceToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4086599/

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