-
(
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 type = [[UIApplication sharedapplication] enabledremotenotificationtypes];
if(Uiremotenotificationtypenone! = type)
return YES;
}
return NO;
}
(The type of push notification that the user opens in iOS8 corresponds to uiusernotificationtype (the type of types attribute uiusernotificationsettings in the code below), IOS7 corresponds to uiremotenotificationtype)
Here is an example of the uiusernotificationtype for iOS8, such as when a local notification or push/remote notification push, this constant indicates how the app will alert the user (e.g., a combination of Badge,sound,alert)
So how to get it, in IOS8 is through the types property, [[UIApplication sharedapplication] Currentusernotificationsettings].types
For example, we need to know that this property stores all of the push types you specify (Badge,sound,alert), and in figure one we know the bitmask of the push type: (take four-bit binary as an example)
Uiusernotificationtypenone = 0, = = 0000 0
Uiusernotificationtypebadge = 1 << 0, = = 0001 1 shift left 0 bit 2^0 = 1
Uiusernotificationtypesound = 1 << 1, = = 0010 1 shift left 1 bit 2^1 = 2
Uiusernotificationtypealert = 1 << 2, = = 0100 1 shift left 2 bit 2^2 = 4
(Before the teacher taught C language, said, you can also shift the left as a multiply 2, right to remove 2)
If the user tick push to show badge and cue sound, then types value is 3 (1+2) = = 0001 & 0010 = 0011 = = 2^0 + 2 ^1 = 3
Therefore, if the user does not allow push, the value of types must be 0
iOS technology point: Determine if the user is enabled for push switch/Is it allowed to push?