官方参考链接
https://developer.apple.com/app-extensions/
一、APPExtensions中使用Host APP中的ClassExten
sion
.如果API声明包含NS_EXTENSION_UNAVAILABLE宏,则此API在扩展中将不可用
+ (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的判断
+(BOOL) isAppExtension
{
return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"];
}
.Extenstion编译开关设置
Click
Build Settings
Find (or search)
Preprocessor Macros
underApple 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
.
来源:oschina
链接:https://my.oschina.net/u/868062/blog/406549