How to detect an app extension is enabled in containing app on iOS 8?

寵の児 提交于 2019-12-04 05:08:49
nurxyz

1) first of all let's set some constants to make it easy to understand each other:

  • containing app = the app that installs the extension and holds the extension binary and target
  • host app = the app that the extension is running inside (other party)
  • extension = any of iOS8's new components/modules that we can now build into system-wide use: custom keyboards, today widgets, photo editing effects, and more..

2) Apple also released a more quiet API called App Groups API This API allows a developer to group n extensions under 1 bundle identifier, and creates a communication wire between the app and the extensions contained in it.

3) you can share data between the extensions and the containing app using NUserDefaults, but with this new method:

[[NSUserDefaults alloc] initWithSuiteName:@"<app group identifier>"];

read/write... and sync:

[myDefaultsObj synchronize];

4) and now to the bottom line:

use the app group's url schemes to test what you want:

https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSExtensionContext_Class/#//apple_ref/occ/instm/NSExtensionContext/openURL:completionHandler:

- (void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL success))completionHandler
  • URL - The URL to open.
  • completionHandler - A block that is called when the URL has opened.
  • this parameter - success - is a Boolean value that indicates whether the open was successful.

Good luck!!!

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