I'm looking for a way to disable push notifications when the user logs out of the app.
As the user can do this without an internet connection it is not an option to notify the server that this device should no longer receive notifications.
I figured it out thanks to #wsnjy.
The following code disables notifications:
UIApplication.shared.unregisterForRemoteNotifications()
Related
I am building a TVOS app for the new Apple TV that needs to get notifications from a server to update it's display. Remote notifications are not allowed with TVOS, and it actually displays an error when you try to register the app for remote notifications.
With this being said, are there any alternatives to what I need?
To clarify:
- The app stays running indefinitely, showing a display.
- When the user adds content to the display, I want to notify any apps that are logged in to the same user to update the display.
- I cannot use remote notifications.
Please let me know if this makes sense, and thank you in advance for your help!
What part of the registration errors out for you? Notification dialogs and banners may not really make sense on tvOS, but can you send a silent push notification? All you need to do to register for these is
[application registerForRemoteNotifications];
You do not need to display the request dialog to the user for permission for silent notifications (you do need to have the remote notifications entitlement though.)
According to Apple's documents here, they allow CloudKit. CloudKit subscriptions rely on silent push notifications that I would assume would work on tvOS (without them it would severely cripple CloudKit)
If that still does't work, then you could create your own long polling connection (essentially, you would be making your own custom push notifications). It would only be able to send messages to devices that have the app opened however.
I guess you can have the app poll a web server at a given interval to check if any updates have been made...
Is there anyway to filter push notifications that im send to my app?
I mean, if my user logged out (fb connect) from my app and for somereason my server is miss sync with the loggin-out, i will send to the user notifications while he logged out, which is unwanted situation..
Thanks.
You need to do your filtering server-side. There is nothing your app can do on a device to filter its incoming notifications. Your app may not be running when the notification occurs, and may not be launched if the user disregards the notification.
You can set BOOL variable to false on log-out. so whenever Notification arrive, you check BOOL value, if false don't process Notification and if true do whatever you want to do.
this is just an example case, you can use same logic anywhere else to process Notifications.
You could use unregisterForRemoteNotifications method.
If the client disabled push notifications, can he still receive notifications while the app is running? I read somewhere that if the notification doesn't specify "aps" as the namespace, it'll still go through despite the fact that push notifications have been disabled. The notifications of course will not appear if the app isn't in the foreground. I can't find the article so I can't say for sure this is true.
If your client has disabled push notification in the app you should check this and alert him that your app may not run as expected only till he will enable push notifications again.
I just tested this, nope. Push notifications for active app status will not go through if push notifications are disabled.
On iOS5, the push notification shows on the top bar and not block user. When the push notification is showing and user click our application but not the push bar, our app will launch normally. However, we want to cancel the push notification at that time. Is it possible ? Thanks a lot!
Short answer: No. There is no way you can manipulate sent notifications as far as I know.
Slightly longer answer:
Once a push request has been sent to the Apple Push Notification servers, thats it. It disappears into their system and they will then try to deliver it on a 'best effort' basis. You receive no feedback about its status or any ability to change/delete it.
The only form of feedback you can get is about which devices do not wish to receive push notifications that you tried to send to.
If you want to send delayed notifications which can be cancelled/modified at later data, either write you own solution, or use some pre-existing solution (e.g Urban Airship).
How do you handle users who initially disable push notifications? I keep a record of push id's using EASYAPNS and I'm concerned that if someone disables push notifications, they'll miss out on some great features of my app.
What do you do if they want to enable notifications later on? If I create a settings tab for push notifications and they later on enable them, will the app then and there generate a push id, or is it a one time thing and they're out of luck if they don't register for notifications the first time the app launches?
Thanks
According to Apple's Local and Push Notifications Programming Guide,
"an application should register every time it launches and give its provider the current token.
(...)
Users can thereafter modify the enabled notification types in the Notifications preference of the Settings application, and you can retrieve the currently enabled notification types by calling the enabledRemoteNotificationTypes method."
The user can always go to the iPhone Settings and enable or disable notifications for your app, doesn't matter if he initially had it enabled or not.
You don't need to write the code for setting of Push Notification. iPhone itself has a feature to enable or disable Push Notifications, but application must have implemented the code ofr Push Notification.