UIUserNotificationSettingsでiOS通知設定確認
アプリの通知について、インストール初回に許可を請うと思いますが、
その後ユーザがどのような設定になっているのかを確認したい場合って結構あると思います。
その場合のサンプルの備忘録を残しておきます。
今回、「UIUserNotificationSettings」を使ってステータスを確認したいと思いますが、こちらはiOS8からのものなので、一旦iOSのバージョンをチェックします。
currentSettings.typesがどの値が入ってくるかによって判断します。
+ (BOOL)checkPermissionOfNotification { NSInteger _iOsVersionMajor = [[[[[UIDevice currentDevice]systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue]; if (_iOsVersionMajor >= 8) { UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; //通知オフの場合だけでなく、通知サウンドオフの場合も if((currentSettings.types==0) || (currentSettings.types==4) || (currentSettings.types==5)) { //アラートを出してみる [self showAlertview:@"通知設定が未許可です。\n設定 > 通知 > で通知を許可してください。"]; return false; } } return true; }
currentSettings.types=0 >>> 通知off , sound - , aicon -
currentSettings.types=4 >>> 通知on , soundOff , aiconOff
currentSettings.types=5 >>> 通知on , soundOff , aiconOn
currentSettings.types=6 >>> 通知on , soundOn , aiconOff
currentSettings.types=7 >>> 通知on , soundOn , aiconOn