在iOS 8中包含应用程序时如何启用应用程序扩展? [英] How to detect an app extension is enabled in containing app on iOS 8?

查看:192
本文介绍了在iOS 8中包含应用程序时如何启用应用程序扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS 8测试版上开发一个自定义键盘,我想告诉用户如果我的自定义键盘未启用,如何在包含app中启用它,有没有办法检测到应用程序扩展已启用?

I am developing a custom keyboard on iOS 8 beta, and I want to tell the user that how to enabled it in containing app if my custom keyboard is not enabled, is there any way to detect an app extension is enabled ?

推荐答案

1)首先让我们设置一些常量,以便彼此易于理解:

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


  • 包含app =安装扩展程序的应用程序并保留扩展名二进制文件和目标

  • 主机应用程序=扩展名为的应用程序在内部运行(对方)

  • extension =我们现在可以在系统范围内使用的任何iOS8新组件/模块:自定义键盘,今天的小部件,照片编辑效果等等。 。

2)Apple还发布了一个名为App Groups API的更安静的API
此API允许开发人员对n个扩展进行分组在1个捆绑标识符下,并在应用程序和其中包含的扩展名之间创建通信线路。

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)您可以使用NUserDefaults在扩展程序和包含应用程序之间共享数据,但使用这种新方法:

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>"];

读/写...和同步:

[myDefaultsObj synchronize];

4)现在到底线:

使用应用小组的网址方案来测试您的需求:

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 - 要打开的URL。

  • completionHandler - URL打开时调用的块。

  • 这个参数 - success - 是一个布尔值,表示open是否成功。

  • 祝你好运!!!

    这篇关于在iOS 8中包含应用程序时如何启用应用程序扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆