UILocalNotification not firing properly on iPhone when app not foregrounded - ios

UPDATE - a warning to anyone with similar symptoms... check Do Not Disturb is not active!
I finally paid to get an app I was working on running on my iPhone instead of on the simulator.
Having done so I've spotted a strange behaviour with regards to the UILocalNotifications that I create, which are set to use the default sound UILocalNotificationDefaultSoundName, and the default timezone ([NSTimeZone defaultTimeZone]).
If the app is foregrounded then the local notification fires on time and I receive it within
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
and I create an alert view to display it.
If however I lock my phone just before a notification is expected then nothing appears on the screen, but when I press the home button to show the lock screen I can see my app's notification in the notification centre on the lock screen. No sound was played, but then again the phone didn't wake up to show the notification properly.
If however I just press the home button so the app is put in the background leaving me looking at the springboard apps then I don't see any notifications whatsoever, and again no sound is heard.
On the simulator the same code correctly fires the notification banner when looking at the app icons in the spring board, although I've never been able to hear any sounds for the notification. But as the simulator doesn't let you configure the notification centre for apps I always presumed it was perhaps set to not allow sounds. On my device sounds for this apps notifications are enabled, and i've tried it with banner and alert modes, with no joy. Very frustrating.
Has anyone experienced this, or have an idea what could be going on?

Oh the irony of this answer.. think it's time to go to bed. My iPhone thinks that too for nearly 3 hours now... My question happily describes Do Not Disturbs behaviour, which was active.. Sorry to waste everyones time!!

Related

Sometimes Notifications cause iOS screen to just wake up

That's really weird problem..my notifications is working perfectly but in very random and rare cases, the screen just is woken up but no notification appears.
Although I'm using native Swift, it seems it's a common problem
IOS Push notification - Sometimes only wakes screen and plays sound
Do you have any suggestions?
If you have a line of code that reduces the application badge number when a notification is received, make sure that this line doesn't get called when app state is not "Active".

Notification with sound and vibration when iphone is Locked

I am currently working on an iOS app and i need some help.
I want the app to be able to notify the user about something in form a "push notification" even when the phone locked. The push notifications work fine when the phone is not locked but as soon as i lock the phone it wont give me any sound or vibration. It will only show me the visual part of the notification but it comes in completely silence. It does not even light the screen up when the notification gets pushed to the user.
I currently use
content.sound = UNNotificationSound.default()
And it works fine with sound and vibration when the phone is unlocked.
Is it because i need to do something with my settings? do i need any code to do such thing? do i need to have developer account?
Any help would make me really happy!!
3 STEPS TO HOPEFULLY RECOVER SOUND ON YOUR IPHONE FOR INCOMING NOTIFICATIONS.
Check that the ringer on the left of the phone doesn’t show an orange line – indicating sound switched off. If so, slide it to the right so only white is showing. This may have fixed it.
Swipe up from the bottom of the screen to reveal symbols, music etc. Ensure that the half moon symbol is grey and not white. If it’s white touch it to make it grey – this will switch off do not disturb. This may have fixed it.
Check your settings, Do not Disturb half moon icon, ensure that Manual is off and not showing a green on icon. If it is, touch the green icon which will make it white and switch it off. This may have fixed it.
(I hope that helps, it worked for my iphone 5C as I’d inadvertently switched on Do Not disturb as shown in step 2. above.)
Just an FYI if someone else is having this same issue. I was having the same troubles getting my notifications to come through on my phone when it was locked.
I realized the issue was I was building to my physical device which was also attached to the Apple Watch I was wearing. Since my watch is set to mirror my iPhone notifications the phone didn't play them as it expected my watch to take over when was locked. However, every time you build & run your app it takes a few minutes for your watch to recognize your app and take over the user notifications.
The solution here is to either wait 10 minutes or so after building and then try firing off a notification (which should appear on your watch) OR simple take off your watch before you build & run.

iOS local notification without turning on screen

I'm working on app that will manage quite a lot of local notifications. So since I don't want to waste user's battery, I'm wondering - is there any possibility to don't turn on the screen? So the notification still will be fired and the banner will be on the screen but only if user will unlock the phone. It's kind of "minor notification" that are still should be displayed but they're not so important to wake up the phone.
And if there's such possibility - wouldn't it be what Apple calls "bad user experience". You know, kind of confusion that notification didn't wake up the phone's screen?
And yes, sound still should exist, because it should work as reminder.
Thanks in advance.

ios7 didreceiveremotenotification not called when screen is locked

I'm having a trouble to get the information from push notification and it only happens on iOS7, I have tested on iOS5 and iOS6, the function works perfectly fine. Here is the scenario: I have a game playing between 2 iPhones and it's a turn-base game, in every move, there will be a push notification sent to each competitor announce that the other one has made the move and now is your turn.
The problem is, when I lock my iPhone (turn off the screen) and the other made the move, there IS the push on my iPhone, and I slide to unlock, obviously the app appear but the 'didreceiveremotenotification' has not been invoked.
It's weird that only happens on iOS7. I know there are only 3 states that the application will get the push notification supspended/background/foreground. what state is the lockscreen? Any helps would be great and sorry for my English, if I didn't make it clear, please leave the comment, I will explain more.

Cancel a push notification sound while it is playing

Tried to find this already but can't find any questions which are asking quite the same thing.
Basically I have set up my push notifications, everything works fine and they are received both when the app is open and closed. However, the push noise we are using is quite long and I'm not sure if it's possible to cancel the sound once they press the "ok" button on the alert.
I have tried to utilise the mute toggle switch, but this only seems to come into play at the moment that sound starts to play, if it's off the sound plays, if it's on then it doesn't. If I toggle the switch mid-sound it has no effect. However, if I just play a regular sound clip in my app (not a push notification sound) and use the toggle switch then the sound stops/starts as you would expect.
Is there a way to cancel the sound? Or is it treated differently as a system sound of some kind?
Edit: I've been trying to work this out myself for the last few days, and I'm coming to the conclusion that there is no way to cancel the push alert sound mid-sound. Can anyone confirm that this is definitely the case?
Edit2: For some reason the xcode tag has been removed - with the reason being that it is nothing to do with xcode. I feel maybe my issue was not clear - I AM using xcode to build the app, and I am looking for a way to programatically control whether the push notification sound is heard or not. Thanks.
No answers given, having tried and failed over the last few months I can only assume this is not possible (just in case anyone has the same issue in the future).
It works for me:
[[UIApplication sharedApplication] cancelAllLocalNotifications]
As of iOS 10, you can remove all notifications from Notification Center by calling
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
The audio stops playing and all the notifications are removed from Notification Center.
Alternatively, to stop the sound for only a specific notification, you can use:
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [String])
This stops the audio for only the given notifications, and removes them from Notification Center.
To get the ids for all the delivered notifications, use
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
let ids = notifications.map { $0.request.identifier }
}

Resources