I have an iOS 10 app and watchOS 3 extension that uses iOS 10 User Notifications Framework. The local notification is scheduled from the iOS app, and is shown on the watch when the iPhone is locked, and shown on the iOS app on the lock screen if I raise my iPhone, and don't respond to the watch. The iOS notification have three background action buttons.
If I respond to the notification on my iPhone, the userNotificationCenter(_:didReceive:withCompletionHandler:) UNUserNotificationCenter delegate method is called correctly. But if I instead tap on one of the action buttons on my watch, the function is not called.
According to Apple's App Programming Guide for watchOS, under the section Responding to Selected Actions:
For background actions, the handling of actions depends on where the notification was scheduled:For local notifications scheduled on iPhone, background actions are handled by your iOS app regardless of which device displayed the notification.
This is not happening, and I don't know why. Have anyone got this working from the watchOS?
It looks like I didn't put the correct options in the UNNotificationAction. The options should be an empty array, instead of the .foreground I had mistakenly put there.
So for e.g. the Just Practice button, the correct action for it to be background is:
let justPracticeAction = UNNotificationAction(identifier: "justPractice", title: "Just Practice", options: [])
Related
I am sending notifications from firebase.
Background notification works fine but I can't find something that worked in foreground for me.
I want to display the notification when the app is open same as when the app is in background.
with system notification sound and same banner display at the top of screen.
You can control this on iOS
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(badge: true, alert: true, sound: true);
package:firebase_messaging/firebase_messaging.dart
Sets the presentation options for Apple notifications when received in
the foreground.
By default, on Apple devices notification messages are only shown when
the application is in the background or terminated. Calling this
method updates these options to allow customizing notification
presentation behaviour whilst the application is in the foreground.
Important: The requested permissions and those set by the user take
priority over these settings.
[alert] Causes a notification message to display in the foreground,
overlaying the current application (heads up mode). [badge] The
application badge count will be updated if the application is in the
foreground. [sound] The device will trigger a sound if the application
is in the foreground. If all arguments are false or are omitted, a
notification will not be displayed in the foreground, however you will
still receive events relating to the notification.
I have an issue with my app's push notification on ios 7, it works when app in back ground or remove it from dock. But push messages DO NOT work (not appearing) when the app screen comes to foreground.
But it was fine with iOS 6. Any change require in coding or storyboard settings?
When PushNotification is arrive it calls didReceiveRemoteNotification method when app is in foreground.
And when your app is not in foreground it will send to Notification Center, and if user tap on notification from notification center then it will call didReceiveRemoteNotificationmethod.
//According to Apple Push notification Document.
Push notifications serve much the same purpose as a background application on a desktop system, but without the additional overhead. For an application that is not currently running—or, in the case of iOS, not running in the foreground—the notification occurs indirectly.
Check Link :)
I searched a lot and didn't find how to programmatically bring application to background so phone's home screen is shown. I don't want to terminate app, but just to programmatically make press on HOME button. Is there any way to do it?
No, unfortunately not. There is no public API that allows you to send a user back to the homescreen.
As shown in these questions:
iPhone - Sending the app to the background
Send App to Background process
Sending Application to background on iphone
Programmatically sending an iOS app to background
Brad Larson provides a detailed explanation to the answer of this question:
Suspend the application
Unfortunately, there is no background mode in iOS where the app can still run things while out of focus. Apple has designed the system to "pause" the application so state is preserved, but be careful the app can be terminated at any time.
You can do this by calling a private API but beware as said above Apple does not allow this on AppStore apps.
var x = UIApplication.SharedApplication;
x.PerformSelector (sel: new MonoTouch.ObjCRuntime.Selector ("suspend"), obj: x, delay: 5);
I have GuitarToolkit on my iPhone4S (iOS 5.01 - NOT jailbroken) It has a metronome feature which continues playing in the background, and also adds a red banner overlay (see screenshots) which persists on the home/lock screen and also when other apps are running. The banner is animating (background colour pulses) and it is also 'active' in that pressing it will return you to the GuitarToolkit app.
I know about the background audio APIs for the sound, but how does it do this banner? My first thought was local notifications, but nothing appears in notification center, and GuitarToolkit is not listed under Notifications in Settings.
My iPhone is not jailbroken and GuitarToolkit is available in the App Store, so what APIs is it using to achieve this?
Having an active AVAudioQueue creates that banner.
The banner appears because it’s got an open audio recording session—you’ll notice that the system Voice Memos app does the same thing, as does Shazam for a moment before it enters the background and Skype when you’re on a call with the app in the background. I’m not sure of the specific API, but that’s generally what’s going on.
is it possible to add a notification to the lockscreen that will not disappear?
or (my second choice)
Is it possible to add a notification to the lockscreen, which will be thre until the iPhone is unlocked the next time?
For example:
iPhone is unlocked
message incoming
lock iPhone
message is in lockscreen
unlock iPhone
message is not longer in lockscreen
Edit:
My goal is to have a notification on the lockscreen every time.
No, neither is possible. If your app is in foreground, it gets delivered to your app directly and is not displayed. If the screen is locked or you app is in background, the notification is shown.
in ios5 there is a new feature in notification that notifications are automatically shown in the lockscreen if the user select the option from the setting but your app cannot receive any notification if your app in foreground.