access user push notification preferences/permissions in the iPhone using objective c - iphone

we are looking for a way to find out (not modify, just find out) if our application has been allowed to receive notifications or not from our service. This probably requires read-only access to the "general settings" properties or some specific API's. Does anybody know how to get that information? I am talking about the info in iPhone --> Settings --> Notifications
For those who are interested, this is the rationale:
we are having some issues with users pressing NO when asked to allow our application to receive push notifications. As you can imagine, users might just press no because they are racing through registration or because they don't quite understand what is happening, or simply because they are not too sure whether they should allow the application to get notifications. But then they forget they denied permission so file support requests because they don't receive push notifications.

Call -[[UIApplication sharedApplication] enabledRemoteNotificationTypes]. From the docs:
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 the registerForRemoteNotificationTypes: 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.

-enabledRemoteNotificationTypes is deprecated.
It is recommended that you use the simple boolean instead:
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]

Related

TVOS remote notification replacement

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...

How to determine Push notification status programmatically?

In my app, for first time push notification registration, I call didRegisterForRemoteNotificationsWithDeviceToken and save the device token in persistence as well as update my server list for device token. Now afterwards if somebody turns the push notification settings off from iPhone Settings how can I determine it from my app so that I can remove the device token from server as well. I know APNS provides a feedback list, but other than that is there a way to determine it in App programmatically? Thanks for any help!
I believe you do not want to manage tokens this way.
Your app should always be asking Apple for an APNs token. You should always then send that token to your own server, likely associating the token with your user (if you have one). You do this because the token could change, so you want to make sure you always have up-to-date tokens.
The Feedback service will tell you (actually, you poll it at some interval of your choosing) which tokens have become invalid. At this point, you remove the tokens from your server-side database. To be clear, you need a server-side process that polls Apple's feedback service and then updates your server-side database.
You will not receive feedback about invalid tokens until you try to send a notification using the token. The notification will (I believe) be accepted by Apple when you send it, but when Apple discovers it's for an invalid token, the message is dropped, and the token is added to your feedback.
Now, if the user of your app accepts push notifications when your app first asks about it, but later turns off notifications via the Settings app for your app, you will not get any feedback about it. What happens, near as I can tell, is that any notification you send to that device will be sent to the device, but the OS drops it, honoring the user's ultimate choice in the Settings app for your app and notifications.
Finally, there is an API you can call in your app to get a bitmask of which kinds of notifications are enabled for your app on the device. Here's a method I wrote for this purpose; adjust as needed:
+(BOOL)acceptsPushNotifications
{
UIRemoteNotificationType mask = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
return (mask & UIRemoteNotificationTypeAlert) == UIRemoteNotificationTypeAlert;
}
But I would not recommend using this to decide if you app should tell your server to delete the token from your database. That's not how the whole APNs system is intended to work... I believe.

How do push notifications on the iPhone determine which users are notified?

I'm just trying to understand push notification more.
Let's say I have a web service that my app connects to that needs a user to sign in with a username and password. And this all works fine when running the app.
Now... how does the web service determine which user to send the push notification to?
I'm really unsure on how it works with users with usernames and passwords. It would be great if someone could enlighten me to this. A better understanding could improve my apps in the future. Thanks!
I'll give a brief over view of how push notifications work:
First, your app will call the registerForRemoteNotificationTypes: method. This will check that your app is allowed to send and receive the types of notifications you requested, and contact Apple's servers to register your device. You will get back a special token used to uniquely identify the device.
Your app needs to send this token to your server along with the details of the account that the user is logged in with, so your server can associate that token with the user.
When you want to send a push notification to a user, you lookup the token you received previously for that user and use that when sending the notification to Apple's server. This will forward the notification to the appropriate device.
It's probably a good idea if you read the Apple documentation here: Apple Push Notification Service. This will give you a clearer understand of how it all works.
Here is the wonderful tutorial explains in detail, http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
For login procedures, you don't even need push notifications. If you need a general introduction, you will find one here
Below I have mentioned 2 links.
https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html
http://mobiforge.com/developing/story/programming-apple-push-notification-services
Now coming to your question, push notification is pushed from a server. Now for a particular user the server side should maintain the database such that whatever changes made to a specific user should be pushed to that device id.
Hope this help.
Push notification is awesome feature of iOS apps. It works like your application needs to register for Push notification as
//Your application registeres for push notification using following line
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
This will tells you application to handle generation of device token failure/success by delegate methods
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
//Your application registered for push notification i.e. allowed by user.
//You need to take device token and pass it to your webservice and store it in database.
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
//Your application registered for push notification i.e. not allowed by user.
}
So, Now what after you have device token ? .. Its simple now use it for sending push notification. You can find different code for that using PHP as well as .Net. Search around and you will get plenty of them.

How do you handle users who don't enable push notifications but might want to later on?

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.

iOS - Push Notification: does it always display a notification

I'd like to know if it is possible to send a push notification, through APNS, without displaying a notification if the application isn't started? (in this case, the message received will be thrown away)
Thx
I may be misunderstanding your question, but I am assuming you are asking how to provide the user with options to turn off particular aspects of the push notification?
You will have to set this in the App. That is, if the user wishes to turn off this particular aspect, your App will have to send up the request for them.
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
So, if you still wanted to do badges, but no longer show alerts:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge];
Don't forget to resend the Token to your provider as it may have changed after this request.