iOS App Extensions

纵然是瞬间 提交于 2020-03-21 15:00:06

3 月,跳不动了?>>>

官方参考链接

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

一、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编译开关设置

  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.




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

.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!