Facebook、mail、twitterに画像とテキストを渡すUIActivityViewControllerを作成しています。
-(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の状態を判断するためのメッセージメールのタイムアウト