我希望在 3D Touch 快捷操作项中显示日期。如果用户没有打开应用程序,是否有任何方法可以刷新数据?
目前,快速操作仅会显示上次打开应用程序的日期,而不是当前日期。
是否有可能显示当前信息,或者这是一些不允许的后台进程?
AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let dateVariable = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
let dateString = dateFormatter.string(from: dateVariable)
let shortcut4 = UIMutableApplicationShortcutItem(type: "GetDate",
localizedTitle: dateString,
localizedSubtitle: "Get Today's Date in subtitle",
icon: UIApplicationShortcutIcon(type: .date),
userInfo: nil)
application.shortcutItems = [shortcut4]
return true
}
UIApplication.shared.shortcutItems
访问,但是你无法从小部件中获取。 - Maroš Beťko