Cordova / iOS8推送通知

时间:2015-01-05 00:46:44

标签: ios angularjs cordova ionic-framework

我正在尝试将推送通知添加到我的Ionic / Cordova iOS8应用程序中。我已经在Android中使用它了,但我在使用iOS时遇到了一些困难(如图)。我做的第一件事就是安装插件(https://github.com/phonegap-build/PushPlugin)。然后我手动将PushNotification.js文件复制到platforms / ios / www / plugins / www文件夹中。然后我创建了一个单独的控制器来查看该插件是否可行。 XCode控制台中没有日志记录(我确实安装了控制台日志插件并正常工作)。

.controller('PushCtrl', ['$scope', '$location', '$cordovaPush', 'AuthService', 'UserFactory', function($scope, $location, $cordovaPush, AuthService, UserFactory) {
    if (typeof $cordovaPush !== 'undefined' && typeof device !== 'undefined') {
        console.log(device.platform);
        if (device.platform == 'android' || device.platform == 'Android') {
            var config = {
                senderID: GCMsenderID
            };
        } else {
            var config = {
                "badge": "true",
                "sound": "true",
                "alert": "true"
            }
        }
        $cordovaPush.register(config).then(function(result) {
            console.log("Push Notification Result: " + result);
            UserFactory.gcm('register', result.deviceToken);
        }, function(err) {
            console.log('Unable to device token from Google Cloud Messaging');
        });
    } else {
        console.log('Device is undefined?');
    }
}])

UserFactory中的gcm方法所做的就是将值发布到服务器。我确保插件安装正确,我按照Apple的教程准确地创建了SSL证书。我处于停滞状态,不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

在cordova push plugin 2.4下,设备令牌存储在结果中,而不是存储在iOS的result.devicetoken中。

尝试更改为此并查看其是否有效:

UserFactory.gcm('register', result);