官方参考连接html
https://developer.apple.com/app-extensions/
ios
PDF下载地址https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensibilityPG.pdfgithub
1、APPExtensions中使用Host APP中的ClassExtenapp
sionui
.若是API声明包含NS_EXTENSION_UNAVAILABLE宏,则此API在扩展中将不可用spa
+ (UIApplication *)sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead."); UIApplication的处理 { if (![[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"]) { Method sharedApplicationMethod = class_getClassMethod([UIApplication class], @selector(sharedApplication)); if (sharedApplicationMethod != NULL) { IMP sharedApplicationMethodImplementation = method_getImplementation(sharedApplicationMethod); Method rsk_sharedApplicationMethod = class_getClassMethod([UIApplication class], @selector(yu_sharedApplication)); method_setImplementation(rsk_sharedApplicationMethod, sharedApplicationMethodImplementation); } } }
.app Extenstion的判断
debug
+(BOOL) isAppExtension { return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"]; }
.Extenstion编译开关设置code
Click Build Settings
orm
Find (or search) Preprocessor Macros
under Apple LLVM 6.0 - Preprocessing
Add TARGET_IS_EXTENSION
or any other name of your choice in both the debug and release sections.
代码地址:https://github.com/6357/YUAppExtensions
.