IOS technical point: determines whether the user has enabled the push switch/whether push is allowed ?, Ios Switch
-(BOOL) IsAllowedNotification {
// IOS8 check if user allow notification
If (IS_IOS_8 ){// System is iOS8
UIUserNotificationSettings * setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
If (UIUserNotificationTypeNone! = Setting. types ){
Return YES;
}
} Else {// IOS7
UIRemoteNotificationType = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
If(UIRemoteNotificationTypeNone! = Type)
Return YES;
}
Return NO;}
(The push notification type enabled by the user in iOS8 corresponds to UIUserNotificationType (the type of the types attribute of UIUserNotificationSettings in the code below), and iOS7 corresponds to UIRemoteNotificationType)
This example uses iOS8's UIUserNotificationType. For example, when a local notification or push/remote notification is pushed, this constant specifies how the app notifies users (such as Badge, Sound, alert combination)
So how can we get it? In iOS8, we use the types attribute, [[UIApplication sharedApplication] currentUserNotificationSettings]. types
For example, after obtaining the information, we need to know that this property stores all the push types you specified (Badge, Sound, Alert ), in Figure 1, we know the bitmask corresponding to the push type: (taking the four-bit binary as an example)
UIUserNotificationTypeNone = 0, == 0000 0
UIUserNotificationTypeBadge = 1 <0, = 0001 1 0 shifted left 2 ^ 0 = 1
UIUserNotificationTypeSound = 1 <1, = 0010 1 shifts 1 to the left, 2 ^ 1 = 2
UIUserNotificationTypeAlert = 1 <2, = 0100 1 shifted left 2 ^ 2 = 4
(When the teacher taught the C language, he said that the Left shift can also be used as a multiplication 2, and the right is removed 2)
If the badge and sound prompt are displayed when you select push, the value of types is 3 (1 + 2) = 0001 & 0010 = 0011 = 2 ^ 0 + 2 ^ 1 = 3
Therefore, if the user does not allow pushing, the value of types must be 0.