SwiftUI-小组件Widget

创建小组件

Xcode - add Taget - WidgetExtention

结构

小组件使用三方库

Podfile 中添加 target ‘widgetsExtension’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Uncomment the next line to define a global platform for your project
platform :ios, '14.1'

target 'DemoApp' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for widgetmaker

pod 'HandyJSON', '~> 5.0.2'
end

target 'widgetsExtension' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for widgetsExtension

pod 'HandyJSON', '~> 5.0.2'
end

和宿主数据共享

小组件类似于一个独立的App,数据通过 AppGroup 和宿主数据共享

添加AppGroup

选择项目根目录 - Target - Signing&Capability- AppGroup


欢迎和我一起交流学习

文章来自: http://hanks-zyh.github.io/