私は、リモート通知を有効に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:
でデバッグした後、私は警告を受け取りました。そして私はこの方法も取り除いてテストしました。しかし、このアラートは通知を受け取ったときに表示されます。
このアラートビューを無効にするにはどうすればよいですか?私はUIAlertController
、通知から来ているとは思わない、私のiPhone
無効にすることはどういう意味ですか?警報はまったく見ない?それを静かなプッシュに変換することを意味しますか? – Honey
はい。アラートは表示されません。 – codebot
「サイレントプッシュに変換することを意味しますか?」はい。私は警告を表示する必要はありません – codebot