Why push notification is shown when app is foregro

2019-01-29 06:58发布

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.

标签: ios ios10
2条回答
Luminary・发光体
2楼-- · 2019-01-29 07:50

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.

查看更多
Bombasti
3楼-- · 2019-01-29 07:59

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.

查看更多
登录 后发表回答