Tumblr的UIDocumentInteractionController

Ale*_*der 0 iphone sharing tumblr ios

我需要在Tumblr中分享照片,在iOS中使用app Tumblr.

对于Instagram我喜欢这样:

  NSData *imageData = UIImageJPEGRepresentation(self.test.image, 1.0);

    NSString *writePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"instagram.igo"];
    if (![imageData writeToFile:writePath atomically:YES]) {
        NSLog(@"image save failed to path %@", writePath);
        return;
    } 

    // send it to instagram.
    NSURL *fileURL = [NSURL fileURLWithPath:writePath];
    self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    [self.documentController setUTI:@"com.instagram.exclusivegram"];
    [self.documentController setAnnotation:@{@"InstagramCaption" : @"#hey"}];

    if (![self.documentController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES]) NSLog(@"couldn't present document interaction controller");
Run Code Online (Sandbox Code Playgroud)

但是我不知道怎么会这样,但对于Tumblr,谢谢

jay*_*ava 8

- (IBAction)btn_tumblr:(id)sender{

CGRect rect =  CGRectMake(0, 0, 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.frame.size,self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();

[UIImageJPEGRepresentation(getShareimage, 1.0) writeToFile:[NSString stringWithFormat:@"%@/%@",[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"],@"photo.tumblrphoto"] atomically:YES];
NSURL *fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"],@"photo.tumblrphoto"]]; 
self.dic.delegate = self;
self.dic.UTI = @"com.tumblr.photo";
[self setupControllerWithURL:fileURL usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:fileURL];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];}


- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate{
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;}
Run Code Online (Sandbox Code Playgroud)

试试这一个......!:)