Random number in iOS app badge - ios

After I install and start my iOS app on device or in the Simulator, the red badge at the corner of the app's icon shows a 5 digits number.
I haven't noticed it for months, then installed some stuff to enable local notifications (linked the standard "PushNotificationsIOS", installed "react-native-push-notifications").
When I saw the bug, I removed everything notifications-related, and yet now I see it no matter how far I go back in my commits history. The number used to change after every notification, but now it is a stable 61'051 after a fresh install.
I would bet that the device is still sending thousands of notifs from an old bug, and the number is the result of a modulo.
What can cause the badge to show up with such a number? What did not get uninstalled properly?
Otherwise, can I remove the badge altogether?

I believe that you scheduled a number of local notifications and would like to get rid of them. Even that you removed all of the notifications related code, it does not mean that already scheduled notification won't be fired. So you have to manually clean them in your code.
If you use iOS 10+ notifications, this may help you:
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications()
center.removeAllPendingNotificationRequests()
Apple documentation

Related

iOS Push Notification Programming - Is there a way to disable push notification on iPhone by programming

A few days ago, I got the issue below.
I've been getting notifications for the past several days. The notification had been enabled, and the app was working (I received push notification) until it suddenly didn't yesterday. And when I open the app, it suddenly asks me to enable notification (please see the picture "iOS Push Notification Permission Alert.png")
iOS Push Notification Permission Alert.png
I guessed that my client removed the app and re-installed, so all permissions were lost. But they said that they didn't.
So, How can it happen?
My concerns are:
If notification was enabled, how can it show the alert above again? Is there a possible way?
If notification was not enabled, why have I received the notification for the past several days?
Under which scenario(s), would an app suddenly disable already enabled notification? Is there a way to disable notification permission for the app on the iOS phone by programming?
I will appreciate your answers so much!
P/s: I read the post disable push notification in app, but it doesn't help for my questions.
This is only possible if the app is reinstalled or the notifications are turned off from the settings.
There is one setting in iPhone which will allow iPhone to offload the unused apps and if this happened, there will be a cloud icon on the left of app title.The app will be reinstalled when you click it again.
And it seems that it will also happened when the storage of iPhone is not enough.
So I guess this happened in your client's phone.
This setting is in both Setting-iTunes & App Stores-Offload Unused Apps and Setting-General-iPhone Storage-Offload Unused Apps.

Even with "voip" present in "UIBackgroundModes" in "plist", iOS App does not auto start after device reboot in iOS10

I need my VoIP App to auto start after rebooting the device.
Apple docs clearly mention that :-
(=========EDIT: This is from official Apple docs please have a look at this before commenting or answering that the App cannot be launched without user interaction or silent push notification. Also have a look at Github project below, people have verified this behaviour)
Values for the UIBackgroundModes array
Value : voip Description : The app provides Voice-over-IP services.
Apps with this key are automatically launched after system boot so
that the app can reestablish VoIP services. Apps with this key are
also allowed to play background audio.
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1
I have ensured that :-
The App was running when the device was powered off.
VoIP is present in the plist and Capabilities section.
Ensured that app the certainly not launched after device reboot by adding logs to a file in the main method and the application:didFinishLaunchingWithOptions: method.
Screen of the device is unlocked at least once, after the device has been rebooted.
I even tried executing this GitHub example App with 36 stars to test
Boot Launch. https://github.com/lithium3141/BootLaunch
But even this App does not restart on reboot when I tried on device.
Hence, this leads me to think if something has been changed recently in iOS10 or am I still missing something here?
Okay, I investigated this a bit further, but first I should point out I did not verify this by actually trying to build a project for this as it would be too time consuming for me now.
I found this (already mentioned in the comments), this, and most importantly this tech Q&A.
What I gathered from especially the various comments of the Apple technicians in those threads, it appears that the behavior of iOS 10 has indeed changed. That means that the same code that connected to VoiP servers in past versions of iOS will no longer do that if you link your build against the latest SDK, i.e. iOS 10 libraries.
Now, in your case, you don't actually need a real VoiP connection, right? You are just interested in the "start after reboot" functionality, correct? At least the demo project you linked doesn't actually do any VoiP connection, the setKeepAliveTimeout:handler: method, for example, isn't even implemented.
I am aware this specific issue is not discussed in the linked threads or addressed in the Q&A, BUT:
It makes sense that, together with the entire legacy VoiP behavior, the reboot feature vanishes as well. Were you to switch to Push-Kit VoiP, your app wouldn't need to be started after a relaunch, it would restart once the next remote notification arrives (and VoiP notifications have high priority so there's supposedly no delay).
Obviously I am deducting the rationale behind this entire thing here and can't guarantee Apple really thought along those lines, but it makes sense: The entire reason for a (legacy) VoiP app to be (re-)launched after a reboot was that it needed to make a connection, i.e. it needed to run some code. With push notifications that is no longer necessary (the OS basically does that for you behind the scenes to get those notifications), so it makes sense that they removed this functionality along with the entire legacy VoiP approach altogether.
You could test this by compiling against the older SDK (i.e. use Xcode 7 as the Q&A suggests) and see whether it relaunches then. That one apple staffer actually explained that the OS does indeed distinguish on the build SDKs for apps, which is totally counter-intuitive to me. Apparently in this case it would decide "hey, this is an older app, so it expects to be relaunched cause its SDK was documented that way" for apps build on Xcode 7 and "Oh, this app is a new one, so I don't need to stick to the old ways" otherwise. Wowsies.
TL;DR: To me it strongly looks like yes, the iOS SDK changed this behavior along with abandoning the entire old, notification-less VoiP approach. Compiling against the new SDKs will result in apps not being relaunched after reboot.
For the record: I can understand the angry people in those threads. While there might be technical reasons for the change, this specific consequence was far from obvious. If a method is deprecated, but the project still compiles and runs I wouldn't expect such a process to fail in that manner. Those apps don't crash, they're just "treated differently by the OS", which not quite the same. At least I would have expected the documentation to be clearer about this in the new SDK.
App will invoke in background when it is in terminated mode only with push kit silent notification and certificates has to be generate for push kit, not with normal APNS notification and normal push notification certificates.
From back end, your payload has to be like this.
$body['aps'] = array(
'content-available'=> 1,
'alert' => $message,
'sound' => 'default',
'badge' => 0,
);
Once you get pushkit payload, then schedule local notification with sound file, your app will be invoked in background upto your sound file plays.( Max 30 seconds ) Til then you have to complete your background task.
Kindly do refer some important details about push kit integration step by step process
https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Life cycle of app - when app is in terminated and push kit payload comes
First of all
didFinishLaunchingWithOptions // will invoke
Then
didReceiveIncomingPushWithPayload // payload method gets invoke
Then if you have local notification
didReceiveLocalNotification // receive local notification
Then
handleActionWithIdentifier // handler method if you have action buttons ( local )
Then if you have remote notification
didReceiveRemoteNotification // receive remote notification
Then
handleActionWithIdentifier // handler method if you have action buttons ( remote )
Note - Without tapping on app icon or receiving push kit payload, your app will never gets revoke/open/repoen automatically. If you want your app is VOIP based and app gets revoke after device reboot. Not possible.

App notification sound defaulting to off in iOS 7

Starting in iOS 7, my app's entry in Notification Center has sounds defaulting to off for some users. Since my app is an alarm clock and needs to use UILocalNotifications all the time, this obviously is a major problem. Does anyone know what might have changed to cause this problem? And is there anything that can be done to address it?
I have an app that uses notifications too (timing meeting agenda items), and I agree that notification sounds are critical for an app like this. But app can't override the settings in Settings -> Notification Center, so the user must set the notification sounds there.
What I found was that the settings stayed the same when I upgraded the phone to iOS 7, but a re-install of the app can trash them - if the app was deleted before the upgrade. Deleting the app and re-installing (on iOS7 and earlier) doesn't change the notification settings.

Push Notification iOS resetting

I want to reset the push notification setting for my app. I have read the apple documentation regarding resetting the settings (which didn't help) and some questions here as well (which didn't help either). So in the last I reset my iPhone by going to settings->General->Reset ->Erase All Content and Settings (That didn't worked as well.)
Any other solution?
BTW I am using iOS 6.1
https://developer.apple.com/library/archive/technotes/tn2265/_index.html
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
You can also move your clock by a day after uninstalling the app and try.

Changing Icon per Day

Just like the Calendar app on the iphones and ipods, how do I make the Icon change per day?
I assume this is for an iOS app. The answers is, you can't. The Calendar app has access to functionality in iOS that us mere mortal developers cannot access. You may be able to pull this off with a jailbroken phone, but I've never tried that.
Since changing the icon is not officially supported, if it's numerical information you want to show, you can use the Notification Badge instead.
Updating iOS badge without push notifications
So you could make it show today's date in the badge, and schedule the badge to update at midnight, or show the current temperature and schedule it to update hourly.
There is a new solution for this situation.
You can use
setAlternateIconName(_:completionHandler:)
iOS 10.3 is out with xcode 8.3.
check out solution here

Resources