iOS App Extensions

官方參考連接html

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

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


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

  1. Click Build Settingsorm

  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.




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

.

相關文章
相關標籤/搜索