在我的應用我啓用遠程通知,如何禁用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
你是什麼意思禁用?根本看不到警報?!你的意思是將其轉換爲無聲推動? – Honey
是的。沒有看到警報。 – codebot
「你的意思是把它轉換成無聲推動?」是。我不需要顯示警報 – codebot