iOS8-程序扩展遇到的问题
XCode6添加扩展找不到Application Extension?
要在已有的工程上才可以添加Application Extension。不能直接新建工程的时候就添加Application Extension。
添加方法:File/new/Target
from: StackOverFlow
extension 去掉左边的空白
extension 左边的空白A Today widget created using the Xcode Today template includes Auto Layout constraints for standard margin insets. To get the inset values for your calculations, implement the widgetMarginInsetsForProposedMarginInsets: method.
from: stackoverflow
-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{
return UIEdgeInsetsZero;
}
更新extension 内容
[[NCWidgetController widgetController] setHasContent:YES forWidgetWithBundleIdentifier:@"The bundle identifier of the extension."];
Both a widget and its containing app can use this method to specify whether the widget has content to display. The value of flag determines whether a widget should be visible in the Today view and whether the widget’s most recent snapshot is still valid.
打开 Containing APP
通过自定义 URL scheme
来打开Containing APP。
[self.extensionContext openURL:[NSURL URLWithString:@"你自定义的 URL scheme"] completionHandler:^(BOOL success) {
}];
extension 里面不能用 UIApplicaion
的API来打开URL
不能在 App Extensions 里面用的API
因为APP Extension是专注于某一项功能,所以它是没有资格参与某些活动,app extenstion 不能:
- Access a sharedApplication object, and so cannot use any of the methods on that object
- Use any API marked in header files with the NS_EXTENSION_UNAVAILABLE macro, or similar - - unavailability macro, or any API in an unavailable framework
For example, in iOS 8.0, the HealthKit framework and EventKit UI framework are unavailable to app extensions.- Access the camera or microphone on an iOS device
- Perform long-running background tasks
- The specifics of this limitation vary by platform, as described in the extension point chapters in this document.
(An app extension can initiate uploads or downloads using an NSURLSession object, with results of those operations reported to the containing app.)- Receive data using AirDrop
(An app extension can send data using AirDrop in the same way an app does: by employing the UIActivityViewController class.)
extension 链接的Framework里面也不能有上述的API,不然会被AppStore拒绝的。
Tips
extension 不支持键盘输入
用户只能查看,点击按钮,不能输入(像回复信息什么的不行,extension 的目的是展示最新的信息)
extension 必须支持arm64
包含app extension 的APP必须支持arm64 (iOS) or x86_64 architecture (OS X),否则会被AppStore拒绝
extension 支持
NSURLSession
后台任务
extension 可以在后台建立上传下载任务,但是不能在后台播放音乐,拨打VoIP等。如果在你的extension的Info.plist 添加了UIBackgroudModes,你的应用将会被AppStore拒绝。
extension的
targeted device
必须是 “iPhone/iPad” (sometimes called universal)
为了通过审核,你必须为你的extension的targeted device
指定为 “iPhone/iPad” (sometimes called universal) ,不管你的containing app的targeted device
是什么。
确保你的extension 的 targeted device
是“iPhone/iPad”的步骤
- In the Xcode project navigator for your keyboard project, select the project file.
If the project & targets list in the project editor is hidden, show it. To do this, click the button at the left of the project editor tab bar. - In the targets group in the project & targets list, select the target for your app extension.
- Choose the Build Settings tab in the project editor.
Ensure that the Basic and Combined buttons are selected, to make it easier for you to locate the settings you need here. - In the Deployment group in the project editor, view the Targeted Device Family setting. For both the Debug and Release configuration, the value should be “iPhone/iPad.”
If you find different values, correct them to be “iPhone/iPad.”