From 8655407ab6987bb7268fab55b6380051f26668fe Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 24 十一月 2021 10:17:15 +0800 Subject: [PATCH] 备份 --- SiriIntents/IntentHandler.cs | 171 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 86 insertions(+), 85 deletions(-) diff --git a/SiriIntents/IntentHandler.cs b/SiriIntents/IntentHandler.cs index 9270fdf..8837700 100644 --- a/SiriIntents/IntentHandler.cs +++ b/SiriIntents/IntentHandler.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Foundation; +using HDLSceneSiri; using Intents; namespace SiriIntents @@ -15,7 +16,7 @@ // "<myApp> John saying hello" // "Search for messages in <myApp>" [Register("IntentHandler")] - public class IntentHandler : INExtension//, IINSendMessageIntentHandling, IINSearchForMessagesIntentHandling, IINSetMessageAttributeIntentHandling + public class IntentHandler : INExtension, IINSendMessageIntentHandling, IINSearchForMessagesIntentHandling, IINSetMessageAttributeIntentHandling { protected IntentHandler(IntPtr handle) : base(handle) { @@ -27,107 +28,107 @@ // This is the default implementation. If you want different objects to handle different intents, // you can override this and return the handler you want for that particular intent. - if(intent is HDLSceneSiri.HDLRunSceneIntent) - { - return new HDLRunSceneIntentHandlder(); - } + //if (intent is HDLRunSceneIntent) + //{ + // return new SiriKit.HDLRunSceneIntentHandlder(); + //} return this; } - //// Implement resolution methods to provide additional information about your intent (optional). - //[Export("resolveRecipientsForSearchForMessages:withCompletion:")] - //public void ResolveRecipients(INSendMessageIntent intent, Action<INPersonResolutionResult[]> completion) - //{ - // var recipients = intent.Recipients; - // // If no recipients were provided we'll need to prompt for a value. - // if (recipients.Length == 0) - // { - // completion(new INPersonResolutionResult[] { INPersonResolutionResult.NeedsValue }); - // return; - // } + // Implement resolution methods to provide additional information about your intent (optional). + [Export("resolveRecipientsForSearchForMessages:withCompletion:")] + public void ResolveRecipients(INSendMessageIntent intent, Action<INPersonResolutionResult[]> completion) + { + var recipients = intent.Recipients; + // If no recipients were provided we'll need to prompt for a value. + if (recipients.Length == 0) + { + completion(new INPersonResolutionResult[] { INPersonResolutionResult.NeedsValue }); + return; + } - // var resolutionResults = new List<INPersonResolutionResult>(); + var resolutionResults = new List<INPersonResolutionResult>(); - // foreach (var recipient in recipients) - // { - // var matchingContacts = new INPerson[] { recipient }; // Implement your contact matching logic here to create an array of matching contacts - // if (matchingContacts.Length > 1) - // { - // // We need Siri's help to ask user to pick one from the matches. - // resolutionResults.Add(INPersonResolutionResult.GetDisambiguation(matchingContacts)); - // } - // else if (matchingContacts.Length == 1) - // { - // // We have exactly one matching contact - // resolutionResults.Add(INPersonResolutionResult.GetSuccess(recipient)); - // } - // else - // { - // // We have no contacts matching the description provided - // resolutionResults.Add(INPersonResolutionResult.Unsupported); - // } - // } + foreach (var recipient in recipients) + { + var matchingContacts = new INPerson[] { recipient }; // Implement your contact matching logic here to create an array of matching contacts + if (matchingContacts.Length > 1) + { + // We need Siri's help to ask user to pick one from the matches. + resolutionResults.Add(INPersonResolutionResult.GetDisambiguation(matchingContacts)); + } + else if (matchingContacts.Length == 1) + { + // We have exactly one matching contact + resolutionResults.Add(INPersonResolutionResult.GetSuccess(recipient)); + } + else + { + // We have no contacts matching the description provided + resolutionResults.Add(INPersonResolutionResult.Unsupported); + } + } - // completion(resolutionResults.ToArray()); - //} + completion(resolutionResults.ToArray()); + } - //[Export("resolveContentForSendMessage:withCompletion:")] - //public void ResolveContent(INSendMessageIntent intent, Action<INStringResolutionResult> completion) - //{ - // var text = intent.Content; - // if (!string.IsNullOrEmpty(text)) - // completion(INStringResolutionResult.GetSuccess(text)); - // else - // completion(INStringResolutionResult.NeedsValue); - //} + [Export("resolveContentForSendMessage:withCompletion:")] + public void ResolveContent(INSendMessageIntent intent, Action<INStringResolutionResult> completion) + { + var text = intent.Content; + if (!string.IsNullOrEmpty(text)) + completion(INStringResolutionResult.GetSuccess(text)); + else + completion(INStringResolutionResult.NeedsValue); + } - //// Once resolution is completed, perform validation on the intent and provide confirmation (optional). - //[Export("confirmSendMessage:completion:")] - //public void ConfirmSendMessage(INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) - //{ - // // Verify user is authenticated and your app is ready to send a message. + // Once resolution is completed, perform validation on the intent and provide confirmation (optional). + [Export("confirmSendMessage:completion:")] + public void ConfirmSendMessage(INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) + { + // Verify user is authenticated and your app is ready to send a message. - // var userActivity = new NSUserActivity("INSendMessageIntent"); - // var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Ready, userActivity); - // completion(response); - //} + var userActivity = new NSUserActivity("INSendMessageIntent"); + var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Ready, userActivity); + completion(response); + } - //// Handle the completed intent (required). - //public void HandleSendMessage(INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) - //{ - // // Implement your application logic to send a message here. + // Handle the completed intent (required). + public void HandleSendMessage(INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) + { + // Implement your application logic to send a message here. - // var userActivity = new NSUserActivity("INSendMessageIntent"); - // var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Success, userActivity); - // completion(response); - //} + var userActivity = new NSUserActivity("INSendMessageIntent"); + var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Success, userActivity); + completion(response); + } - //// Implement handlers for each intent you wish to handle. - //// As an example for messages, you may wish to add HandleSearchForMessages and HandleSetMessageAttribute. + // Implement handlers for each intent you wish to handle. + // As an example for messages, you may wish to add HandleSearchForMessages and HandleSetMessageAttribute. - //public void HandleSearchForMessages(INSearchForMessagesIntent intent, Action<INSearchForMessagesIntentResponse> completion) - //{ - // // Implement your application logic to find a message that matches the information in the intent. + public void HandleSearchForMessages(INSearchForMessagesIntent intent, Action<INSearchForMessagesIntentResponse> completion) + { + // Implement your application logic to find a message that matches the information in the intent. - // var userActivity = new NSUserActivity("INSearchForMessagesIntent"); - // var response = new INSearchForMessagesIntentResponse(INSearchForMessagesIntentResponseCode.Success, userActivity); + var userActivity = new NSUserActivity("INSearchForMessagesIntent"); + var response = new INSearchForMessagesIntentResponse(INSearchForMessagesIntentResponseCode.Success, userActivity); - // // Initialize with found message's attributes - // var sender = new INPerson(new INPersonHandle("sarah@example.com", INPersonHandleType.EmailAddress), null, "Sarah", null, null, null); - // var recipient = new INPerson(new INPersonHandle("+1-415-555-5555", INPersonHandleType.PhoneNumber), null, "John", null, null, null); - // var message = new INMessage("identifier", "I am so excited about SiriKit!", NSDate.Now, sender, new INPerson[] { recipient }); - // response.Messages = new INMessage[] { message }; - // completion(response); - //} + // Initialize with found message's attributes + var sender = new INPerson(new INPersonHandle("sarah@example.com", INPersonHandleType.EmailAddress), null, "Sarah", null, null, null); + var recipient = new INPerson(new INPersonHandle("+1-415-555-5555", INPersonHandleType.PhoneNumber), null, "John", null, null, null); + var message = new INMessage("identifier", "I am so excited about SiriKit!", NSDate.Now, sender, new INPerson[] { recipient }); + response.Messages = new INMessage[] { message }; + completion(response); + } - //public void HandleSetMessageAttribute(INSetMessageAttributeIntent intent, Action<INSetMessageAttributeIntentResponse> completion) - //{ - // // Implement your application logic to set the message attribute here. + public void HandleSetMessageAttribute(INSetMessageAttributeIntent intent, Action<INSetMessageAttributeIntentResponse> completion) + { + // Implement your application logic to set the message attribute here. - // var userActivity = new NSUserActivity("INSetMessageAttributeIntent"); - // var response = new INSetMessageAttributeIntentResponse(INSetMessageAttributeIntentResponseCode.Success, userActivity); - // completion(response); - //} + var userActivity = new NSUserActivity("INSetMessageAttributeIntent"); + var response = new INSetMessageAttributeIntentResponse(INSetMessageAttributeIntentResponseCode.Success, userActivity); + completion(response); + } } } -- Gitblit v1.8.0