can application find out if push notifications are enabled or disabled? - iphone

Can my application find out if push notifications were disabled through Settings on the device? I am not talking about checking with feedback.push.apple.com. I would simply like to know if the switch in the Settings was set to ON or OFF.

You can use
[[UIApplication sharedApplication] enabledRemoteNotificationTypes]
If this returns UIRemoteNotificationTypeNone which is equal to the value 0, then the application accepts no notifications. Hope this helps you.

You can find out which kind of notifications are enabled for your app using [[UIApplication sharedApplication] enabledRemoteNotificationTypes].

Related

ON / OFF setting for Push notification at app level

I would like to apply the native feature of ON/OFF toggle for push notifications at app level. When i applied the same in my app and when I switch OFF, i am unable to receive notifications. However, when I switch ON, i am not receiving notifications. To have my notifications enabled, I need to uninstall and then install my app.
any possible solution is appreciated.
You can you use UISwitch control for on/off OR you can also use separate UIButton for on/off.
You just need to unregister for remoteNotification by : ( Off )
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
When you want to register again then ( On )
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
For checking ON or OFF iPhone Push Notifications try this code,
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
// Yes it is..

Local Notification (repeat) fired after new install of app

in my app I am using local notifications and often they have a repeat interval set.
The problem is, when the user deletes the app and reinstalls it, the repeat notifications start firing again.
Is there a fix for this problem? Will the following suggestion from another user work? :
you can use [[UIApplication sharedApplication] cancelAllLocalNotifications]; only at first launch, so that "old" notification will be cancelled....(I haven't tried that)
Thanks a lot!
you can use [[UIApplication sharedApplication]
cancelAllLocalNotifications]; only at first launch, so that "old"
notification will be cancelled...
This is not your solution. This will cancel all your already scheduled notification every time when your didFinishLaunching method will called. So before applying above solution there should be one more check. Store a value in NSUserDefauls for checking that you are installing application again after deleting.
if(![[NSUserDefaults standardUserDefaults]objectForKey:#"Notification"]){
[[UIApplication sharedApplication] cancelAllLocalNotifications]
[[NSUserDefaults standardUserDefaults]setBool:Yes ForKey:#"Notification"];
}
This will prevent from canceling all notifications every time.

How can I temporarily disable all local notification scheduled by my iPhone app?

Is there any method to temporarily disable all local notifications created by an iPhone app? I need to re enable them all with respect to a condition. my requirement is if the user turned off the notification button on my app , then no more notifications is shown.If he turned it on then all notifications should be shown. Any idea?
You can get all scheduled notifications and save them in shared preferences for example.
[[UIApplication sharedApplication] scheduledLocalNotifications];
Then cancel all notifications:
- (void)cancelLocalNotification:(UILocalNotification *)notification
If user activate notifications again, you can reschedule them again.
You can use "cancelAllLocalNotifications" method and When User turn it On you can set again All notification for it.

iOS Persistent Notification / Quick Launch

I'm curious if anyone can provide information on how apps like AppSwitcher use the notification center to create persistent quick-launch notifications.
I know that they are using a url to do launch apps, but what I'm looking for is how to create the notification and keep it persistent.
If your app creates a notification and doesn't clear notifications programmatically, it will remain in Notification Center until the user clears all notifications from your app.
The best I've been able to come up with is calling something like a following ever so often:
[[UIApplication sharedApplication] cancelLocalNotification:localNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
This will delete the current notification, and replace it with a new one. However, it's not really persistent, and another drawback is that the screen will turn on when the notification gets refreshed. Still searching for a better way.

can we show badge without APNS?

I want to simulate push notification without using apple's push notification server, so I want to know can I show badge also if yes which API or Objective-C code I have use to show badge?
Yes. Use [[UIApplication sharedApplication] setApplicationIconBadgeNumber:<n>]. See the documentation.
We can use [[UIApplication sharedApplication] setApplicationIconBadgeNumber:<n>] to show the badge with out APNS.
If we want to reset the previous badge while application is restarted ,we can use this
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];