gpt4 book ai didi

ios - 带有 Cordova 应用程序的 Azure 通知中心 (iOS)

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

我正在尝试使用通知中心推送 Cordova 应用程序(iOS)

Azure 面如下。

Notification Hub

Notification Hub

客户端源代码如下。我确定Azure客户端已正确连接并且注册成功。

    function initPushNotification(){
var push = PushNotification.init({
android: {
senderID: "12345679"
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});

var registrationSuccess = function () {
alert('Registered with Azure!');
};

var registrationFailure = function (error) {
alert('Failed registering with Azure: ' + error);
};

push.on('registration', function(data) {
client.push.apns.registerTemplate(handle,
'myTemplate', template, null)
.done(registrationSuccess, registrationFailure);
});

push.on('notification', function(data) {
alert('Push Received: ' + data.message);
});

push.on('error', function(e) {
alert(e.message);
});

但是当我从通知中心页面执行测试发送时,没有任何反应。我尝试了从简单的 ruby​​ 脚本直接到 APNS,通知正确地发送到 iPhone。

Notification Hub Test

有人知道如何修复它或任何信息吗?

我的环境是

  • MacBook Pro
  • OS X ElCapitan
  • Cordova 6.0.0
  • com.microsoft.azure-mobile-services 1.2.9“Windows Azure 移动服务”
  • phonegap-plugin-push 1.6.2“PushPlugin”

最佳答案

很可能由于某种原因对 client.push.register() 的调用没有成功。我没有使用您正在使用的特定插件,我正在使用 azure-mobile-apps-cordova-clientphonegap-plugin-push 结合。到目前为止,这个组合符合我的目的。

您可以在此处找到更完整的示例:Add Push Notifications to your Apache Cordova App .

我要补充的一件事是,当您在 azure-mobile-apps-cordova-client 插件中调用 Push.register() API 时,您可以为其提供一个错误函数回调,如果 API 调用失败,该回调函数将被调用。它看起来像这样:

push.register('apns', data.registrationId, null, null, function(err) {console.log(err);});

最后,在 Visual Studio 中,您还可以连接到通知中心并列出和管理注册。这对于确定 APNS 注册是否真正被接受很有用。

关于ios - 带有 Cordova 应用程序的 Azure 通知中心 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36614102/

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