gpt4 book ai didi

iOS10 - userNotificationCenter didReceiveNotificationResponse 调用延迟 10 秒

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:12:52 33 4
gpt4 key购买 nike

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

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

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

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

- (void)applicationWillEnterForeground:(UIApplication *)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)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

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

我怎样才能避免这种卡住应用程序的巨大延迟?

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

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

最佳答案

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

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

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

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