简体   繁体   中英

Refresh 3D Touch Quick Action title

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
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM