如何以编程方式从 React Native 生成的 xcodeproj 中删除“推送通知”?

问题描述 投票:0回答:1

我是 ReactNative 和 Swift 的新手。我有一个生成的 XCode 项目,它在“签名和功能”选项卡中显示“推送通知”。

我可以单击鞭打图标,但是我想以编程方式删除“推送通知”功能(或者更好的是调整 xcodeproject 的生成方式,以便一开始就不会添加“推送通知”)。

我开始查看

xcodeproj
Ruby Gem(并修改了
xcodeproj
命令(例如使用
show
config-dump
),希望能轻松找到并调整此设置。

到目前为止,我的尝试包括加载项目和访问构建设置(直接使用 ruby 解释器):

require 'xcodeproj'

project_path = './ios/my_test_proj.xcodeproj'


project = Xcodeproj::Project.open(project_path)

target = project.targets.first

target.build_settings("Release")

它只列出了这些选项:

{
    "ASSETCATALOG_COMPILER_APPICON_NAME"=>"AppIcon", 
    "CLANG_ENABLE_MODULES"=>"YES", 
    "CODE_SIGN_ENTITLEMENTS"=>"my_test_proj/my_test_proj.entitlements", 
    "CURRENT_PROJECT_VERSION"=>"1", 
    "INFOPLIST_FILE"=>"my_test_proj/Info.plist", 
    "IPHONEOS_DEPLOYMENT_TARGET"=>"13.4", 
    "LD_RUNPATH_SEARCH_PATHS"=>"$(inherited) @executable_path/Frameworks", 
    "MARKETING_VERSION"=>"1.0", 
    "OTHER_LDFLAGS"=>["$(inherited)", "-ObjC", "-lc++"], 
    "OTHER_SWIFT_FLAGS"=>"$(inherited) -D EXPO_CONFIGURATION_RELEASE", 
    "PRODUCT_BUNDLE_IDENTIFIER"=>"com.anonymous.my_test_proj", 
    "PRODUCT_NAME"=>"my_test_proj", 
    "SWIFT_OBJC_BRIDGING_HEADER"=>"my_test_proj/my_test_proj-Bridging-Header.h", 
    "SWIFT_VERSION"=>"5.0", 
    "TARGETED_DEVICE_FAMILY"=>"1,2", 
    "VERSIONING_SYSTEM"=>"apple-generic"
}

我在上面的输出中找不到任何与推送通知相关的内容,在 xcodeproj Ruby Gem 文档中也找不到任何内容。

是否可以以编程方式从 XCode 项目中删除“推送通知”(或创建一个没有“推送通知”的项目)?如果是这样怎么办?

(我在 OSX 14.1 上使用 XCode 15.2)

ios xcode build
1个回答
0
投票

目前的解决方法是从项目的 .entitlements 文件中删除

aps-environment
键。 (
sudo gem install plist
是先决条件):


require 'xcodeproj'
require 'plist'

project_path = './ios/my_test_proj.xcodeproj'


project = Xcodeproj::Project.open(project_path)

target = project.targets.first
# you might need to prefix this path, depending on how your .xcodeproj is setup
entitlements_path = './ios/' + target.build_settings("Release")["CODE_SIGN_ENTITLEMENTS"]
# parse plist
entitlements = Plist.parse_xml(entitlements_path)
# search and delete "aps-environment" key
if entitlements.key?("aps-environment")
    entitlements.delete("aps-environment")
end
# save plist (ideally this would run before opening the xcodeproj to avoid editing this while Xcode is open)
Plist::Emit.save_plist(entitlements, entitlements_path)
© www.soinside.com 2019 - 2024. All rights reserved.