简体   繁体   English

如何检测在 iOS 8 上的包含应用程序中启用了应用程序扩展?

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

我正在 iOS 8 beta 上开发自定义键盘,我想告诉用户如果我的自定义键盘未启用,如何在包含应用程序中启用它,有什么方法可以检测应用程序扩展是否已启用?

  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..扩展 = 我们现在可以构建到系统范围内使用的任何 iOS8 新组件/模块:自定义键盘、今天的小部件、照片编辑效果等等..
  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. Apple 还发布了一个更安静的 API,称为 App Groups API。这个 API 允许开发人员将 n 个扩展分组在 1 个捆绑标识符下,并在应用程序和其中包含的扩展程序之间创建通信线路。

  3. you can share data between the extensions and the containing app using NUserDefaults, but with this new method:您可以使用 NUserDefaults 在扩展程序和包含的应用程序之间共享数据,但使用这种新方法:

     [[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:使用应用组的 url 方案来测试你想要的:

    https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSExtensionContext_Class/#//apple_ref/occ/instm/NSExtensionContext/openURL:completionHandler : 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. URL - 要打开的 URL。
    • completionHandler - A block that is called when the URL has opened. completionHandler - 在 URL 打开时调用的块。
    • this parameter - success - is a Boolean value that indicates whether the open was successful.此参数 - 成功 - 是一个布尔值,指示打开是否成功。

Good luck!!!祝你好运!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 7:检测是否启用了App自动更新? - iOS 7: detect if App autoupdating is enabled? 如何在iOS App包含扩展和扩展(不是主机应用程序)之间进行通信 - How to communicate between iOS App Containing Extension and Extension (not Host App) 如何检测 iOS App Extension 中的内存警告 - How to detect memory warnings in iOS App Extension 如何检测是否在iOS应用中启用了堆栈粉碎保护 - How to detect if stack smashing protection is enabled in an iOS app 如何检测我的iOS应用程序已启用PIE / ASLR? - How to detect that PIE/ASLR has been enabled for my iOS app? iOS:如何仅在不包含应用程序的扩展程序中运行框架代码 - iOS:How to run framework code only in extension not containing app iOS 操作扩展无法打开包含应用程序 - iOS action extension cannot open containing app 通过WatchKit扩展检测iOS应用是否在前台 - Detect if iOS app is in foreground from WatchKit extension 将文件从iOS应用扩展程序保存到包含的应用 - Saving files from an iOS app extension to the containing app 如何使用应用程序扩展中的 IPC 将信息异步发送到 iOS 上的包含应用程序? - How can I use IPC from an app extension to asynchronously send information to the containing app on iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM