UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
notificationTypes
リモート通知が有効になっているものを見つけるのに役立つ整数コードがあります。そのためには、 を理解する必要がありますUIRemoteNotificationType
。
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
} UIRemoteNotificationType;
ビット単位の左シフト計算によると、次の値になります。
- UIRemoteNotificationTypeNone = 0
- UIRemoteNotificationTypeBadge = 1
- UIRemoteNotificationTypeSound = 2
- UIRemoteNotificationTypeAlert = 4
- UIRemoteNotificationTypeNewsstandContentAvailability = 8
次のコードは、アプリで有効になっているリモート通知を見つけるのに役立ちます。
if (notificationTypes == UIRemoteNotificationTypeNone) {
// Do what ever you need to here when notifications are disabled
NSLog(@"User doesn't want to receive push-notifications");
} else if (notificationTypes == UIRemoteNotificationTypeBadge) {
// Badge only
NSLog(@"Badges Only");
} else if (notificationTypes == UIRemoteNotificationTypeAlert) {
// Alert only
NSLog(@"Alerts only");
} else if (notificationTypes == UIRemoteNotificationTypeSound) {
// Sound only
NSLog(@"Sound Only");
}
else if (notificationTypes == UIRemoteNotificationTypeNewsstandContentAvailability) {
// NewsstandContentAvailability only
NSLog(@"NewsstandContentAvailability Only");
}else if (notificationTypes == 5)//Badge(1)+Alert(4)=5 {
// Badge & Alert
NSLog(@"Badges and Alert");
} else if (notificationTypes == 3)//Badge(1)+Sound(2)=3 {
// Badge & Sound
NSLog(@"Badges and Sound");
} else if (notificationTypes == 6)//Alert(4)+Sound(2)=6 {
// Alert & Sound
NSLog(@"Alert and Sound");
} else if (notificationTypes == 7)//Badge(1)+Alert(4)+Sound(2)=7 {
// Badge, Alert & Sound
NSLog(@"Badge, Alert & Sound");
}
else if (notificationTypes == 10)//Sound(2)+NewsstandContentAvailability(8)=10 {
// Sound & NewsstandContentAvailability
NSLog(@"Sound & NewsstandContentAvailability");
}
注: 考えられるすべての if-else ステートメントを書いたわけではありません。必要に応じて追加してください。
これがあなたを助けることを願っています。