我有一个使用Ionic.io推送消息的Ionic项目。它由Fastlane构建,并通过HockeyApp部署。
由于升级到Xcode 8推送通知不再适用于iOS 10.
我有一个包含推送权利的权利文件,并使用ruby脚本添加到xcode项目文件中,请参阅https://github.com/fastlane/fastlane/issues/6544
当我用Fastlane构建项目时,推送仍然无效。当我在Xcode中打开项目文件并查看功能部分时,它会在“将推送通知权利添加到您的权利文件”中显示一个复选标记,但在“将推送通知功能添加到您的应用程序ID”中显示错误。
如果我按“修复”并重建,请按确实。
所以我的问题是:
我希望能够正确启用推送功能,只使用Fastlane,xcodebuild,ruby等等,只要它只在命令行中,并允许我的离子项目干净利落地构建。
答案 0 :(得分:4)
所以我设法通过做两件事来实现它:
感谢https://github.com/Azenet和https://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
答案 1 :(得分:0)
对于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.plist
和Entitlements-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>