2017-10-09 140 views
0

我有一个包含四个目标的iOS项目,但似乎无法获取特定目标的版本号。获取特定目标的版本号

通过以下测试:

lane :beta do 
    puts get_version_number(scheme: 'myApp', target: 'myApp') 
    end 

我得到这样的输出:

[10:04:05]: -------------------------------- 
[10:04:05]: --- Step: get_version_number --- 
[10:04:05]: -------------------------------- 
[10:04:05]: Using deprecated option: '--scheme' (true) 
[10:04:05]: $ cd /Users/diego/myApp/ios && agvtool what-marketing-version -terse 
[10:04:05]: ▸ "myApp.xcodeproj/../myApp-tvOS/Info.plist"=1.0 
[10:04:05]: ▸ "myApp.xcodeproj/../myApp-tvOSTests/Info.plist"=1.0 
[10:04:05]: ▸ "myApp.xcodeproj/../myApp/Info.plist"=0.9 
[10:04:05]: ▸ "myApp.xcodeproj/../myApp Tests/Info.plist"=1.0 
[10:04:05]: 1.0 

返回的版本号是1.0,因为在那里我期待0.9 - 因为我指定的schemetarget对于此目标:"myApp.xcodeproj/../myApp/Info.plist"=0.9

编辑

我已经安装了这个plugin,它提供了对版本号和版本号的更精细控制。

+0

你明白了,因为搜索中断了 - 我得到了同样的东西(也许你正在使用像我这样的React Native)。查看'get_version_number'的代码,另一种解决方案是使用已弃用的'scheme'字段来或多或少地进行硬编码搜索。在你的情况下,'get_version_number(scheme:“myApp/Info”)'会起作用。 – zeh

回答

-1

以下是得到的版本号的方式:

目标C:

NSString * appVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 

斯威夫特< 3:

let appVersionString: String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String 

斯威夫特3:

let appVersionString: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String 

让我知道你是否需要别的东西。

+0

谢谢,@tendstoZero,但我在询问为什么它不能使用Fastlane(注意我在问题中添加了[fastlane]标签。 – dbarros