2017-02-22 48 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

я сделал. Но нет таких предупреждений, как – codebot