官方参考链接

https://developer.apple.com/app-extensions/

https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214-CH20-SW1


PDF下载地址https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensibilityPG.pdf

iOS App Extensions-LMLPHP

一、APPExtensions中使用Host APP中的ClassExten

iOS App Extensions-LMLPHPsion

.如果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编译开关设置

  1. Click Build Settings

  2. Find (or search) Preprocessor Macros under Apple LLVM 6.0 - Preprocessing

  3. Add TARGET_IS_EXTENSION or any other name of your choice in both the debug and release sections.


    iOS App Extensions-LMLPHP

    iOS App Extensions-LMLPHP



iOS App Extensions-LMLPHP

代码地址:https://github.com/6357/YUAppExtensions

.

05-30 11:01