问题
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