iOS App Extensions

官方参考链接

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

205951_9m1u_868062.png

一、APPExtensions中使用Host APP中的ClassExten

213915_i5IA_868062.pngsion

.如果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.


    210934_Ahsb_868062.png

    210934_NPCu_868062.png



220909_exXU_868062.png

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

.

转载于:https://my.oschina.net/u/868062/blog/406549

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值