我正在创建一个UIActivityViewController,我正在传递图像&文本到Facebook,邮件,推特。
-(void)Activityshowmethod{
NSLog(@"The Selected Photo Count %i",[self.selectedPhotos count]);
//UIActivityViewController *activityViewController2 =[[UIActivityViewController alloc]init];
NSMutableArray *newArray=[[NSMutableArray alloc]init];
NSMutableArray *newArraytext=[[NSMutableArray alloc]init];
logactivity *shopactivity=[[logactivity alloc]init];
[shopactivity setSelectedthings:self.selectedPhotos];
for (log * ChosenPhot in self.selectedPhotos) {
NSString *initalTextString = [NSString
stringWithFormat:@"I am Sending from my log : %@",
ChosenPhot.categoryname];
//[newArraytext arrayByAddingObject:initalTextString];
[newArraytext addObject:initalTextString];
CreateShoplogTagImage *createimagetag=[[CreateShoplogTagImage alloc]init];
UIImage *newimage=[createimagetag Imagetag:ChosenPhot];
[newArray addObject:newimage];
}
//NSMutableArray *addArray=[[NSMutableArray alloc]initWithObjects:newArray,newArraytext, nil];
NSMutableArray *addArray=[[NSMutableArray alloc]initWithArray:newArray];
[addArray addObjectsFromArray:newArraytext];
UIActivityViewController *activityViewController2 =[[UIActivityViewController alloc]initWithActivityItems:addArray applicationActivities:@[shopactivity]];
[self presentViewController:activityViewController2 animated:YES completion:^{}];
}
虽然我想在同一个UIActivityViewController中共享文件,所以我创建了自己的UIActivity,我在其中创建了文件
- (void)performActivity
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"slog.log"];
NSLog(@"The String of the Path is :%@",filePath);
NSData *savedData = [NSKeyedArchiver archivedDataWithRootObject:self.Selectedthings];
[savedData writeToFile:filePath atomically:YES];
//[self.Selectedthings writeToFile:filePath atomically:YES];
TestViewController *test=[[TestViewController alloc]init];
NSLog(@"I have Pushed the Shoplog Button");
[test showmailcomposer:savedData];
}
然后我尝试从我的rootviewcontroller(Testviewcontroller)显示邮件编辑器 使用以下代码:
-(void)showmailcomposer:(NSData*)datafile{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer =[[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Check out these Shoplog Photos"];
NSMutableString *emailBody = [NSMutableString string];
[mailer addAttachmentData:datafile mimeType:@"log" fileName:@"Slog"];
[emailBody appendFormat:@"Sent from my log " ];
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:^{}];
}
}
我得到的错误如下:
超时消息传递确定CanSendMail状态的邮件