當我的應用程序處於前景時,我正在使用Cordova和插件phonegap-plugin-push, 我沒有看到通知警報。 我需要做什麼? (我知道在Android平臺上執行此操作的方式(在PushNotification的init方法中設置爲「forceShow」:true),但這僅適用於Android) 預先感謝您的回覆。cordova iOS通知不能在前臺工作
回答
丹尼斯,
通知不能在前臺工作。它只能在後臺運行。在前臺處理它需要在委託方法中實現邏輯。 以下是在前臺顯示通知的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];
}
}
它會幫助你解決你的問題。
在iOS中,如果您的應用程序處於前景中,則不會顯示推送通知警報。要實現它,您應該在推送通知接收委託中編寫警報代碼,前提是您的應用程序處於前臺。要知道iOS中的應用程序狀態,這是代碼。
+(BOOL) runningInForeground
{
UIApplicationState state = [UIApplication sharedApplication].applicationState;
return state == UIApplicationStateActive;
}
@iamgam感謝您的回覆!但我使用科爾多瓦,你知道如果是在cordova修改javascript的方法嗎?或者只能使用本機代碼? – Denise
@Denise,請閱讀此[鏈接](https://github.com/phonegap-build/PushPlugin)'// iOS function onNotificationAPN(event){ if(event.alert) { navigator.notification。警報(event.alert); (event.sound) var snd = new Media(event.sound); snd.play(); (event.badge) { } pushNotification.setApplicationIconBadgeNumber(successHandler,errorHandler,event.badge); } }' –
如果這可以幫助你,請投票並接受答案。 –
如果妳不想碰iOS原生的東西,那麼你就可以顯示自己的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
});
謝謝!我用類似的方法使用push.finish()方法解決了問題,現在顯示了橫幅,但是當它消失時,通知不會存儲在設備讀取通知列表中,這是一個問題!任何想法來解決它? – Denise
我不理解你的新問題。但我想提供一些可能對您有所幫助的信息。 1.首先,該橫幅將成爲應用程序Web視圖的一部分,因此它絕不會存儲在通知中心的本機通知列表中。 2.當橫幅將消失,那麼它將不再是你的應用程序的一部分。 3.您也可以使用** cordova-plugin-local-notifications **來顯示本地通知,而不是橫幅 –
- 1. Android後臺通知不工作在Firebase
- 2. Firebase通知不在後臺工作
- 3. 推送通知不工作在ios 8.3
- 4. ios推送通知不能在服務器上工作
- 5. 後臺iOS通知
- 6. PhoneGap的通知不工作
- 7. 推送通知不工作ios 8.3?
- 8. Xamarin的iOS推送通知不工作
- 9. IOS推送通知聲音不工作
- 10. 解析推送通知不工作ios
- 11. iOS本地通知聲音不工作
- 12. 在前臺彈出通知
- 13. 在前臺不顯示通知
- 14. cordova navigator.camera.getPicture不能在android中工作
- 15. Cordova - 通知後臺運行服務
- 16. 帶有Firebase通知的iOS,全部不能正常工作
- 17. 推送通知以使IOS不能正常工作
- 18. 不能在MySQL-工作臺
- 19. 本地通知聲音不能在前臺
- 20. 的Joomla MySQL不能通過工作臺
- 21. cordova平臺添加ios不能在mac上工作(ios子項目創建時發生錯誤)
- 22. 當應用程序不在後臺或前臺,不能推送通知到通知管理器
- 23. 通知JS不能正常工作
- 24. 推送通知不能正常工作
- 25. 短信通知 - 不能正常工作
- 26. FLAG_ACTIVITY_CLEAR_TOP不能從通知部分工作
- 27. cordova iOS連接對象不能正常工作
- 28. FCM通知,通知時,請單擊應用程序在前臺後臺不
- 29. Cordova InAppBrowser EventListeners無法在ios上工作
- 30. 通知工作4.0+,但不工作3.0前
謝謝所有!我使用cordova插件的push.finish()方法解決了問題,現在顯示了橫幅,但是當它消失時,通知不會存儲在設備讀取通知列表中,這是一個問題!任何想法來解決它? – Denise