电子邮件对话框未在iphone sdk中打开

时间:2013-04-25 10:38:46

标签: iphone ios objective-c xcode addressbook

在我的应用中,我使用PersonPicker视图从地址框中获取电子邮件ID。

当我选择任何电子邮件ID时,我尝试打开电子邮件对话框。但它只会打开&立即关闭。

我无法解决这个问题。

我从Here

获得了代码

我的代码如下:

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{

    // Get the first and the last name. Actually, copy their values using the person object and the appropriate
    // properties into two string variables equivalently.
    // Watch out the ABRecordCopyValue method below. Also, notice that we cast to NSString *.
    NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

    // Compose the full name.
    NSString *fullName = @"";
    // Before adding the first and the last name in the fullName string make sure that these values are filled in.
    if (firstName != nil) {
        fullName = [fullName stringByAppendingString:firstName];
    }
    if (lastName != nil) {
        fullName = [fullName stringByAppendingString:@" "];
        fullName = [fullName stringByAppendingString:lastName];
    }


    // Get the multivalue e-mail property.
    CFTypeRef multivalue = ABRecordCopyValue(person, property);

    // Get the index of the selected e-mail. Remember that the e-mail multi-value property is being returned as an array.
    CFIndex index = ABMultiValueGetIndexForIdentifier(multivalue, identifier);

    // Copy the e-mail value into a string.
    email = (NSString *)ABMultiValueCopyValueAtIndex(multivalue, index);
    NSLog(@"%@",email);
    // Create a temp array in which we'll add all the desired values.
    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    [tempArray addObject:fullName];

    // Save the email into the tempArray array.
    [tempArray addObject:email];


    // Now add the tempArray into the contactsArray.
    [contactsArray addObject:tempArray];
    NSLog(@"%@",contactsArray);
    // Release the tempArray.
    [tempArray release];

    // Reload the table to display the new data.
    [table reloadData];

    // Dismiss the contacts view controller.
    [contacts dismissModalViewControllerAnimated:YES];
    [contacts release];


    MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
    if (Apicker != nil)
    {

        [Apicker setSubject:@""];
        NSString * someString = nil;
        someString=@"<a href=\"https://www.google.com\">Google</a>";
        [Apicker setMessageBody:someString isHTML:YES];

        NSArray *toRecipients = [NSArray arrayWithObjects:email, nil];
        [Apicker setToRecipients:toRecipients];

        Apicker.mailComposeDelegate = self;
        [self presentModalViewController:Apicker animated:YES];
        [Apicker release];

    }



    return NO;
}

我认为这可能是解雇和放弃的问题。提出模态视图。

2 个答案:

答案 0 :(得分:1)

你的解雇和存在的问题是两者重叠。 - 解雇它然后显示它有点像你做但但你遇到了问题,因为这些东西是动画的。在那里没有动画或延迟预设直到解雇后

答案 1 :(得分:0)

这是您将获得Apple提供的示例代码的链接。 https://developer.apple.com/library/ios/#samplecode/QuickContacts/Listings/Classes_QuickContactsViewController_h.html

点击此链接并在顶部下载示例代码。我希望它会对你有所帮助。