2

ユーザーが電話のアドレス帳から連絡先を選択し、その連絡先を UITableView に表示できるようにするアプリに取り組んでいます。次のコードを使用して連絡先を取得します。

-(IBAction)pickPhoneContacts:(id)sender //opens phone's address book
{
   ABPeoplePickerNavigationController *picker =

   [[ABPeoplePickerNavigationController alloc] init];

   picker.peoplePickerDelegate = self;

   [self presentViewController:picker animated:YES completion:nil];

}

  //called when user presses the cancel button in the Address book view controller
  - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController*)peoplePicker

 {
    [self dismissViewControllerAnimated:YES completion:nil];
 }


   //called when user pics up a contact from the phone's address book

   - (BOOL)peoplePickerNavigationController:

  (ABPeoplePickerNavigationController *)peoplePicker

  shouldContinueAfterSelectingPerson:(ABRecordRef)person {


  [self displayPerson:person]; //calls displayPerson:(ABRecordRef)person to show contact's information in the app

  [self dismissViewControllerAnimated:YES completion:NULL];

   return NO;
}


//called when the user selects the property of the contact. This method will not be called in the  app but included to complete the implementation of the protocol


- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)

peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person

 property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
 {
   return NO;
 }

   //Displays the contact name and the contact's primary number in the app's text fields (add contact view controller)
 - (void)displayPerson:(ABRecordRef)person
 {
    NSString* name = (__bridge_transferNSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty); //Extracts the contact's first name from address book & assigns it to a string value


  self.contactNameTextFiled.text = name;

  NSString* phone = nil;

  //Extracts the first phone number among multiple contact numbers from address book & assigns it to a string value
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,kABPersonPhoneProperty);

if (ABMultiValueGetCount(phoneNumbers) > 0)
{
    phone = (__bridge_transfer NSString*)

    ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

}
else
{
    phone = @"[None]";
}

self.primaryNumberTextField.text = phone;

CFRelease(phoneNumbers);

}

ここでのタスクは、ユーザーがアドレス帳から連絡先を取得するとすぐに、ABPeoplePickerNavigator を閉じて、すぐに MFMessageComposeViewController が既定のメッセージと選択した連絡先番号を表示することです。アプリのユーザーが選択した連絡先番号にメッセージを送信するようにします。メッセージ作成ビューコントローラーに次のコードを使用しました。

-(void)sendSMS
{
   MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
   if([MFMessageComposeViewController canSendText])
   {
      controller.body = @"Test Message";
      controller.recipients = [NSArray arrayWithObjects:@"111222333", nil];
      controller.messageComposeDelegate = self;
       [self presentViewController:controller animated:YES completion:nil];

   }

}

ABPeoplePickerNavigationController が終了するとすぐに MFMessageComposeViewController が表示されるように、このメソッドをどこで呼び出す必要があるか教えてください。

4

4 に答える 4

1

新しい関数dismissViewControllerAnimatedを使用します:completion:完了後、コードを編集したので、SMSを送信します。

- (BOOL)peoplePickerNavigationController:

  (ABPeoplePickerNavigationController *)peoplePicker

  shouldContinueAfterSelectingPerson:(ABRecordRef)person {


  [self displayPerson:person]; //calls displayPerson:(ABRecordRef)person to show contact's information in the app

//  [self dismissViewControllerAnimated:YES completion:NULL];
    [self dismissViewControllerAnimated:YES completion:^{
        [self sendSMS];
    }];

   return NO;
}
于 2013-01-29T06:56:19.947 に答える
0

試してみる

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person;

電話

-(void)sendSMS

disconnectViewControllerAnimated:completion: 完了ハンドラーで。

[self dismissViewControllerAnimated:YES completion:{[self sendSMS]}];

これが役立つことを願っています。

于 2013-01-29T07:01:04.870 に答える
0

あなたがそれを閉じるときは、あなたのアドレスコントローラーのアニメーションをいいえに設定してください

    [self dismissViewControllerAnimated:NO completion:nil];
于 2013-01-29T06:53:55.423 に答える