0

我已经尝试过这段代码,但它显示错误

警告:尝试呈现 <_UIDocumentActivityViewController: 0x16acdc00> 已在其上呈现 <_UIDocumentActivityViewController: 0x16ae4800>

如何解决这个问题?

-(IBAction)saveToInstagram:(id)sender {


        CGRect rect = CGRectMake(0 ,0 , 0, 0);
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.ig"];

        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
        NSLog(@"JPG path %@", jpgPath);
        NSLog(@"URL Path %@", igImageHookFile);
        self.docFile.UTI = @"com.instagram.photo";
        self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
        [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
        NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
        }
        else {
            NSLog(@"No Instagram Found");
        }



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

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {

}
4

2 回答 2

2

问题是,在呈现第一个 docfile 时,您尝试呈现第二个

// First presentation
[self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {

        // Second presentation
        [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ]; 
}

我真的不明白为什么你需要两次使用相同的方法,但如果你真的这样做,那么对于第一个演示文稿使用动画:不。我会建议某种完成代码块,但似乎没有这样的方法UIDocumentInteractionController

于 2016-03-02T11:29:55.933 回答
0
Don't forget to add <string>instagram</string> in you plist array with key: LSApplicationQueriesSchemes.

    @property (nonatomic, strong) UIDocumentInteractionController *docIC;        

    - (void)sharePhoto:(UIImage *)image caption:(NSString *)caption
    {
        NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
        {
            NSString *imgPath = [TUtil documentPath:@"Image.igo"];
            NSData *data = UIImageJPEGRepresentation(image, 1.0);
            [data writeToFile:imgPath atomically:YES];


            NSURL *igImageHookFile = [NSURL fileURLWithPath:imgPath];
            self.docIC = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
            [self.docIC setDelegate:self];
            [self.docIC setUTI:@"com.instagram.exclusivegram"];

            // Subject
            [self.docIC setName:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];

            //http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
            //self.docIC.annotation = [NSDictionary dictionaryWithObjectsAndKeys:caption, @"InstagramCaption", nil];

            [self.docIC presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
        }
        else
        {
            NSString *iTunesLink = @"itms-apps://itunes.apple.com/app/id389801252?mt=8";
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
        }
    }
于 2017-05-25T03:11:34.137 回答