Attach object using iOS6 UIActivityViewController

后端 未结 3 1604
灰色年华
灰色年华 2020-12-16 23:35

I\'m migrating to use the UIActivityViewController for sharing in iOS6, but I can\'t figure out how to create email attachment objects to be included when sharing by email.<

3条回答
  •  旧时难觅i
    2020-12-16 23:56

    You have very limited control over UIActivityViewController, but if you're attaching well-know mime types, I found you can get it to work correctly by providing the associated file extension in a file URL. For example, if your attachment is a vCard, use the ".vcf" extension in the file URL:

    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    // The file extension is important so that some mime magic happens!
    NSString *filePath = [docsPath stringByAppendingPathComponent:@"vcard.vcf"];
    NSURL *fileUrl     = [NSURL fileURLWithPath:filePath];
    
    [data writeToURL:fileUrl atomically:YES]; // save the file
    
    // Now pass the file URL in the activity items array
    UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:
        @[@"Here's an attached vCard", fileUrl] applicationActivities:nil];
    [vc presentModalViewController:avc animated:YES];
    

提交回复
热议问题