How to create multiple shortcuts at application start

366 Views Asked by At

So what I am trying is to donate multiple shortcuts (like 20 types of activites) at app delegate...it is weird that it works if I donate in a specific view controller, but if I make a for loop in a app delegate it doesnt work...here is the code:

activity = NSUserActivity(activityType: activityType)

        activity?.title = activityTitle

        if #available(iOS 12.0, *) {

            activity?.suggestedInvocationPhrase = suggestedPhrase

            activity?.isEligibleForPrediction = true

            activity?.persistentIdentifier = NSUserActivityPersistentIdentifier(activityType)

        }

        activity?.isEligibleForSearch = true



        //self.activities.append(activity!)

        if #available(iOS 12.0, *) {

            NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: [activityType], completionHandler: {[weak self] in

                self?.activity?.becomeCurrent()

            })

        }
1

There are 1 best solutions below

0
ralphneeleman On

Appdelegate is the first thing that's run on app load, this can cause it not to load your shortcuts, consider running them from the first viewcontroller the app opens