gpt4 book ai didi

ios - 在 iOS 应用 [phonegap/cordova][Pushwoosh] 上将推送通知显示为警报消息

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:04 25 4
gpt4 key购买 nike

您好,感谢您查看这个问题,当我的 iOS 应用程序打开时,我无法接收推送通知。不过,当应用程序在后台运行时,它可以完美运行。但是当应用程序打开时,它甚至没有触发应该将通知显示为警告消息的“推送通知”事件。

我遵循了这些说明,但做了一些调整: http://www.pushwoosh.com/programming-push-notification/ios/ios-additional-platforms/push-notification-sdk-integration-for-phonegap/

这是我在页面加载时的代码:

document.addEventListener("deviceready", pushwooshReady, true);
document.addEventListener("push-notification", displayPushwooshMessage, true);

pushwooshReady 函数:

function pushwooshReady() {
initPushwoosh();

if(device.platform == 'iOS') {
app.receivedEvent('deviceready');
}
}

initPushwoosh 函数:

function initPushwoosh() {
//get the plugin
var pushNotification = window.pushNotification;

if(device.platform == 'iOS') {
//call the registration function for iOS
registerPushwooshIOS();
} else if (device.platform == 'Android') {
//call the registration function for Android
registerPushwooshAndroid();
}
pushNotification.onDeviceReady();
}

这是 registerPushWooshIOS 函数:

function registerPushwooshIOS() {
var pushNotification = window.pushNotification;

//register for push notifications
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid: PW_appid, appname: PW_appname},
function(status) {
//this is a push token
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);

//we are ready to use the plugin methods
onPushwooshiOSInitialized(deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});

//reset badges on application start
pushNotification.setApplicationIconBadgeNumber(0);
}

这是我的 displayPushwooshMessage 函数:

function displayPushwooshMessage(event) {
if(device.platform == 'Android') {

var msg = event.notification.title;
var userData = event.notification.userdata;

if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}

alert(msg);

} else if(device.platform == 'iOS') {
var notification = event.notification;
alert(notification.aps.alert);
pushNotification.setApplicationIconBadgeNumber(0);
}
}

非常感谢您的帮助。

最佳答案

好吧,看来我又要回答我自己的问题了。

我成功了,但没有使用 javascript 的 alert() 方法,因为 pushwoosh 网站上的说明对我来说并不适用。所以我所做的非常简单,但我花了一天时间才弄明白,因为我没有任何 Objective-C 背景。

我在 PushNotificationManager.mhandlePushReceived 函数中注释掉了 if 语句。这是代码:

    NSString *alertMsg = [pushDict objectForKey:@"alert"];

bool msgIsString = YES;
if(![alertMsg isKindOfClass:[NSString class]])
msgIsString = NO;

//if(!isPushOnStart && showPushnotificationAlert && msgIsString) { <- Commented this out
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.appName message:alertMsg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
alert.tag = ++internalIndex;
[pushNotifications setObject:userInfo forKey:[NSNumber numberWithInt:internalIndex]];
[alert show];
return YES;
//} <- Also this one.

[self processUserInfo:userInfo];

它奏效了。我什至不知道为什么它不起作用,它来 self 下载的 SDK。哦,好吧,我不确定是否有人遇到过或将会遇到同样的问题,但我希望这个答案能帮助那些将来会遇到的人。

**更新:

其实报错是不一样的,不需要上面的解决方法。我收到了 Pushwoosh 支持团队的以下回复:

Dmitry Dyudeev (Pushwoosh)
May 29 16:41

Hello Clint,

Thank you for contacting us!

It turns out that you have located a bug in our plugin. Thank you for pointing it out! We will >update our plugin in the nearest future.

Meanwhile, since updating the plugin will take some time, you can find the onDeviceReady method in the PushNotification.m file and add the following line at its end, it will solve the issue:

     [[NSUserDefaults standardUserDefaults] synchronize];

Please let me know about the results!

Regards,
Dmitry Dyudeev
Pushwoosh Team

关于ios - 在 iOS 应用 [phonegap/cordova][Pushwoosh] 上将推送通知显示为警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23908886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com