ios - 需要指导在 Cordova 应用程序中使用 native APNs/GCM 为 iOS 推送通知

标签 ios cordova push-notification apple-push-notifications apns-sharp

我正在使用推送通知 plugin在我的 Cordova 应用程序中。我能够使用 GCM 获得 Android 的通知,这非常简单。现在是 iOS,自周日以来,这对我来说是一个很大的痛苦,现在已经快 4 天了。我将分享我到目前为止所做的事情。请帮我让通知也能在 iOS 设备上运行。

根据插件,在应用程序方面,我的java 脚本 如下所示

myApp.controller('Register', function ($scope) {
    $scope.regGCM = function () {
        document.addEventListener('deviceready', onDeviceReady, false);
    }
    function onDeviceReady() {
        var push = PushNotification.init({
            "android": {
                "senderID": "41502493944",
                "sound": "true",
                "vibrate": "true",
            },
            "ios": {
                "alert": "true",
                "badge": "true",
                "sound": "true",
            },
            "windows": {}
        });
        push.on('registration', function (data) {
            var deviceid = data.registrationId;
            alert(deviceid);
        });
        push.on('notification', function (data) {
        console.log("notification");
        });
        push.on('error', function (e) {
            console.log("push error");
        });
    }
});

regGCM() 触发 iOS 设备请求允许为我的应用程序推送通知的权限时,它返回一个 token

然后为了在线测试推送通知,我使用了这个 site这需要我们的 token.pem 文件。
为了创建一个.pem 文件,我做了以下事情。

1) 从 here 创建了一个 p.notification 证书.
2) 在 mac keychain 中安装它。
3) 将已安装的证书导出为 pushcert.p12 文件。
4) 在终端中执行此命令 (openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts) 我得到了 pushcert.pem 文件。

即在线测试site说消息已发送,但我从未收到通知到我的 iOS 设备。我是推送通知的新手,不知道正确的步骤,可能遗漏了一些东西。有没有人知道 Cordova 中的 iOS p.notification。无论是使用 GCM 还是 native APN,我都不介意这样做的方式。
如有任何帮助,我们将不胜感激。

最佳答案

我检查了提到的网站:http://www.pushwatch.com/apns/ .它工作正常。

由于推送证书不正确,您没有收到推送通知。

如果您没有获得设备 token ,那么您可以假设证书没有正确创建。

问候...

-严厉的国王

关于ios - 需要指导在 Cordova 应用程序中使用 native APNs/GCM 为 iOS 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37698492/

相关文章:

android - CCPointFromString 正在崩溃 :( in cocos2dx 2. 0.4

ios - 检测动画 UIImageView 上的点击

android - 移动设备上出现 404 错误,但在 PC 浏览器上有效

javascript - 在 Phonegap 中打开 PDF (Android)

android - Java 客户端无法在 Android 上接收来自 Mosquitto 的消息

ios - 我忘记了 APNs 证书,现在怎么办? (推送通知不起作用)

iphone - 加载 UITableViewCell 时如何设置 UIActivityIndi​​catorView

ios - UITextfield 自定义位置因 iPhone 尺寸不同而上移

javascript - Phonegap 如何重用/包含 HTML 页面?

python - GmailAPI : "Error sending test message to Cloud PubSub projects/[project-id]/topics/[topic-id] : User not authorized to perform this action."?