2017-02-22 87 views
2

在我的應用我啓用遠程通知,如何禁用iOS遠程通知上的默認通知警報視圖?

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")){ 
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
    center.delegate = self; 
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ 
     if(!error){ 
      [[UIApplication sharedApplication] registerForRemoteNotifications]; 
     } 
    }]; 
}else{ 
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil]; 
    [application registerUserNotificationSettings:settings]; 
    [application registerForRemoteNotifications]; 
} 

我實現的委託方法如下,

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ 
    NSLog(@"Failed!!"); 
} 


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
    // Print message. 
    if (userInfo) { 
     NSLog(@"Message ID: %@", userInfo); 
    } 

    completionHandler(UIBackgroundFetchResultNoData); 
} 

但是,當應用程序在前臺和接收通知,我買了一個UIAlertView中通知標題和消息。我想要

//Called when a notification is delivered to a foreground app. 
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ 
    NSLog(@"User Info : %@",notification.request.content.userInfo); 
    completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionBadge); 
} 

//Called to let your app know which action was selected by the user for a given notification. 
-(void)userNotificationCenter:(UNUserNotificationCenter *)center  didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ 
    NSLog(@"User Info : %@",response.notification.request.content.userInfo); 
    completionHandler(); 
} 

我在willPresentNotification:上調試,之後觸發我得到了警報。我也通過刪除這種方法進行測試。但收到通知時仍會顯示此警報。

如何禁用此警報視圖?我使用的是10.2的iOS在我的iPhone

enter image description here

+0

你是什麼意思禁用?根本看不到警報?!你的意思是將其轉換爲無聲推動? – Honey

+0

是的。沒有看到警報。 – codebot

+0

「你的意思是把它轉換成無聲推動?」是。我不需要顯示警報 – codebot

回答

1

我不認爲UIAlertController來自通知。你確定你沒有在別處創建一個嗎?

您的通知的實施似乎沒問題。

您可以在您的項目中搜索並使用斷點來查看您的UIAlertController中的任何一個是否受到攻擊?

+0

我搜索了很多。但是,這發生.. – codebot

+0

你可以CMD + Shift + F(全球項目研究)爲這個AlertView的每一個線索。例如,您可以搜索「initWithTitle:」Alert「」或「message:」Alert「」。任何事情爲了找到這個AlertView。 – Balanced

+0

我做到了。但是,您沒有爲所有AlertController嘗試使用 – codebot