iOS 7 Local notifications with no sound by default - ios

When I run the app on my iOS 7 device, the app doesn't appear on the device notifications settings and doesn't sounds when a notification is being fires. Only after the first notification is being fired, I can see my app under the list of the notification settings with sounds turned off.
Why doesn't the app show in the notifications list initially?
Why are the sounds turned off by default?
On iOS 5&6 I don't have these problems. These are local notifications.

It looks like iOS 7.0.3 includes a fix for that.

Have you set the applicationIconBadgeNumber in "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions"? Comment this code, and try again.....I don't why, but I got the same problem. After I commented this line, my app works correctly.

I got this same problem. What i found out was, i have a piece of code that caused this all along.
In my AppDelegate didFinishLaunchingWithOptions, i have implemented:
//remove this if you have it
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; //to reset the badge everytime the app loads
So what i did, I removed that code & redeploy the app. Now it has ON default value in Notification Center.
Phew.

Hmm,
Interestingly, I changed the order of
notification.SoundName = UILocalNotification.DefaultSoundName;
notification.ApplicationIconBadgeNumber = 1;
to
notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;
and it works now. When the app is running in background, the local notification fires and plays the default notification sound.

Related

Programmatically delete Remote Notifications from Notification Centre

How can we pragmatically remove any pending remote notifications sent for my app from notification centre. I want to clear them up on app launch.
I have tried with [[UIApplication sharedApplication] cancelAllLocalNotifications]; API but its not helping.
PS: This question is specific to iOS 10 and old threads are not duplicates for this one.
Finally...
This one works like charm!
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
You can clear all notifications from notification centre by using these simple lines of code
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
use wherever you want. From my side I have used when user pressed logout.
You can use in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method to clear notifications after app opens
AFAIK, you should do it by using the background mode for remote notifications, and then responding to these notifications by issuing a local notifications.
You can remove local notifications, but not remote notifications.
Reseting the application badge number also remove all the notifications (local & remote) from the notification center.
Objective C
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
Swift
UIApplication.shared.applicationIconBadgeNumber = 0
This can definitely be achieved by using removeDeliveredNotifications(withIdentifiers:) method available in UserNotifications.framework.
For a detailed tutorial, please follow this
https://medium.com/#sebastianosiski/implementing-removable-remote-notifications-on-ios-a17d74832bde

How to find out the Icon Badge count?

I'm using push notifications on my iOS app and everything is working great.
The icon badge is working and when I open the app I clear it with this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
But before clearing it I would like to find out what is the badge count to make some changes on the app according to the number of notifications the user has when opening the app.
Is it possible to do get this number?
Thanks!
[UIApplication sharedApplication].applicationIconBadgeNumber
Try

iOS 7 - didReceiveRemoteNotification: not triggering on background

I know that this question is tipical but I'm missing something and I don't kwon what is.
I have a simple application, in iOS 7. Using Xcode 6. I'm developing in objective-c.
I want to receive push notifications and update my app icon badge to (1) but I can't trigger the didReceiveRemoteNotification method when the app is in background so I can't set the badge number. This is not my first app with push notifications and badges but I can't do it...
My code:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
NSLog(#"RECEIVING NOTIFICATION");
When i'm on the app the badge is correctly setted and the log is printed, but if I'm in background mode the method is not triggered.
My payload APNS
{"aps":{"alert":"New push","sound":"default"}}
I want to set the badge manualy to 1. I don't need it on de payload.
Any suggestions?
Thanks
The remote notification will set the badge automatically according to the number of "badge" in aps.
For example:
{"aps":{"alert":"New push","sound":"default","badge":1}}
A bit late, but it might help someone else.
You can trigger - application:didReceiveRemoteNotification: when your app is in background by following this two steps:
Set Required background modes to App downloads content in response to push notifications in your Info.plist file
Add "content-available": 1 to your notification payload.
This will call - application:didReceiveRemoteNotification: and allow you to handle notifications in background (i.e, refresh the content of your app, etc...).
Hope this helps!

Dismiss apple push notifications when clicked

So it's a pretty straight forward problem. My server sends an APN to the iOS device, I can click on the notification and the app launches and everything works as it should, but the notification never gets dismissed, it just sits there in notification centre.
Any help would be greatly appreciated!
Apologies if this has been answered before, I've searched all over stack and only found reference to local notifications.
Edit
Ok, so when I put
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
in the application:didFinishLaunchingWithOptions it dismisses any old notifications when the app is launched (and no this doesn't happen by default when the app launched anyway), but when I put it in any of the other delegate methods that get called when the app becomes active like applicationDidBecomeActive: it doesn't work?
This is making very little sense...
Adding in:
application.applicationIconBadgeNumber = 0;
into applicationDidBecomeActive: did the trick!

How stop local notification sound after cancel local notification

In my application I scheduled local notification with custom sound. After I cancel it from code the sound continue playing. How can I stop it?
-(void)cancelNotification{
if(localNotification){
[[UIApplication sharedApplication] cancelLocalNotification:localNotification];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
}
Try changing your code like below, hope this works for you. I am adding this just for a try.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[[UIApplication sharedApplication] cancelLocalNotification:notification] ;
}
In didRecieveRemoteNotification set your application icon badge number. It will do the trick.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
}
I had the same problem when initially testing with an iPhone 4.
The problem appears to have gone away as of iOS 8 and now Local Notification Sounds stop when canceled after transitioning to the App.
iPhone4 [ iOS - 7.1.2 ] - Local Notification sound keeps playing in App no matter what
iPhone6 [ iOS - 8.1.1 ] - Local Notification sound stop when canceled programmatically
From what I can infer, it appears a fix exists somewhere in iOS 8.x
(Alas I didn't manage to find any documentation or release notes on the matter.)
The Problem becomes a non-issue for apps focusing on iOS 8
(provided you cancel the Local Notification coming in)
I used this same answer for a Similar Problem

Resources