We are developing an application containing a chat.
Our issue only happens after a fresh app install:
Install the app
Login of an existing user who has some unread chat messages, so I set the app badge to N (number of unread messages) when I download from the server the chat information (using setApplicationIconBadgeNumber).
Send the app to background (tapping the HOME button)
As the app goes to background, the app icon badge is set to N (the number of unread messages), but after a second the N badge disappears!
There are several strange behaviors in this:
After the N badge disappeared, if I 'move' the app icon by long tapping and moving it on the screen the badge reappears to stay.
If after launcing the app the first time and before going to background, the app receives a push notification, the badge doesn't disappear.
After the first app run, on all the following runs this effect doesn't happen and the N badge remains.
When the app is killed during the first run, the app badge doesn't appear at all (even if by our logs we set the value through setApplicationIconBadgeNumber).
We logged all the app setApplicationIconBadgeNumber instances and there is never a set to '0' after being set to N for the app icon badge.
We also checked the system console and there are only system logs reporting the correct set of the app icon badge: [com.mychatapp.app] Setting badge number to N
In my case, it was because I was using Airship's SDK and instead of using their code for updating the badge count, I was using the iOS native code and that caused a glitch, especially right after a reinstallation and grant the push perms again
Related
I don't understand why when my app is killed. I received an incoming notification and selected that notification until when the app was opened I found the ui design was messed up, I couldn't even access the address I had previously set for the notification to go to the required screen. please help me
Here is the screen I'm getting the error on
https://i.stack.imgur.com/5jjzw.jpg
I’m putting an app into background.
Assuming that I’m not doing anything to keep the app alive in the background, then the app goes through suspended state in a matter of 5 seconds. Right?
What happens if I then tap on the app icon? That’s not suppose to trigger a didFinishLaunch right? It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications. I won't be getting any other callback. Right?
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon. Right? Does it also persist device restarts but not force-restart?
The only time I won’t be brought back to the screen I was at (before hitting home) is if the device receives a memory warning and my app is flushed out of suspended state. At this point tapping on the app icon will result in didFinishLaunch. Right?
(I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase. Most of the time it just goes back to its previous screen)
I've already seen Will ios terminate the app running in background after a specific time? but that doesn't address all aspects I want.
It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications.
Right, if your app was not terminated in the background.
I won't be getting any other callback.
Not necessarily true. If you were summoned to the front by a local notification, for example, you'll also get an event about that.
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon.
Not necessarily. The app might well be terminated silently in the background.
Does it also persist device restarts but not force-restart?
Absolutely not. How can the app run when the device is off? Shutting down the app terminates every app.
I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase
It's not a matter of time. The watchdog process is constantly combing the suspended apps looking for the ones that take up too much memory so that other apps can run. You must not be surprised if yours is one of them.
You can come back to the front launching from scratch or by coming back to life from suspension; it's the most basic fact of iOS app life! You just need to accept it.
But there are lots of things you can do to reduce your chances of being terminated in the background. Giving up memory-consuming objects as you background is first on the list.
I have a strange issue with badges.
Here is the code which sets badge count getted from backend
UIApplication.shared.applicationIconBadgeNumber = badge
so the issue is, when app connected to debugger its successfully changes the badge, but when I disable it from debugger and run it, the badge icon doesnt change, and its only on one iphone, other ones work fine with same code.
So can you help to understand the problem with this one?
Problem
Sending silent notifications for release app version shows next log:
SpringBoard[48] <Warning>: High Priority Push: [Bundle ID] - BAR Disabled
Any idea? BAR Disabled??
Looks like when "BAR Disabled" log appears, the method (didReceiveRemoteNotification - fetchCompletionHandler) is not being called.
More info
BAR Disabled Log appears in production app in tested iphone 4s and iphone6
BAR Disabled Log is not appearing in tested iPhone5, and fetchCompletionHandler is called.
BAR Disabled Log is not appearing while debugging.
BAR Disabled Log appears with param "content-available":1
Tested with swift and objective-c
Tested with Distribution profile(testflight) & adhoc profile(itunes)
iOS version 9.3.1
Notification
{"aps":{"alert":"Test","sound":"default","content-available":1}, "data" : 345}
Result
Displays notification with text "Test" and plays default sound but fetchCompletionHandler is not being called, just a log:
SpringBoard[48] <Warning>: High Priority Push: [Bundle ID] - BAR Disabled
BAR Disabled means that Background App Refresh is not enabled so app is not able to perform fetchCompletionHandler.
From device go to Settings > General > Background App Refresh and turn on Background App Refresh.
If you quit an app from the app switcher, it might not be able to run or check for new content before you open it again.
More Info about Background App Refresh (BAR):
This is a whole other thing that works outside of the 10 minutes grace period. An app with BAR enabled is allowed to wake up every now and then until it's quit from the app switcher or the phone resprings/reboots. There is no 10 minute restriction here, and it's important to understand that BAR is different from backgrounding. By "wakes up" I mean "opens a sleepy eye and downloads some stuff, then goes straight back to sleep". If you kill the app from the app switcher, its BAR privilege is gone as well.
BAR-enabled apps are usually scheduled to wake up at opportune moments to update themselves. These moments include:
when the device is actively in use
when the device is connected to wifi and/or a power source
when a push notification for the app is received
when location changes
From Apple themselves: iOS learns patterns based on your use of the device and tries to predict when an app should be BAR-updated in the background. It also learns when the device is typically inactive, such as during the night, to reduce update frequency when the device is not in use.
Thanks to the information shared by /u/Niruga, there is also what is called a "silent" push notification that apps can make use of to wake their app up for BAR-updates. Silent push notifications are not seen by the user.
For example, Dropbox makes use of BAR and location to keep its photo upload working past 10 minutes for as long as it takes to finish uploading. It won't be constantly uploading, since that's not what BAR does. So what's happening in Dropbox is that it uses location changes to make the app wake up and upload for 10 minutes before it goes to back to sleep, then waits for the next location change to make the app wake up again and continue where it left off, and repeat until all uploading is done, all without the user having to keep the app open in the foreground.
To decide whether or not to enable BAR, think about whether you trust the app developers not to abuse the function.
Hope it helps.
ref: https://www.reddit.com/r/jailbreak/comments/3eao32/discussion_write_up_ios_backgrounding_and/
I am developing an Apple Watch2 App. My app stops running after a few seconds the screen turns into black but I want my app to run on the screen even after the screen turns into black. So that the user can see my app anytime on the screen by not tapping to the app icon again.
I tried to add a timer and then an animation and also made dynamic UI changes to avoid my app to stop running but it didn't work - after a few seconds the screen turns into black, the app stops and the main watch clock screen comes into display.
I saw that it is possible to do this functionality in "Apple Workout App". When the user starts a timer, even if the screen turns into black, the app doesn't stop running so the user checks the timer anytime she/he wants. So please let me know how I can get this functionality?
Thanks,
E.
You can't control this from your app; The user selects the behaviour for their watch using the Apple Watch app on their phone. They can select "Show watch face" (the default) or "Resume Last Activity". They can also select how long the display stays on for on a tap; either 15 or 70 seconds.
Some Apple apps such as Maps, Remote and Timer can override this setting and if a fitness app has an active HealthKit workout activity then the watch will also resume the last activity on wrist raise/face tap. If your app isn't using HealthKit for a workout activity then you have to live with the behaviour the user has selected.