“告诉朋友”的例子,允许select多个联系人

我想在我的应用程序中添加一个“告诉朋友”选项,允许用户select多个联系人发送电子邮件。 联系人需要过滤到只有电子邮件地址的人。

有没有人知道我可以重复使用的这样一个好的例子。

我最近寻找同样的问题,我发现iTellAfriend。 这个对我有用。

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

在你的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任何地方调用下面的方法(最好在一个button中)

 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:@"xxxx@xxxx.com", @"xxxxx@xxxx.com", nil]; [picker setToRecipients:toRecipients]; [picker setSubject:self.messageTitle]; [picker setMessageBody:[self messageBody] isHTML:YES]; return picker; } 

当你点击你的button下面的场景将出现它不会发送电子邮件在模拟器上,但在设备上 在这里输入图像说明