1. Share Extension

1.1. Info.plist

1.1.1. NSExtensionActivationRule

分享支持的格式,有对应的 key 表示支持,没有或者值为 false 表示不支持

  • NSExtensionActivationSupportsAttachmentsWithMaxCount
  • NSExtensionActivationSupportsAttachmentsWithMinCount
  • NSExtensionActivationSupportsFileWithMaxCount
  • NSExtensionActivationSupportsImageWithMaxCount
  • NSExtensionActivationSupportsMovieWithMaxCount
  • NSExtensionActivationSupportsText
  • NSExtensionActivationSupportsWebURLWithMaxCount
  • NSExtensionActivationSupportsWebPageWithMaxCount

1.2. SLComposeServiceViewController

分享界面,如果要完全自定义界面,可以换成 UIViewController

1.3. 打开 Host App

参考 openURL:completionHandler: NSExtensionContextopenURL:completionHandler: 只支持 Today widget

所以采用下面的方式:

- (void)openHostApp {
    UIResponder *responder = self;
    SEL selector = NSSelectorFromString(@"openURL:");
    while (responder) {
        if ([responder respondsToSelector:selector]) {
            [responder performSelector:selector withObject:[NSURL URLWithString:@"example://"]];
            break;
        } else {
            responder = responder.nextResponder;
        }
    }
    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
}

1.4. References

results matching ""

    No results matching ""