PhoneGap推送插件未在ioS

时间:2016-05-04 10:18:45

标签: ios cordova phonegap-pushplugin

我在phonegap应用程序中使用以下插件https://github.com/phonegap/phonegap-plugin-push。我没有在注册活动的ioS版本上获得任何东西。在Android上它100%工作。我请求协助,看看我是否遗漏了任何东西。代码如下。我有证书并启用了推送服务。我创建了一个分发证书,该应用程序在苹果商店。基本上在启动时我有一个自我调用函数并通过http发送注册到我们的服务器,我们没有从ioS获得任何东西。我们使用phonegapbuild构建ioS版本并通过macincloud.com上传。我在这里读了几篇文章,但没有一篇能解决我的问题。

<gap:plugin name="phonegap-plugin-push" source="npm" >
   <param name="SENDER_ID" value="15971xxxxxxx" />
</gap:plugin>

我的环境是 Windows 10 Cordova -v 6.0.0 phonegap -v 5.5.0 push plugin -v 1.5.3

这是代码

(function() {
'use strict';
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    var samplePushApp = angular.module('samplePushApp');
    samplePushApp.factory('deviceService', deviceService);

    deviceService.$inject = ['$http', '$q',  '$cordovaDevice', 'messagesSqlLiteService'];

    function deviceService($http, $q,  $cordovaDevice, messagesSqlLiteService) {
            var url = 'http://example.com/api/device/';
            console.log("PushNotification Registration");
            var push = PushNotification.init({ 
                "android": {"senderID": "15971xxxxxxx"},
                "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
                "windows": {} } );

            push.on('registration', function(data) {
                console.log(data.registrationId);
                console.log("data.registrationId");
                var model = $cordovaDevice.getModel();
                var platform = $cordovaDevice.getPlatform();
                var uuID =  $cordovaDevice.getUUID();
                var version = $cordovaDevice.getVersion();
                var data = { "model": model, "platform": platform, "registrationId": data.registrationId, "DeviceId": uuID , "version ": version  };
                console.log(JSON.stringify(data));
                $http.post(
                    url,
                    JSON.stringify(data),
                    {
                        headers: {
                            'Content-Type': 'application/json',
                            'Accept': 'application/json'
                        }
                    }
                ).success(function() {
                    console.log("Device Info submitted");
                }).error(function(data, status) {
                    console.error('Device Info error', status, data);
                });
            });

            push.on('notification', function(data) {
                navigator.notification.alert(data.title+" Message: " + data.message, function(){}, "", "");
                messagesSqlLiteService.insert(data);
                location.href = '#messages';
            });

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

    // create an injector
    var $injector = angular.injector(['samplePushApp']);
    $injector.invoke(deviceService);


}
})();

解决

作为更新。事实证明,代码没有任何问题。有两个主要问题。

我最终借用了一台mac(来自macincloud)并使用

构建了该项目
phonegap build ios

第一个问题:我收到了这个错误

Build Error
===========
ld: '/Users/user000516/Downloads/my-app - ioS/platforms/ios/samplePush/Plugins/phonegap-plugin-push/GCM/Libraries/libGGLCloudMessaging.a(GGLContext+CloudMessaging.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这意味着推送插件无法在启用bitcode的情况下进行编译。我在xCode中禁用了bitcode,并且项目已成功构建。我不确定这是否是Phonegap Build的构建失败的原因。

第二个问题:我从XCode做的另一件事是获得Capabilities选项卡并启用Push Notification功能。

在这些更改之后,代码按预期工作。

希望这有助于某人

1 个答案:

答案 0 :(得分:0)

如果我应该编辑我的问题,或者提供解决方案,则不确定。

解决

作为更新。事实证明,代码没有任何问题。有两个主要问题。

我最终借用了一台mac(来自macincloud)并使用

构建了该项目
phonegap build ios

第一个问题:我收到了这个错误

构建错误

ld: '/Users/user000516/Downloads/my-app -          ioS/platforms/ios/samplePush/Plugins/phonegap-plugin-push/GCM/Libraries/libGGLCloudMessaging.a(GGLContext+CloudMessaging.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode   for this target. for architecture arm64

clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

这意味着推送插件无法在启用bitcode的情况下进行编译。我在xCode中禁用了bitcode,并且项目已成功构建。我不确定这是否是Phonegap Build的构建失败的原因。

第二个问题:我从XCode做的另一件事是获得Capabilities选项卡并启用Push Notification功能。

在这些更改之后,代码按预期工作。

希望这有助于某人

相关问题