ios 配置快捷指令

js 复制代码
struct OpenIntent: AppIntent {
    @available(iOS 16, *)
    static var title = LocalizedStringResource("这里填写标题")
    @available(iOS 16.0, *)
    static var description = IntentDescription("这里填写描述")
    
    // 意图执行时,是否自动将应用拉起到前台
    static var openAppWhenRun: Bool = true
    
    @available(iOS 16.0, *)
    func perform() async throws -> some IntentResult {
        //这样写会有一个dialog提示
//        return .result(dialog: "play")
  //这样写没有弹窗
        return .result()
    }
}

struct MeditationShortcuts: AppShortcutsProvider {
  
    @available(iOS 16.0, *)
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: OpenIntent(),
            phrases: [
                "\(.applicationName) aaa",//这里必须有\(.applicationName) 否则在快捷指令里面搜索不到
            ],
            //shortTitle 跟 systemImageName 最好一起写
            shortTitle: "charge",
            systemImageName: "battery.100percent.bolt" 
        );
        
    }
}

设置systemImageName 的颜色以及在快捷指令中显示的背景色

info.plist 中添加

CustomTintColor BackgroundGradientColor1 BackgroundGradientColor2 都是设置的颜色资源的名字

xml 复制代码
<dict>
     <key>CFBundlePrimaryIcon</key>
     <dict>
         <key>NSAppIconActionTintColorName</key>
         <string>CustomTintColor</string>
         <key>NSAppIconComplementingColorNames</key>
         <array>
             <string>BackgroundGradientColor1</string>
             <string>BackgroundGradientColor2</string>
         </array>
    </dict>
</dict>
相关推荐
從南走到北14 小时前
JAVA海外短剧国际版源码支持H5+Android+IOS
android·java·ios
疯笔码良15 小时前
iOS 国际化与本地化完整指南
ios·swift
库奇噜啦呼16 小时前
【iOS】GCD学习
学习·ios·cocoa
Kathleen10017 小时前
iOS--TableView的复用机制以及性能优化(处理网络数据)
ios·性能优化·网络请求·gcd·uitableview
子春一1 天前
Flutter 与原生平台深度集成:打通 iOS 与 Android 的最后一公里
android·flutter·ios
依旧风轻1 天前
objc_object 与 objc_class 是一定要了解的底层结构
ios·objective-c·isa·objc_class·objc_object
m0_495562781 天前
Coreblutooth蓝牙
ios