2016-08-01 9 views
1

私のアプリがフォアグラウンドになっているときにCordovaとプラグインphonegap-plugin-push、 を使用しています。通知アラートが表示されません。 私は何をしなければなりませんか? (私はAndroidプラットフォームでこれを行う方法を知っています( "forceShow"を設定すると、PushNotificationのメソッドinitでtrueですが、これはAndroidのみで動作します) あなたの返信をお寄せいただきありがとうございます。コードバーiOS通知がフォアグラウンドで機能しない

+0

は、すべてに感謝!私はcordovaプラグインのpush.finish()メソッドを使って解決しましたが、現在バナーが表示されていますが、表示されなくなると通知はデバイスの読み込み通知リストに保存されません。それを解決するための任意のアイデア? – Denise

答えて

0

デニス、

通知はフォアグラウンドでは機能しません。これはバックグラウンドでのみ機能します。フォアグラウンドでそれを処理し、デリゲートメソッドでロジックを実装する必要があります。 以下はフォアグラウンドで通知を表示するObjective Cのコードスニペットです。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    application.applicationIconBadgeNumber = 0; 
    //self.textView.text = [userInfo description]; 
    // We can determine whether an application is launched as a result of the user tapping the action 
    // button or whether the notification was delivered to the already-running application by examining 
    // the application state. 

    if (application.applicationState == UIApplicationStateActive) 
    { 
     // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view. 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"Your App name received this notification while it was running:\n%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

     [alertView show]; 
    }  
} 

問題を解決するのに役立ちます。

+0

ご返信ありがとうございます!しかし、私はコルドバを使用している、あなたが知っている場合は、コードバでjavascriptを変更することですか? – Denise

+0

安全な方法@Denise。自由に使用することができ、アプリケーションの拒否は発生しません。お返事 – Sabby

0

アプリがフォアグラウンドの場合は、プッシュ通知アラートは表示されません。これを実現するには、アプリケーションがフォアグラウンドにある場合、プッシュ通知受信代理人の警告のコードを記述する必要があります。 iOSのアプリケーション状態を知るために、これがコードです。

+(BOOL) runningInForeground 
{ 
UIApplicationState state = [UIApplication sharedApplication].applicationState; 

return state == UIApplicationStateActive; 

} 
+0

@iamgamご返信ありがとうございます!しかし、私はCordovaを使用しています。あなたが知っているのは、コードブラウザでJavaScriptを修正する方法があるのか​​、それともネイティブコードでのみ可能なのでしょうか? – Denise

+0

@Denise、この[リンク](https://github.com/phonegap-build/PushPlugin) '// iOS 機能onNotificationAPN(イベント){ if(event.alert) { navigator.notification。警告(event.alert); (event.sound) { var snd = new Media(event.sound); snd.play(); } if(event.badge) { pushNotification.setApplicationIconBadgeNumber(successHandler、errorHandler、event.badge); } } ' –

+0

これが役立つ場合は、投票して回答を受け入れてください。 –

1

uが、あなたが方法を以下に(iOSのプッシュBanerなど)バナー独自のcustmizeのHTML/CSSを表示することができ、IOSネイティブのものに触れたくない場合は、次の

push.on('notification', function(data) { 
    If(platform == "iOS" && data.additionalData.foreground){ 
    // Show your Baner here 
// U can also define call back on clicking of that banner 
//Like navigation to respective page or close that banner 
}); 
+0

ありがとう!同様の方法でpush.finish()メソッドを使用して解決しましたが、現在バナーが表示されていますが、通知が表示されなくなると、デバイスの読み取り通知リストにその通知が保存されません。それを解決するための任意のアイデア? – Denise

+0

私はあなたの新しい問題を正しく理解していません。しかし、私はあなたを助けるかもしれないいくつかのより多くの情報を提供したいと思います。 1.まず、このバナーはアプリケーションのWebビューの一部になるため、通知センターのネイティブ通知のリストには決して格納されません。 2.バナーが消えると、もうアプリケーションの一部になりません。 3.バナーの代わりに、** cordova-plugin-local-notifications **を使用してローカル通知を表示することもできます –

関連する問題