Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I load internet files? #14

Closed
pepicrft opened this issue Oct 12, 2013 · 7 comments
Closed

How can I load internet files? #14

pepicrft opened this issue Oct 12, 2013 · 7 comments

Comments

@pepicrft
Copy link

I've implemented in my application a gallery with remote resources, and the one that I can't represent like images, gifs, videos.. I would like to open them with TTOpenInAppActivity. The problem is that I don't have the resources downloaded, I have their URLs. If I add the items to TTOpenInAppActivity in url format and for example the resource is a PDF I can't open it with external apps like Dropbox/Books...

I've tried to download it before and passing NSData to TTOpenInAppActivity, but I still have the same problem. Any suggestion about how can I get it?

Thanks

@honkmaster
Copy link
Owner

The problem is: UIDocumentInteractionController relies on local files. You coukd try to create temporary files, by donwloading the files you want to export from the internet. Than open the TTOpenInAppActivity, afterwards you can delete the temporary files.

@pepicrft
Copy link
Author

Thanks @honkmaster ;)

@honkmaster
Copy link
Owner

Another notice: You don`t have to use nsdata as activity item. You just have to use a NSURL-Object pointing to a local file.

@pepicrft
Copy link
Author

Thanks @honkmaster I discover later ;), I've to implement then a cache system downloading locally files cleaning them with care :)

@pepicrft
Copy link
Author

Maybe you can help me @honkmaster , I'm trying to do the way you comment but the app crash and I don't know why because I don't get any error in console. That's the code:

 //Generating activities
    TTOpenInAppActivity *openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.view andRect:self.view.frame];
    [activities addObject:openInAppActivity];
    TUSafariActivity *safari = [[TUSafariActivity alloc] init];
    [activities addObject:safari];
    ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
    [activities addObject:chromeActivity];


    // Generating and presentin UIActivity
    if([NSData dataWithContentsOfFile:upload.path]){
        //We've the data locally
        UIActivityViewController *activityViewController= [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:upload.path]] applicationActivities:activities];
        //openInAppActivity.superViewController = activityViewController;
        [self.navigationController presentViewController:activityViewController animated:YES completion:NULL];
    }else{
        //We've to download
        [SVProgressHUD show];

        [upload downloadData:^(float progress) {
            if(progress==1.0){
                [SVProgressHUD dismiss];
                UIActivityViewController *activityViewController= [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:upload.path]] applicationActivities:activities];
                //openInAppActivity.superViewController = activityViewController;
                [self.navigationController presentViewController:activityViewController animated:YES completion:NULL];
            }
        } withErrorBlock:^(NSError *error) {
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"Error loading attachment", nil)];
        }];
    }

And from console I don't receive any kind of error. It's strange

@pepicrft
Copy link
Author

Sure @honkmaster , I discovered 😛 thanks for all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants