This repository has been archived by the owner on Nov 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
中文文档
smx edited this page Sep 27, 2017
·
4 revisions
1、App IDS 创建 App ID
2、App Groups 创建 共享组
3、App IDS 修改 项目app ID
Today widget ID
的 共享组
4、iOS Provisioning Profiles 最后一步创建 真机证书
1、 Schemes 配置项目target
可被其他app跳转的 Schemes
2、 App Groups 开启App的共享组
1、编写在 - (void)viewDidLoad
#ifdef __IPHONE_10_0 // 因为是iOS10才有的,还请记得适配
// 如果需要折叠
self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;
#endif
/// 如果需要折叠效果的,不要在 - (void)viewDidLoad 写高度。否则造成【折叠/展开】按钮样式bug
self.preferredContentSize = CGSizeMake(0, 110);
2、折叠、展开的 的处理方式
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
if(activeDisplayMode == NCWidgetDisplayModeCompact) {
// 110
self.preferredContentSize = CGSizeMake(0, 110);
}
else {
// 最高,根据设备机型(自行查看maxSize)
self.preferredContentSize = CGSizeMake(0, 400);
}
}
3、Today Wideget刷新界面时机
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
// 请求网络/获取<共享组> 数据
//不要在这里写高度。否则造成【折叠/展开】按钮样式bug
// completionHandler(NCUpdateResultNewData); // 刷新页面UI
// completionHandler(NCUpdateResultNoData); // 没有数据,不刷新
}
4、取消widget默认的inset,让应用靠左
- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets
{
return UIEdgeInsetsZero;
}