Send activity/update ios app to a user while in background - ios

I am building my first app but wanted to know if there is a way to send updates or activity notifications to a user without a push notification.
These updates could include:
icon badge
Sound
Alert that appears on the lockscreen (I believe this is the push notification)
What can be done without requiring the user to give permission? I have tasks for the user at x time and want to remind them at that time.

Related

Is there a way to get iOS System alarm notifications?

I'm coding a timer app, and I've noticed a major drawback: while I can make the alarm send the user a notification when the timer is done, it can only send notifications, while the built-in Clock app triggers a fullscreen alert no matter what screen you are on, ensuring the user sees the end of the timer. Is there any way to integrate my app with iOS to allow this fullscreen alert functionality? I send a notification when the alarm finishes - is there a specific type of notification that I need to send?
Unfortunately not. You have to stay within the confines of your app. The iOS Clock app has special privileges because...well, it's made by Apple.
Is the notification not enough? I would think that would alert the user adequately.

iOS: Show UILocalNotification again after unlock

I need to re-show an uilocalnotification again after user unlock his iphone, because the notification is an incoming call. Currently, after user unlock his iphone, the notification is "gone" back to the notification center, and the ringtone is silent as well. User have to manually pull down notification center to see the call notification.
I wonder how Whatsapp deal with situation like this? Whatsapp will re-display the top banner notification again after I unlock my phone.
I searched google and found 2 ways as below:
Using NSTimer to schedule cancelLocalNotification() and presentLocalNotification() again . I tried this but I got double same notification and NSTimer fails to run more than twice, although it was set to repeat.
Using com.apple.springboard.lockstate to detect when user unlocked their phone . But is it private API that can lead to rejection on app store?
Thanks!

How to get the push notification payload when force-quit / swipe up to kill the iOS app without tapping on the banner/alert?

I’m building an app which handles notifications pushed from Parse, and trying to create a notification history function. I’ve enabled the background modes successfully, so when the app is running in the background, the app can get the payload well via application:didReceiveRemoteNotification:fetchCompletionHandler even the banner/alert is not tapped. However, when force-quit / swipe up to kill the app, application:didReceiveRemoteNotification:fetchCompletionHandler is not called.
Is there any method to implement for getting the push notification payload when the app is killed without tapping the banner/alert? Thank you in advance!
You can't get a notification's payload if your app is killed.
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user. In other
cases, though, the user must launch the app explicitly or reboot the
device before the app can be launched automatically into the
background by the system. When password protection is enabled on the
device, the system does not launch an app in the background before the
user first unlocks the device. -
Understanding When Your App Gets Launched into the Background
Anyway, push notifications are not reliable.
It means that you can not be sure that they will ever be delivered.
If you want to keep a "notification history" list, do it server-side and fetch it in-app (in a totally not push related way).
Each time you send a push notification, keep it's content in database, like any object. Then when the user opens the history list, fetch the list like any other parse object.

How to detect when user clears your app's notification

My app has notification feature. When I receive a notification I show a badge in my app icon.
As I know, when my app is on background, since user does not clicks on the notification at notification center, my app does not know that it has a notification. So it can not change the badge number.
Also from this topic:
Detect when a user clears notification from the notification center
If user clears the app's notification, the app can not detect it.
So the problem is here:
- My app is on background
- User receives a notification related to the app
- App adds a badge with number 1 to the app's icon
- User deletes the notification from notification center
- App never understands that notification has been removed so that it can remove the badge!!!
So how other apps fix this problem? Is there any solution for this?
There is no way to check when the user clears notifications for your app.
The usual practice for clearing the app badge is when the user has viewed the applicable content within your app (e.g. messages in a messaging app), or otherwise just clearing the badge the next time the user opens your app if this is not applicable, or you can't easily segment the notifications and connect them to viewable content in your app.
Note: you should not be relying on the user tapping on your notifications in order to get their content. If your user doesn't tap your notification, your app has no way of ever finding out its content, or that it ever existed.
Instead, when your app is opened, it should connect to your server to download updated content, then you can use this complete, accurate information to update your app badge as required. Do not try to fetch content from your notifications.
You can add custom action to your notification: "Mark as read" or "Delete". Remove badge in -application:handleActionWithIdentifier:... method.
Yes, it doesn't allow you to detect user cleans the notification. But there is no any way to do it. So I suggest a workaround to solve this problem.

Don't show push notifications

Is there an opportunity to stop showing push notifications via an app?
I have an app connected to a database. When someone sends me something like a message I will get a push on my devices (lock-)screen. But if the user does not want to see specific notifications for something, maybe a new message by person XY, it should not appear!
So is there an opportunity for hide specific pushs via the app or do I have stop them server-side?
You'll have to make the change server-side. From the app side, you can't stop only certain push notifications, because it's while the app is backgrounded (or not even running) that push notifications will be showing, so your app has no control over whether specific ones will show or not.
If the app is not in the foreground then the push notifications don't get delivered to the app, they get delivered directly to the user and hence there is no chance for the app to intervene and filter them.
BUT if your app is for iOS7 only then you could use silent background push notifications, then when the push is delivered the OS will rouse your app and the push will be delivered to it, then the app can examine the content of the push and also examine the user preferences and then present the background push as a local push or not (to the user a local push looks just like a remote push).
One caveat is that if the user forcefully terminates your app (by upwardly swiping it out of the task manager) and the user has not restarted it then the OS will not deliver the silent push to it.

Resources