我想在我的应用程序中添加一个“告诉朋友”选项,该选项允许用户选择多个联系人以向他们发送电子邮件。联系人需要过滤为仅具有电子邮件地址的联系人。

有没有人知道这样一个可以重用的示例。

最佳答案

我最近在搜索相同的问题,然后找到了iTellAfriend。这个对我有用。

github/iTellafriend下载此源代码。打开zip文件,并在src文件中将iTellAFriend.h和iTellAFriend.m拖到您的项目中。选中“将项目复制到目标组文件夹(如果需要)”和“为任何添加的文件夹创建组文件夹”

在您的appdelegate.m中添加#import "iTellAFriend.h"

将以下内容添加到您的appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
      //[iTellAFriend sharedInstance].appStoreID = yourAppId;
        [iTellAFriend sharedInstance].appStoreID = 408981381; //example

        return YES;
}


#import "iTellAFriend.h"添加到ViewController.m以及ViewController.m调用方法中的任何位置(最好在按钮中)

if ([[iTellAFriend sharedInstance] canTellAFriend]) {
            UINavigationController* tellAFriendController = [[iTellAFriend sharedInstance] tellAFriendController];
            [self presentModalViewController:tellAFriendController animated:YES];
        }


在iTellAFriend.m中修改以下内容

- (UINavigationController *)tellAFriendController
{
  MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  picker.mailComposeDelegate = self;


  [picker setSubject:self.messageTitle];
  [picker setMessageBody:[self messageBody] isHTML:YES];

  return picker;
}




- (UINavigationController *)tellAFriendController
{
  MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  picker.mailComposeDelegate = self;

    NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
    [picker setToRecipients:toRecipients];

  [picker setSubject:self.messageTitle];
  [picker setMessageBody:[self messageBody] isHTML:YES];

  return picker;
}


当您单击按钮时,将显示以下场景,它将不会在模拟器上但在设备上发送电子邮件

关于ios - “告诉 friend ”示例,允许选择多个联系人,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10095948/

10-12 00:11