ON / OFF setting for Push notification at app level - iphone

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

Related

can you answer a push notification with your voice?

can you answer a push notification with your voice? So when you iPhone is locked and you get a push notification, can you react to it with you voice?
You're not registered for audio push notifications in your app. Just register for it like this in your App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever you have already in your app delegate...
// Let device know you're going to be sending one of these types of notifications.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
The 5 types are:
UIRemoteNotificationTypeBadge
UIRemoteNotificationTypeSound
UIRemoteNotificationTypeAlert
UIRemoteNotificationTypeNone
UIRemoteNotificationTypeNewsstandContentAvailability
Here's the documentation: Registering for Remote Notifications
also refere this documents
Hope that helps!
You can not play voice in push notification.Push notification Payload not contain your voice.
Users see notifications in the following ways:
Displaying an alert or banner
Badging the app’s icon
Playing a sound.
According to apple push notification document

How to remove Single Remote notification in iphone

I am developing game which have support of server side push notification of score and winning notification, User game request.
All is working fine with notification read and response store to device side. But when notification is pushing to notification center. when i click on notification at that time it remove all the push notification from notification center with following code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
But i want to remove selected remote notification from notification center.
Is there any way to remove single remote notification.Please help me.
Thanks in advance.
To cancel local notifications
If you have the means to obtain a reference to the specific UILocalNotification instance you want to cancel, you can call cancelLocalNotification: on it.
Try traversing all scheduled notifications in order to obtain that reference by going through:
NSArray *scheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
To cancel remote notifications
This is entirely up to the server, can't be done without proper API on the server's side.

iPhone: how to remove notification from notification center

I have a provider which sends Push notifications to my iPhone. If I'm on home screen, I click on push notification in notification center and my app become open. Then I close my app, but notification is still in notification center...Why ? I already read that, why its not disappear ? How to remove this notification after I close my app ??
WHen are you want to remove the badge from the application just value of the badge number assign to 0 is means automatically remove the badges.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
You can remove the notifications using the below code
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
This will remove all the app's notification from Notification Center.

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

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

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];