2017-03-24 10 views
0

アプリがフォアグラウンドで実行されているときと同じように、バナープッシュ通知の表示をトリガーすることは可能ですか?バナーiOsプッシュ通知(アプリがフォアグラウンドにある場合)

:私は、バージョン41.2ネイティブ反応し、反応するネイティブプッシュ通知2.2.1

私はAppDelegateに以下を追加することで、それは、IOS 10で可能であることを探してから、注意して使用しています

HA-ネイティブに反応してい

// Required for the localNotification event. 
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
[RCTPushNotificationManager didReceiveLocalNotification:notification]; 
} 

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
     willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ 
    completionHandler(UNNotificationPresentationOptionAlert); 
} 

しかし、これは以下のようなdidReceiveLocalNotification方法をヒットしている代わりにヒットを取得し、していないように見えますuserNotificationCenterにアクセスできますか?あるいは、他の方法を使って同様の結果を得ることは可能ですか?

ありがとうございます。

答えて

2

ここで私はこれをどのようにして稼働させることができたのですか。

AppDelegate.hファイルでは、以下のようなUNUserNotificationCenterDelegateをUserNotificationsをインポートして設定する必要があります。

#import <UIKit/UIKit.h> 
#import <UserNotifications/UserNotifications.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate> 

が続い AppDelegate.mファイルで、あなたの didFinishLaunchingWithOptionsメソッド内 [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];を追加する必要があります。

次に、userNotificationCenterよりも優先されるように、didReceiveLocalNotificationdidReceiveRemoteNotificationを削除する必要があります。

次に、userNotificationCenterハンドラを次のように追加します。

- (void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { 

    completionHandler(UNNotificationPresentationOptionAlert); 

    } 

ホープこれは私のようにiOSの開発と同様になじみのない他のいくつかの反応ネイティブ開発者を支援します。

0

iOSの場合、アプリケーションがフォアグラウンドであれば、ローカル通知やリモート通知に関係なく、バナー効果は発生しません。しかし、あなたがあなたが言及した代理人の方法を通じて通知を受けるでしょう。したがって、バナーを必要とする場合は、独自のバナーを実装する必要があります。

+0

こんにちはエルビン、ご意見ありがとうございます。これが本当に標準的な行動であり、強制される必要があることは事実です。しかし、Monzo Appが実装しているものは可能です - 私は地元の通知で管理し、リモート通知で管理したら回答を投稿します。 – flintchip

0

スウィフト3コード、IOS 10とあなたのappdelegateで

import UserNotifications以上、アプリのdidFinishLaunchingWithOptions機能でUNUserNotificationCenterDelegate を設定

let center = UNUserNotificationCenter.current() 
     center.delegate = self 
     center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in 
      // Enable or disable features based on authorization. 
     } 
     application.registerForRemoteNotifications() 

を追加するアプリが受信したときに、次UserNotificationDelegateメソッドが呼び出されます前景状態とバナーでの通知が表示されます

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) 
{ 
    completionHandler([.alert, .badge, .sound]) 
} 
関連する問題