【问题标题】:Ionic/cordova: how to add push capability with fastlane or xcodebuild?Ionic/cordova:如何使用 fastlane 或 xcodebuild 添加推送功能?
【发布时间】:2016-11-18 09:10:30
【问题描述】:

我有一个使用 Ionic.io 推送消息的 Ionic 项目。它使用 Fastlane 构建并通过 HockeyApp 部署。

由于升级到 Xcode 8 推送通知不再适用于 iOS 10。

我有一个包含推送权利的权利文件,它使用 ruby​​ 脚本添加到 xcode 项目文件中,请参阅https://github.com/fastlane/fastlane/issues/6544

当我使用 Fastlane 构建项目时,推送仍然无法正常工作。当我在 Xcode 中打开项目文件并查看功能部分时,它在“将推送通知权利添加到您的权利文件”中显示一个复选标记,但在“将推送通知功能添加到您的应用程序 ID”中显示错误。

如果我按“修复”并重建,按 确实有效

所以我的问题是:

我希望能够正确启用推送功能,仅使用 Fastlane、xcodebuild、ruby 或其他任何东西,只要它只在命令行中并允许我的 ionic 项目干净地构建。

【问题讨论】:

    标签: ionic-framework xcode8 ios10 xcodebuild fastlane


    【解决方案1】:

    所以我通过做两件事设法让它工作:

    • 我从 xcode 中删除了所有旧的配置文件。这扭转了问题,所以 Xcode 抱怨推送权利没有添加到我的权利文件中,但是在“将推送通知功能添加到您的应用程序 ID”中有一个复选标记。
    • 接下来我更改了脚本以将项目文件包含在项目本身中。 https://github.com/Azenet 告诉我,这可能与不使用 Fastlane 的匹配有关。

    感谢 https://github.com/Azenethttps://github.com/hjanuschka 让我完成了 90% 的工作。

    #!/usr/bin/env ruby
    require 'xcodeproj'
    
    name = ARGV[0]
    projectpath = "../platforms/ios/" + name + ".xcodeproj"
    puts "Adding entitlement push to " + name
    puts "Opening " + projectpath
    proj = Xcodeproj::Project.open(projectpath)
    entitlement_path = name + "/" + name + ".entitlements"
    
    group_name= proj.root_object.main_group.name
    
    file = proj.new_file(entitlement_path)
    
    attributes = {}
    proj.targets.each do |target|
        attributes[target.uuid] = {"SystemCapabilities" => {"com.apple.Push" => {"enabled" => 1}}}
        target.add_file_references([file])
        puts "Added to target: " + target.uuid
    end
    proj.root_object.attributes['TargetAttributes'] = attributes
    
    proj.build_configurations.each do |config|
        config.build_settings.store("CODE_SIGN_ENTITLEMENTS", entitlement_path)
    end
    puts "Added entitlements file path: " + entitlement_path
    
    proj.save
    

    【讨论】:

    • 如果.entitlements 仍然没有在targets下设置,添加`target.build_configurations.each do |config| config.build_settings.store("CODE_SIGN_ENTITLEMENTS", entitlement_path) end` 在目标迭代器中。
    【解决方案2】:

    对于 Xcode 10.1 和 Cordova 4.5.5,我必须像这样重写脚本:

    def enable_push_notifications()
      fastlane_require 'xcodeproj'
      fastlane_require 'fileutils'
    
      app_name = get_app_name
    
      puts "Adding Push entitlement to #{app_name}"
    
      proj = Xcodeproj::Project.open(File.expand_path("../platforms/ios/#{app_name}.xcodeproj"))
    
      attributes = {}
      proj.targets.each do |target|
        attributes[target.uuid] = {"SystemCapabilities": {"com.apple.Push": {"enabled": 1}}}
        puts "Added to target: " + target.uuid
      end
      proj.root_object.attributes['TargetAttributes'] = attributes
    
      FileUtils.cp_r(
        File.expand_path("./overrides/Entitlements-Debug.plist"),
        File.expand_path("../platforms/ios/#{app_name}/Entitlements-Debug.plist"),
        remove_destination: true
      )
      FileUtils.cp_r(
        File.expand_path("./overrides/Entitlements-Release.plist"),
        File.expand_path("../platforms/ios/#{app_name}/Entitlements-Release.plist"),
        remove_destination: true
      )
    
      proj.save
    
      puts "[OK] Added Push entitlement"
    end
    

    这里我没有创建 .entitlements 文件,而是覆盖了其他两个具有相同内容的文件(Entitlements-Release.plistEntitlements-Debug.plist):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>aps-environment</key>
        <string>development</string>
    </dict>
    </plist>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      相关资源
      最近更新 更多