iOS 不同target之間的代碼共享
1, hostapp的源代碼,創(chuàng)建靜態(tài)庫(kù), 或者framework的target,編譯庫(kù)后,拖入到extension target中
2, hostapp的源代碼, 添加compile source files中。
3,注意事項(xiàng):
擴(kuò)展app下列方法被禁止調(diào)用,
UIApplication sharedApplication方法
build settings編譯器選項(xiàng)不同target需要注意設(shè)置prefix-header,preprocessor macros
iOS extension擴(kuò)展和宿主app之間的數(shù)據(jù)共享
宿主:
userdefults目錄
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Data/Application/4A7E7EEB-63E9-412C-A161-09ACE2871DCC/Library/Preferences/com.lanqxyihhenguisleu.1.plist
bundle目錄
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Bundle/Application/27A672B2-DF17-41D4-9939-0DBB4DE176F1/GitWorkFlowTest.app/PlugIns/MyActionExtension.appex
doc目錄
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Data/PluginKitPlugin/9D7D2E19-20B3-4612-9D7E-D746959B346A
擴(kuò)展:
userdefults目錄
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Data/PluginKitPlugin/FF3BF7B6-57C8-479C-A390-916567D9C797/Library/Preferences/com.lanqxyihhenguisleu.1.MyActionExtension.plist
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Bundle/Application/4035127B-AD0C-4F8F-A790-4591A0C4A198/GitWorkFlowTest.app
/Users/ff/Library/Developer/CoreSimulator/Devices/CDE3ED20-8AC7-426E-935E-F3226A26302A/data/Containers/Data/Application/92DA7147-377D-44D0-BDAE-1788C9ACEB2A
1,都有自己的沙盒目錄
/var/mobile/Containers/Data/PluginKitPlugin/780B11AA-B897-46E8-B85A-8CD19A169B28/Library/Caches
/var/mobile/Containers/Data/PluginKitPlugin/B608EAB9-E257-4BA2-9094-55DA5209758E/Library/Caches
2,bundle目錄,宿主app的bundle子目錄下PlugIns目錄中
/private/var/containers/Bundle/Application/0D6DF0DC-6F4C-46D1-BE1F-D3EC11755F52/GitWorkFlowTest.app/PlugIns/MyNotficationServiceExt.appex
/private/var/containers/Bundle/Application/9992E4CA-AB6A-4D5D-B28E-F36BE2808F02/GitWorkFlowTest.app/PlugIns/MyTodayExtension.appex
3,多任務(wù)環(huán)境
TodayExtension工作在主線程,queue: com.apple.main-thread(serial)
UNNotificationServiceExtension工作在queue:com.apple.NSXPCC.ection.user.endpoint(serial)
UNNotificationContentExtension工作在queue:com.apple.main-thread(serail)