0

I'm having weird experience. Why push notification is shown (in native banner) when app is foreground? It's only reproduced on iPhone 7 (iOS10.1.1).

I tested on the other iPhones like a iPhone 5 and iPhone 6s with same app, same iOS version. It's not shown when app is in foreground as normal.

Push banner appears only on iPhone 7.

Is this normal?

My app is created by Xamarin.forms. (For now, Xamarin convert c# code to objective C, so it's basically objective c)

Thanks.

Bright Lee
  • 2,306
  • 2
  • 27
  • 55
  • Can you more elaborate your this line **I tested on the other iPhones - but same app, same iOS version, but happens only on iPhone 7.** – Wolverine Dec 01 '16 at 08:52
  • 1
    @BrightLee I recommend also adding if your using `Swift`, `Objective-c`, or some other framework for your app. As well as if you are using Apple's APIs or an SDK the create your notifications. – jkasten Dec 01 '16 at 09:00

2 Answers2

6

Starting with iOS 10 developers can control how notifications are shown when the app is in focus. This is done by setting up a UNUserNotificationCenterDelegate.

The userNotificationCenter:willPresentNotification:withCompletionHandler: will be fired on this delegate where UNNotificationPresentationOptions can be passed to the completionHandler to determine if the notification should be displayed along with its sound and badge value update.

Based on your question it sounds like you are using a SDK or framework to add notifications. You can still use a UNUserNotificationCenterDelegate along with most notification SDKs.

Note that on iOS 9 and older devices this delegate isn't available and notifications will not show in the notification center when they are received while your app is in focus. Instead you must must still use UIApplicationDelegate for older versions of iOS and show an in app message for them.

jkasten
  • 3,899
  • 3
  • 32
  • 51
  • Thanks jkasten. Yes I forgot that I set these delegate already. I'm sorry for I can only set "answer" mark to only one. – Bright Lee Dec 01 '16 at 09:40
  • How to catch event when user tap to notification in foreground? – huynguyen Oct 18 '17 at 08:41
  • When you assign a `UNUserNotificationCenterDelegate` the notification events on the AppDelegate will no longer fire so you will need to add this new method to this delegate [`userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:`](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649501-usernotificationcenter?language=objc). – jkasten Oct 18 '17 at 11:49
5

If an application is upgraded to iOS10, and developers of their app have used the UserNotifications framework.Then there are functions by which notification can be displayed as a native banner when app is in foreground.

The UNNotificationPresentationOptions flags allow you to specify UNNotificationPresentationOptionAlert to display an alert using the text provided by the notification.

It effect will same if you are using iOS10 , and app is compatible with UserNotifications framework.

As you mentioned, you have tested the app with Other device with same version, Then might be their app's latest version is not installed on those devices.

It is not based on iPhone7 only. That will work when iOS10 is installed in your device and application is using UserNotifications framework for handling the notification.

Wolverine
  • 4,264
  • 1
  • 27
  • 49