2016-10-07 4 views
2

Kann SiriKit die INSendPaymentIntent an meine App übergeben? Die Absicht muss von meiner App gehandhabt werden, anstatt in der Siri-Erweiterung. Aber die INSendPaymentIntentResponse hat nicht die. continueInApp wie INStartAudioCallIntentResponseCode. Es gibt .failureRequiringAppLaunch, aber dieses Verhalten ist nicht das bevorzugte. Hast du eine Idee? Wie gebe ich ein Objekt an meine App weiter?Wie übermittele ich meine App mit SiriKit?

Antwort

0

In der IntentHandler-Erweiterung gibt es eine Handle-Methode, die funktioniert, wenn der Benutzer auf die Schaltfläche "Senden" in Siri UI Extension klickt. (Swift 3, IOS 10 und 11)

class IntentHandler: INExtension, INSendPaymentIntentHandling { 

    func handle(intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) { 
     if let _ = intent.payee, let currencyAmount = intent.currencyAmount { 
      // Handle the payment here! 

      // Create a user activity to pass it to our application 
      let userActivity = NSUserActivity(activityType:"myActivityName") 

      // Pass parameter dictionary to the userinfo 
      userActivity.userInfo = ["amount": Int(truncating: currencyAmount.amount!)] 

      // By providing a userActivity to the intent response, Siri will open up the app and continue the payment there 
      completion(INSendPaymentIntentResponse.init(code: .inProgress, userActivity: userActivity)) 
     } 
    } 
} 

Danach continueUserActivity in unserer Anwendung aufgerufen wird

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler 
{ 
    // Parse userActivity.userInfo parameter to get the amount etc. 

    return YES; 
}