你可以嘗試像下面
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString* html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray* dataToShare = @[html];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop];
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview: self.view];
[self presentViewController:activityViewController animated:YES completion:^{}];
您也可以在HTML源代碼寫入到本地文件,例如,my_mail_message.html
,然後再建一個NSURL
對象與該文件,例如,[NSURL URLWithString:@"file://my_mail_message.html"]
,然後使用NSURL
對象作爲您提供給initWithActivityItems:applicationActivities
的activityItems
數組的一個元素。希望能幫助到你!
這比使用舊的MFMailComposeViewController複雜得多。所以這基本上意味着沒有辦法用UIActivityViewController清理處理HTML郵件內容。 – Michel