Wednesday, May 22, 2013

enabledRemoteNotificationTypes example UIApplication ios


[UIApplication enabledRemoteNotificationTypes]

Returns the types of notifications the application accepts.
- (UIRemoteNotificationTypeenabledRemoteNotificationTypes
Return Value
A bit mask whose values indicate the types of notifications the user has requested for the application. See UIRemoteNotificationType for valid bit-mask values.
Discussion of [UIApplication enabledRemoteNotificationTypes]
The values in the returned bit mask indicate the types of notifications currently enabled for the application. These types are first set when the application calls theregisterForRemoteNotificationTypes: method to register itself with Apple Push Notification Service. Thereafter, the user may modify these accepted notification types in the Notifications preference of the Settings application. This method returns those initial or modified values. iOS does not display or play notification types specified in the notification payload that are not one of the enabled types. For example, the application might accept icon-badging as a form of notification, but might reject sounds and alert messages, even if they are specified in the notification payload.
Example of [UIApplication enabledRemoteNotificationTypes]
UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
And then check the returned bit mask for what is and isn't enabled
if (notificationTypes == UIRemoteNotificationTypeNone) {
    // Do what ever you need to here when notifications are disabled
} else if (notificationTypes == UIRemoteNotificationTypeBadge) {
    // Badge only
} else if (notificationTypes == UIRemoteNotificationTypeAlert) {
    // Alert only
} else if (notificationTypes == UIRemoteNotificationTypeSound) {
    // Sound only
} else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)) {
    // Badge & Alert
} else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)) {
    // Badge & Sound        
} else if (notificationTypes == (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)) {
    // Alert & Sound
} else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)) {
    // Badge, Alert & Sound     
}
Example of [UIApplication enabledRemoteNotificationTypes]
UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (enabledTypes & UIRemoteNotificationTypeBadge) {
    //UIRemoteNotificationTypeBadge is set in the bitmask
}
Example of [UIApplication enabledRemoteNotificationTypes]
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
UIRemoteNotificationType typesset = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge);
if((types & typesset) == typesset)
{
    CeldaSwitch.chkSwitch.on = true;
}
else
{
    CeldaSwitch.chkSwitch.on = false;
}