无法使用cordova-plugin-fcm插件向iOS生产添加推送通知权利 [英] Unable to add push notifications entitlement to iOS production with cordova-plugin-fcm plugin

查看:138
本文介绍了无法使用cordova-plugin-fcm插件向iOS生产添加推送通知权利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio 2017在空白的Cordova应用程序中安装cordova-plugin-fcm插件. 我安装插件并添加google-plist文件等. 在我的Mac上,我使用的是xcode 7.2.1.

I am trying to install cordova-plugin-fcm plugin in a blank Cordova app using Visual Studio 2017. I install the plugin and add the google-plist files etc. On my mac i have xcode 7.2.1.

当我从Visual Studio构建IPA时,它会生成IPA,但未启用推送通知. 我已将所有源代码(包括插件文件夹)添加到bitbucket.下方链接; https://bitbucket.org/quintonn/pushnotificationtest

When i build an ipa from visual studio it generates an IPA, but it does not have push notifications enabled. I have added all the source code, including plugins folders, to bitbucket. Link below; https://bitbucket.org/quintonn/pushnotificationtest

我缺少在iPhone上启用推送通知的功能吗? 仅供参考,我可以很容易地在android上使用它.

What am i missing to get push notifications enabled on my iphone? FYI, i can get it workig on android quite easily.

我不想打开xcode来启用推送通知.我知道可以直接从Visual Studio中使用钩子或xcconfig或config.xml.但是我只是无法正常工作,而且我已经花了大约三个星期的时间才无法正常工作.我只是在黑暗中感到沮丧,因为所有在线阅读材料都是针对不同版本的cordova,Visual Studio,xcode,phonegap或ionic或其他任何版本的.

I don't want to have to open xcode to enable push notifications. I know it's possible directly from Visual Studio using a hook or xcconfig or config.xml. But i just can't get it working and i've spent about 3 weeks now unable to get this working. And i'm just feeling in the dark as all the reading material online is for different versions of cordova, or visual studio, or xcode, or phonegap or ionic or whatever.

推荐答案

我已经花了很多很多时间来解决这个问题.

I've spent many, many, many.... hours on this problem.

我想出了一个cordova after_prepare 钩子,该钩子解决了我在XCode 7和8上的问题. 这是...

And i've come up with a cordova after_prepare hook that solves my problem on XCode 7 and 8. Here it is...

"use strict";

var fs = require('fs');
var path = require('path');
var xcode = require('xcode');

module.exports = function (context)
{
    var encoding = 'utf-8';
    var plist = fs.readFileSync(path.resolve(__dirname, "../GoogleService-Info.plist"), encoding);


    fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/GoogleService-Info.plist"), plist, encoding);

    var projectPath = path.resolve(__dirname, "../platforms/ios/APP NAME.xcodeproj/project.pbxproj");
    var pbxFile = fs.readFileSync(projectPath, encoding);

    var proj = new xcode.project(projectPath);

    proj = proj.parseSync();

    var pbxGroupKey = proj.findPBXGroupKey({
        name: "Resources"
    });
    proj.removeResourceFile('GoogleService-Info.plist', {}, pbxGroupKey);
    proj.addResourceFile('GoogleService-Info.plist', {}, pbxGroupKey);

    proj.addBuildProperty('"CODE_SIGN_IDENTITY[sdk=iphoneos*]"', '"iPhone Distribution"', 'Release');
    proj.addBuildProperty('DEVELOPMENT_TEAM', 'XXXXXXXX', 'Release');

    proj.addBuildProperty('PROVISIONING_PROFILE', "XXXXXXXX-XXXXXXXX-XXXX-XXXX-XXXXXXXX", 'Release');
    proj.addBuildProperty('PROVISIONING_PROFILE_SPECIFIER', '"NAME OF PROFILE"', 'Release');
    proj.addBuildProperty('TARGETED_DEVICE_FAMILY', '"1,2"', 'Release');

    proj.addTargetAttribute("DevelopmentTeam", "XXXXXXXX");
    var pushEntitlement = "{com.apple.Push ={enabled = 1;};}";
    proj.addTargetAttribute("SystemCapabilities", pushEntitlement);

    /*var attributes = proj.getFirstProject()['firstProject']['attributes'];
    if (attributes['TargetAttributes'] === undefined)
    {
        attributes['TargetAttributes'] = {};
    }
    var target = proj.getFirstTarget();
    if (attributes['TargetAttributes'][target.uuid] === undefined)
    {
        attributes['TargetAttributes'][target.uuid] = {};
    }
    attributes['TargetAttributes'][target.uuid]["SystemCapabilities"] = "{com.apple.Push ={enabled = 1;};}";
    */
    fs.writeFileSync(projectPath, proj.writeSync());

    fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/APP NAME/Resources/GoogleService-Info.plist"), plist, encoding);
    fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/APP NAME/Resources/Resources/GoogleService-Info.plist"), plist, encoding);
};

仅记得更新您的APP名称,预配配置文件名称和团队ID.

Just remember to update your APP Name, provisioning profile name and team id.

这篇关于无法使用cordova-plugin-fcm插件向iOS生产添加推送通知权利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆