Refresh 3D Touch Quick Action title

混江龙づ霸主 提交于 2019-12-22 09:39:25

问题


I want to show the date in a 3D Touch Quick Action item. Is there any way for the data to refresh if the user has not opened the app?

Right now, the quick action will only show the date of the last time the app was opened, rather than the current date.

Is it possible to show current info or is that some background process that is not allowed?

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
}

回答1:


You can update the shortcut items in Background. But without any proper reason you cannot enable the background mode for app. Apple will reject the app in review process.

Update:

I think updating a shortcut item in background is more difficult. From iOS 10 Apple showing the Today widget during the forceTouch (3D shortcut items). You can use Today widget for updating the latest information whenever user user do the forceTouch. I hope this will be useful



来源:https://stackoverflow.com/questions/40110746/refresh-3d-touch-quick-action-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!