iOS mulitple targets

How:

step1:

先 duplicate 已存在的target,

之後會發現多出了對應的info.plist檔

step2:

target 和 info.plist檔 改名,

左上target選擇的地方,長按,選擇Manage schemes

這一步驟主要是要確認project 和改target顯示的名稱

step3:

接下來,點選target,之後點選choose info.plist file
選擇對應的info.plist file檔案,

之後設定他所屬的BundleID和displayname,還有app icon

step4:

在 Swift 專案中,編譯器不再支援 preprocessor 的指令。
所以如果查到下面資料要改 preprocessor,就是舊的了。
新的改法是:
點選target之後,選擇Build Settings,
往下尋找Swift Compiler - Custom Flags
之後 Other Swift Flags 點兩下之後,
在最後面輸入-D XXX (這邊的xxx就是key來讓你後面繼續下面步驟))
(-D )就是必須要的設置

Use:

之後再需要的地方,用下面的方式判斷是從哪個target就好

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

#if KKK
print("KKK!!!YAYAYAY")
versionControl = "KKK"
#elseif XXX
print("Sencod Brand!")
versionControl = "XXX"
#elseif ABC
print("ABC Brand!")
versionControl = "ABC"
#endif

return true
}

Title:iOS mulitple targets

Author:Dean Kai Chang

Post Time:2018/07/31 - 10:07

Last update:2018/08/01 - 11:08

Original Link:https://deankai.github.io/2018/07/31/iOS-MultipleTargets/

許可協議: 署名-非商業性使用-禁止演譯 4.0 國際 轉載請保留原文連結和作者。