簡體   English   中英

iOS10-調用userNotificationCenter didReceiveNotificationResponse延遲10秒

[英]iOS10 - userNotificationCenter didReceiveNotificationResponse called with a 10sec delay

我剛剛使用以下代碼升級了為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];
    }
}

}

我的所有代表都在我的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時凍結的主線程的屏幕截圖: 在此處輸入圖片說明

您的堆棧跟蹤中有些奇怪的東西。 semaphore_wait_trapsemaphore_wait_slow 嘗試看看這里這里這里 話雖這么說,我的猜測是您正在從錯誤的線程調用您的(void)registerForNotifications ,並導致了此問題。

另外,我不明白為什么您的實現中會有一個dispatch_async(dispatch_get_main_queue 。這似乎是不必要的。嘗試從這里查看答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM