INInteraction.delete not working in iOS13.7

210 views Asked by At

Using iOS13.7, Swift5.2.4, XCode11.7,

I try to delete an existing INInteraction in my iOS App.

The INShortcut is created as follows:

@available(iOS 12.0, *)
func createSiriButton(documentID: String, invitationCode: String) -> INUIAddVoiceShortcutButton {
    
    let siriShortcutButton = INUIAddVoiceShortcutButton(style: .whiteOutline)
    
    let activity = NSUserActivity(activityType: "MyIdentifierStringCodeABCDEF")
    
    activity.title = "Test"
    activity.suggestedInvocationPhrase = "Test"
    
    activity.isEligibleForSearch = true
    activity.isEligibleForPrediction = true
    activity.persistentIdentifier = NSUserActivityPersistentIdentifier("MyIdentifierStringCodeABCDEF")
    activity.becomeCurrent()
    
    siriShortcutButton.shortcut = INShortcut(userActivity: activity)
    
    return siriShortcutButton
}

Afterwards, having the ActivityPersistentIdentifier in hand, I try to delete the INInteraction.

I try with three different ways (see deletion methods below) - but none of them works.

What is still wrong - why is my Siri Shortcut INInteraction not deleted by the following code ?

let activity = NSUserActivity(activityType: "MyIdentifierStringCodeABCDEF")
let activityPersistentIdentifier = NSUserActivityPersistentIdentifier("MyIdentifierStringCodeABCDEF")
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: [activityPersistentIdentifier]) {
    print("one deleted")
}
INInteraction.deleteAll { (error) in
    print("all deleted")
}
INInteraction.delete(with: [activityPersistentIdentifier]) { (error) in
    print(error)
}
0

There are 0 answers