Enable/Disable Apple Push Notification from iPhone app?
Solution 1
Unfortunately you can't enable or disable the Push Notifications for your app from the app code. The dialog asking for permission is displayed only once. Usually, other apps display instructions to the user to enable / disable push notifications by going into Settings-> Notification-> AppName.
Solution 2
You can read your app's permissions using UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
and then performing a bitwise and operation with the different types to see which are enabled. You can also call unregisterForRemoteNotifications
to disable notifications. The one thing you can't do is turn on notifications, although you can direct the user.
Solution 3
My requirement was to enable and disable pushnotificaton with a UISwitch
.Inorder to enable push notification from the code use this inside the button action.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Inorder to disable
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
NSLog(@"UnRegistered for pushnotification");
Solution 4
When you give permission for the first time the device token of your iPhone is registered with the APN server and then you can receive the push notification. Later you can enable/disable from your device settings → notification → your app.
Solution 5
1.From your app No its just appear the first time the user open your app after install it .. if then he decide to allow it he can activated from device settings.
2.it can be done from the app and settings .. if you want to disable it from your app you could send the device token (who decide to disable the push notification) to your server and store it for ex. as "no notification list" and when send the payload you ignore these tokens so they will not receive the notification.
3.I already answer it.
Good Luck.
Gopinath
Updated on July 09, 2022Comments
-
Gopinath almost 2 years
I have one more doubt on
APNS
. That is when the app first launch the app asks for Apple Push Notification Permission if the user accepted the they can receive the notifications. If the user cancelled they can't receive any notifications. Am I clear??Now my doubt is,
At first time if the user cancelled the push notification service from the app (Clicked
Cancel
button) again after some days if they want receive Apple Push Notification it is possible to enable the Apple Push Notification again for the particular user from the App.And if the user accept the apple push notification service first and after some days if they don't want to receive the notifications it is possible to disable the
APNS
in our app? I hope you understand my doubt. Can any one please clarify this doubt?It is possible to do these above scenarios in our iPhone app?
Please help me. Thanks in advance.
-
Gopinath about 12 yearsThanks for your answer Adig. Is there any possibility to find by the code that the user switched off to receive the notifications from my app (From our iPhone device settings screen). Thanks in advance.
-
Gopinath about 12 yearsThanks for your answer Malek_jundi. Is there any possibility to find by the code that the user switched off to receive the notifications from my app (From our iPhone device settings screen). Thanks in advance.
-
adig about 12 yearsYou can check if any type of push notifications are enabled by using this :
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone)
-
Malek_Jundi about 12 yearsI don't think so .. but its simple you will make an api function hold 1 parameter (device toke) once the user turned off the notification (its up to you how to make it in your app but the UISwitch it the best choice) you will call this api and set a flag for this token to not receive notification .. thats it.
-
Itai Spector about 8 yearsAs mentioned above, enabling can only happen once.
-
shaqir saiyed over 6 yearsso that means , I can put one ON/OFF switch in my app for my App Notification & I can enable/disable it at any time I want .. does Apple approve this ?
-
Krunal over 6 years@shaqirsaiyed Yet I've not confirmed it, as I've been engaged with enterprise app only. But surely I'll check this with apple. This can be very useful.
-
shaqir saiyed over 6 yearsyea please check it if its possible.