Reputation: 381
I have a question about push notifications.
I have a database with all tokens devices. This is the structure of the table.
ID (number)
APP_NAME (varchar)
APP_TOKEN (varchar)
ENABLE (bool)
If the users go to the device settings and switch off my app notifications, there is anyway to change the field enable to false? I mean, I have a plugin in wordpress witch send notifications to all devices registered in my database and I want to know if an user switch off the notifications to put the field "enable" to false and then no send the notification to him.
Upvotes: 0
Views: 104
Reputation: 2267
You can check all types of notifications cf this question:
BOOL remoteNotificationsEnabled, noneEnabled,alertsEnabled, badgesEnabled, soundsEnabled = NO;
// iOS8+
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
remoteNotificationsEnabled = [UIApplication sharedApplication].isRegisteredForRemoteNotifications;
UIUserNotificationSettings *userNotificationSettings = [UIApplication sharedApplication].currentUserNotificationSettings;
noneEnabled = userNotificationSettings.types == UIUserNotificationTypeNone;
alertsEnabled = userNotificationSettings.types & UIUserNotificationTypeAlert;
badgesEnabled = userNotificationSettings.types & UIUserNotificationTypeBadge;
soundsEnabled = userNotificationSettings.types & UIUserNotificationTypeSound;
}
else { // iOS 7 and below
UIRemoteNotificationType enabledRemoteNotificationTypes = [UIApplication sharedApplication].enabledRemoteNotificationTypes;
noneEnabled = enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone;
alertsEnabled = enabledRemoteNotificationTypes & UIRemoteNotificationTypeAlert;
badgesEnabled = enabledRemoteNotificationTypes & UIRemoteNotificationTypeBadge;
soundsEnabled = enabledRemoteNotificationTypes & UIRemoteNotificationTypeSound;
}
Then depending of the results, update your boolean on your backend by making a call to your API.
Upvotes: 1
Reputation: 2474
You have to check the enabled notification flags on application launch. Then set your enabled flag accordingly with a server call
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone) {
//set your flag to disabled
}
Upvotes: 1
Reputation: 38152
Unfortunately, there is no delegate callback from iOS that inform the app when push notification is enabled or disabled from Settings app. Application need to query the UIApplication
property enabledRemoteNotificationTypes
for example in applicationDidBecomeActive:
and then make a server call to save the setting like in your case ENABLE = NO
.
However, even if server sends the notification when user choose to not listen to it, iOS ignores the notification.
Upvotes: 1