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>
相关推荐
taokexia8 小时前
SwiftUI 组件开发: 自定义下拉刷新和加载更多(iOS 15 兼容)
ios·swift
2501_915918419 小时前
Fiddler抓包工具详解,HTTP/HTTPS抓包、代理设置与调试技巧一站式教程(含实战案例)
http·ios·小程序·https·fiddler·uni-app·webview
库奇噜啦呼11 小时前
【iOS】UICollectionView
macos·ios·cocoa
qixingchao12 小时前
iOS Swift 线程开发指南
ios·swift
AirDroid_cn12 小时前
在 iOS 18 离线徒步地图,如何存储和调用?
ios
2501_9159090612 小时前
iOS 发布 App 全流程指南,从签名打包到开心上架(Appuploader)跨平台免 Mac 上传实战
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915918411 天前
HTTP抓包工具推荐,Fiddler使用教程、代理设置与调试技巧详解(含HTTPS配置与实战案例)
http·ios·小程序·https·fiddler·uni-app·webview
mjhcsp1 天前
C++ 贪心算法(Greedy Algorithm)详解:从思想到实战
c++·ios·贪心算法