Ejemplo n.º 1
0
        public void ResolveRecipients(INSearchForMessagesIntent 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> ();

            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());
        }
Ejemplo n.º 2
0
        public void ResolveRecipients(INSendMessageIntent intent, Action <INPersonResolutionResult []> completion)
        {
            var resolutionResults = new List <INPersonResolutionResult> ();
            var matchingContacts  = new List <INPerson> ();

            // Verify Recipients
            var recipients = intent.Recipients;

            if (recipients.Length == 0)
            {
                // We must have at least one recipient
                resolutionResults.Add(INPersonResolutionResult.NeedsValue);
            }
            else
            {
                // Scan all recipients
                foreach (var recipient in recipients)
                {
                    // Know user to ElizaChat
                    if (AddressBook.FindUser(recipient.Identifier) == null)
                    {
                        matchingContacts.Add(recipient);
                    }
                }

                // Take action based on the found recipients
                switch (matchingContacts.Count)
                {
                case 0:
                    // We have no contacts matching the description provided
                    resolutionResults.Add(INPersonResolutionResult.Unsupported);
                    break;

                case 1:
                    // We have exactly one matching contact
                    resolutionResults.Add(INPersonResolutionResult.GetSuccess(matchingContacts[0]));
                    break;

                default:
                    // We need Siri's help to ask user to pick one from the matches.
                    resolutionResults.Add(INPersonResolutionResult.GetDisambiguation(matchingContacts.ToArray()));
                    break;
                }
            }

            // Report results to Siri
            completion(resolutionResults.ToArray());
        }