UIActivityView doesn't display other apps as option to open pdf - iphone

I'm displaying a PDF in my app and I want to have to same "openIn" functionality as the default iOS mail client.
The code I have is as follows:
NSURL *url = [NSURL fileURLWithPath:#"/var/mobile/Applications/21D850EA-409A-4231-BDFE-6B79FC721DA3/Library/Caches/1373665423163257247920130712/84cd7f88cf1b400cb1f4a4d6ac439649.pdf"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[url] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
I've hard coded the path for testing.
The first image below is how it looks in the mail client.
The second image is how it looks in my app.
Any help would be great.

You misunderstand what is happening. In the Mail app you have opened the PDF in the preview window. The actions icon then brings up a UIDocumentInteractionController with the standard "options" menu.
The UIActivityController does not provide any "open in" functionality. If your want the same options in your app as from the Mail attachment preview window, use a UIDocumentInteractionController and use one of the presentOptionsMenu... methods.

Related

While clicking on some links on UIWebview it's automatically connect(go) to the itunes. but cannot get back to the app after clicking a iTunes link

Here we are using UIWebview related application.
while clicking on some links, it's automatically connect(go) to the itunes.
but it's cannot get back to the app after clicking a itunes link (with out clicking on Exit).
My Question is, how can come back to the app after clicking a itunes.
Try this one uiwebview delegate method.
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}
return YES;
}
I usually insert a button next to UIWebView.
Use a new view and insert button in any corner of view and then put your UIWebView, set your uiwebview is not fit to screen so you can push to exit button. When you tap to button than hide your view. ITs usually what i do for such situation, maybe it can help to you
When you click on any link and you now go to at this link of page and if you want to go previous to your application. Generally You can not go Back to your Application because Apple iOS does not provide this types of feature.
I am not sure but It may be possible in JB Device.
you can add custom tool bar at the top of your view and add back button to custom tool bar to come back to your app. Below to custom tool bar add your webview.Hope it will helps you.
If you are loading the webpage with Safri or you are opening iTunes app with custom schema, it is not possible, because you are leaving the app.
But yes you can do this, If you will load that itunes connect link through web view, and there you can place a custom back button to come back to your previous page.
For Example :
UIWebView *webView=[[UIWebView alloc]init];
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.xyz.com"]]];

UIDocumentInteractionController no longer works in iOS6

I have an app that shares with instagram built for iOS5 and now in iOS6, sharing no longer works although canOpenURL returns true and code executes. The images are saved to the documents folder of the application with a .igo extension. This is passed to instagram with com.instagram.exclusivegram.
The code is below, it enters the if statement and displays "here in" but does not open the Share With dialog like it used to at the bottom of the screen.
NSLog(#"%#", _imgToUpload);
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
uidController = [[UIDocumentInteractionController alloc] init];
//imageToUpload is a file path with .igo file extension
uidController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:_imgToUpload]];
uidController.UTI = #"com.instagram.exclusivegram";
uidController.delegate = self;
CGRect navRect = self.view.frame;
[uidController presentOpenInMenuFromRect:navRect inView:[UIApplication sharedApplication].keyWindow animated:YES];
NSLog(#"here in");
}
_imgToUpload is providing the correct filepath as well.
Thank you,
Nick
Just did some testing and found a solution. Do not present in the keyWindow.
[uidController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];
I have tested this and it will fix the problem.
Another reason for the uidocumentinteraction controller not working in iOS6 is that the new action sheet/launch panel (it shows apps available to open the doc) is now used. My app which worked fine launching iBooks with iOS5 failed because I launched from viewDidLoad which was now too early and I got an error on the current view controller 'whose view is not in the window hierarchy' so I changed my code to performselector after delay of 1 second. The app now calls iBooks via the new panel.

get the list of application through UIDocumentInteractionController

I am using UIDocumentInteractionController to open the list of available pdf application in my device when i click on button but now i want to display setting table which will show the list of all the application and user will be directlly redirect to that applcation next time without displaying the actionsheet or any option
my cade is as below:
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController retain];
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
how can i do that?
You don't, it's not possible using the official SDK to:
Get a list of apps that open a certain file
Open a file with a certain app
One thing you can do is open a URL and the system will decide which app to open.

how to show ppt slideshow in iphone?

I want to show the power point presentation in iphone .
Is this possible ? because I want to show it in the slide show manner .
I however able to show ppt in the webView . but it is in the vertical manner .
I think if i convert all ppt into images and then show that images into scrollbar but i don't know if this is possible .
so if anyone have idea about this . please share here
Edit..
I am using UIDocumentInteractionController but I am unable to see the ppt .. this is the code ..
NSString * path = [[NSBundle mainBundle] pathForResource:#"Sun2" ofType:#"ppt"];
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
docController.delegate = self;
[docController retain];
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
You could write some functions that do exactly as you have described, or consider the use of Apple's own UIDocumentInteractionController.
Be sure to implement the delegate method:
(UIViewController*)documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController*)controller
... which will return the view controller that is to push the document controller.
You may also find some of the code in an old question of mine to be helpful:
UIDocumentInteractionController crashing upon exit

Open file in another app

My app needs to open some file types in other apps, like dropbox app does, it could list the installed apps which could open specific types of file.
How can get the app list?
You'll want to use UIDocumentInteractionController. See also the Document Interaction Programming Guide.
You can use QLPreviewController from the official docs.
Expanding on jtbandes's answer, here's the code that worked for me:
NSURL *url = [NSURL fileURLWithPath:filePath];
UIDocumentInteractionController *popup = [UIDocumentInteractionController interactionControllerWithURL:url];
[popup setDelegate:self];
[popup presentPreviewAnimated:YES];
And don't forget to include this in your H file:
#interface MyViewController : UIViewController <UIDocumentInteractionControllerDelegate>
Also worth noting: this will open a new fullscreen view that has a Document Viewer, as well as the Share button that offers all the various apps that can open this file. If you're just looking for the Share popup, equivalent to the UIActivityViewController, this will do it, but with some extra functionality you may not want.