• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS10 - 延迟 10 秒调用 userNotificationCenter didReceiveNotificationResponse

[复制链接]
菜鸟教程小白 发表于 2022-12-11 19:19:48 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我刚刚升级了注册 iOS 10 的整个 iOS 推送通知,使用以下代码:

-(void)registerForNotifications{
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptionsUNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        dispatch_async(dispatch_get_main_queue(), ^(void){
            if(!error){
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            }
        });
    }];
}
else {
    if ([[UIApplication sharedApplication] respondsToSelectorselector(registerUserNotificationSettings])
    {
        UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
}

}

我的所有委托(delegate)都设置在我的 AppDelegate 中。

编辑:我现在能够进一步确定问题所在。当应用在通知推送后返回前台时,委托(delegate):

- (void)applicationWillEnterForegroundUIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

仅在大约 10-15 秒后调用,而通常它显然是立即调用的。这怎么可能?

我现在正在使用 Localytics 测试推送通知并实现:

- (void)userNotificationCenterUNUserNotificationCenter *)center didReceiveNotificationResponseUNNotificationResponse *)response withCompletionHandlervoid (^)())completionHandler {

在我的 AppDelegate 中用于深度链接。当我添加断点时,我看到发生了这种情况: 我正确收到了推送通知,点击它,应用程序 UI 卡住了大约 10 秒。最后,调用 didReceiveNotificationResponse 并进行深度链接。

如何避免导致应用卡住的巨大延迟?

编辑:它甚至比我更糟糕。当我将 iPhone 连接到 xCode 并在手机上运行构建时,它会在工作前卡住十秒钟。然后,如果我只是运行完全相同的构建而不在 xCode 上运行它(所以没有断点),应用程序会卡住 10 秒然后崩溃。

编辑:这是我的主线程在 xCode 卡住时暂停时的屏幕截图: enter image description here



Best Answer-推荐答案


您的堆栈跟踪中有一些奇怪的东西。 semaphore_wait_trapsemaphore_wait_slow。试试看hereherehere .话虽这么说,我的猜测是你从错误的线程调用你的 (void)registerForNotifications 并且它导致了这个问题。

另外,我不明白为什么您的实现中有 dispatch_async(dispatch_get_main_queue。它似乎没有必要。尝试查看 here 中的答案

关于iOS10 - 延迟 10 秒调用 userNotificationCenter didReceiveNotificationResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42951136/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap