设备令牌未生成的推送通知

发布于 2025-02-06 21:40:39 字数 1828 浏览 9 评论 0 原文

几天以来,我无法收到一个应用程序的推送通知。我的外观仔细,看来它无法生成设备令牌。我能够使用空白的应用程序和以下代码(或SWIFT等价)复制它:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            NSLog(@"Granted.");
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
        } else {
            NSLog(@"Not granted.");
        }
    }];
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Token: %@", deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"Error: %@", error);
}

将通知添加到应用程序的功能中(我已将团队名称和一部分证书描述):

这生成了以下授权文件:

​rel =“ nofollow noreferrer”> “在此处输入映像说明”

该应用程序到达'grided'block:

2022-06-12 19:55:28.665018+0200 Sandbox[1704:108535] Granted.

,并且 我既不看到设备令牌,也不看到日志中的错误。

Since a few days, I am unable to receive push notifications for one of my apps. I had a closer look and it seems it doesn't manage to generate a device token. I was able to reproduce it with a blank application and the following code (or the Swift equivalent):

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            NSLog(@"Granted.");
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
        } else {
            NSLog(@"Not granted.");
        }
    }];
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Token: %@", deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"Error: %@", error);
}

Push notifications were added to the app's capabilities (I've blanked out the team name and part of the certificate description):

enter image description here

and this generated the following entitlements file:

enter image description here

When the app launches, I get the usual popup:

enter image description here

and the app reaches the 'Granted' block:

2022-06-12 19:55:28.665018+0200 Sandbox[1704:108535] Granted.

but I see neither a device token nor an error in the log.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文