Does presentOpenInMenuFromRect close calling program? - ios

I'm developing a PhoneGap Build application, but needed a way to prompt my user to open local files in Adobe Reader (inAppBrowser will not work for my situation). I found a 3rd party plugin for PhoneGap that does what I need. However it only does it for remote .pdf files. I have figured out how to alter the plugin code to work with local files on the iPad/iPhone but it seems to close my application when the user opens the pdf in Adobe Reader.
I know almost nothing about objective C, Xcode, etc.
Desired functionality is:
User navigates my app searching or browsing for files
Finds desired file
Selects file
User is presented with "open with" options of which one is Adobe reader
User selects Adobe, PDF opens
User returns to my app in location they left it
I have it all working except on step #6 above my app seems to be closed. If I press the home button twice app show up at the bottom of iPad but when selected app starts from closed state showing splash screen. I'd like it to be where the user left it.
I believe the relevant code is
NSURL *fileURL = [NSURL fileURLWithPath:localFile];
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[controller retain];
controller.delegate = self;
controller.UTI = uti;
CDVViewController* cont = (CDVViewController*)[ super viewController ];
//CGRect rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height);
CGRect rect = CGRectMake(0, 0, 1024, 768);
[controller presentOpenInMenuFromRect:rect inView:cont.view animated:YES];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: #""];
[self writeJavascript: [pluginResult toSuccessCallbackString:callbackID]];
[callbackID release];
[path release];
[uti release];
Where this line
[controller presentOpenInMenuFromRect:rect inView:cont.view animated:YES];
prompts the user to select Adobe. Is there a parameter I can pass here to not have my application shut down once the user selects to open the pdf in Adobe?
Thanks!
The plugin I have altered in its original state can be found and discussed here:
http://www.tricedesigns.com/2012/08/15/open-with-in-ios-phonegap-apps/

Related

Multiple UIWebView instances or what is it?

I have an app with a UIWebView in a UIView.
URL to image
At this picture I see all my websites I visited. If I open Safari -> Developer -> Name of testing iPhone -> listed content of the picture. Are these visited sites different UIWebView instances?
Is my suspicious correct or what is there shown?
-(void)createWebView {
//[[self webView] removeFromSuperview];
//[[self view] willRemoveSubview:[self webView]];
[self setWebView:[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]];
dispatch_async(dispatch_get_main_queue(), ^{
[[self view] addSubview:[self webView]];
});
[[self webView] setScalesPageToFit:YES];
[[self webView] setDelegate:self];
}
webView is a variable in my header file of type UIWebView and at every new entered URL the webview should be overwritten every time.
Every Instance of UIWebView holds its own history.
General Safari history is restricted to be accessed. And even if you managed to get them, i doubt your app will be accepted by Apple review team.
So the solution i think is to create NSMutableArray and loop on your UIWebViews and add their history into a single place -your created array-.
By so you will have all your local history in that array and do whatever you want with it.

After Successful twitter sharing call back not coming to my app

I am using the following code for twitter sharing. Here i am checking if twitter native app installed in the device then i am opening the native app otherwise i am opening the webView for twitter sharing. Using the following code i am able to do twitter sharing, But the problem is After successful sharing the call back is not coming to my app, It is going to twitter app.
NSURL *instagramURL = [NSURL URLWithString:#"twitter://post?message=hello%20world"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
} else {
// Share this on Twitter
GenericWebViewController *gwvController=[[GenericWebViewController alloc] init];
[gwvController loadWithUrl:[NSURL URLWithString:#"https://twitter.com/intent/tweet?url=www.google.com&text=I%20am%20eating%20branston%20pickel%20right%20now&original_referer=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F9127808%2Fhow-do-you-include-hashtags-within-twitter-share-link-text"] navBarTitle:#"Twitter"];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: #"" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[self.navigationController pushViewController:gwvController animated:YES];
//WI-542:Showing the navigation bar in WebView when user user navigate from deal details.
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
How can i come back to my app after successful sharing.
You can not! Once you launch an external application, you can not go back to your application, unless the external application is specifically done this way (using a "callback" arg for instance), but very few "big name" (twitter, facebook,...) works this way
If you want to use Twitter and still don't exit from your app, use the Twitter frame work (https://developer.apple.com/library/ios/documentation/Twitter/Reference/TwitterFrameworkReference/_index.html )
It's a little bit more complex, but you'll gain the benefit of remaining in your app.

Which file types can UIDocumentInteractionController preview?

I'm putting a UIDocumentInteractionController into my app, which can download arbitrary file types from a server.
It's there for two purposes:
To allow the user to 'Open In' the file in another app that may be able to view the file.
To preview files that the built-in UIDocumentInteractionController is able to preview.
What I'd like to so is to only attempt to display the preview for file types that the system is able to preview. For example, if it's a zip file, the system can't preview that so I want to go straight to the 'Open In'.
I can't find anywhere a list of the types that are supported for preview.
Here's my code:
self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
[self.docController setDelegate:self];
// I'd like to skip this line if the system can't preview the file.
BOOL isOpen = [self.docController presentPreviewAnimated:YES];
if (!isOpen) {
BOOL canOpen = [self.docController presentOpenInMenuFromRect:CGRectMake(300, 300, 100, 100)
inView:self.view
animated:NO];
if (!canOpen) {
// tell user to install an app that's able to open this file.
return;
}
}
The method presentPreviewAnimated: returns a BOOL value (YES if it manages to preview and NO for not managing) so you can:
if (![self.docController presentPreviewAnimated:YES])
{
//present openIn
}

Certain UIActivityViewController services missing from my app

I have implemented UIActivityViewController within my app and can successfully share both strings and images. However, I notice that when you share an image within the iOS Photos app, there are some services that do not appear in my app. Namely Print, Use as Wallpaper, and Assign To Contact, and Photo Stream. My app is able to use Mail, Message, Facebook, Twitter, and Copy just fine.
I am thinking that either:
1.) These extra services have been implemented as custom services within the Photos app using UIActivityItemProvider, UIActivityItemSource, etc..
2.) The data that I am providing is not in the correct format to be used with these services.
I have read through the documentation a few times, but don't seem to see anything about it.
Edit: Showing code as requested:
#define SM_SHARE_IMAGE_AND_STRING 1
-(void)actionToolbarViewControllerUserTappedShareButton:(SMActionToolbarViewController*)sender{
// Reposition anchor view for UIPopoverController to point at
[self repositionAnchorViewToButtonFrame:self.actionToolbarViewController.shareButtonFrame];
// Asynch download of image
[SMUtility downloadAsset:self.selectedAsset completion:^(UIImage *image) {
// Create image source
SMActivitySource *activityImageSource = [[SMActivitySource alloc]initWithImage:image];
#if defined(SM_SHARE_IMAGE_AND_STRING)
// Create string source
NSString *assetsString = [SMUtility assetsString:[NSArray arrayWithObject:self.selectedAsset]];
SMActivitySource *activityStringSource = [[SMActivitySource alloc]initWithString:assetsString];
// Present UIActiviyViewController within an UIPopoverController
NSArray *items = [#[activityImageSource, activityStringSource]mutableCopy];
#else
NSArray *items = [#[activityImageSource]mutableCopy];
#endif
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed){
[SMMixPanel eventSharePhotoMethod:#"Share"];
}];
self.buttonPopoverController = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.buttonPopoverController presentPopoverFromRect:self.anchorView.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}];
}
The Print, and Assign To Contact activities are standard activities shown by the UIActivityViewController as long as you provide the proper data.
You must provide a UIImage for the Assign To Contact activity. See the docs for UIActivityTypeAssignToContact. See the docs for UIActivityTypePrint for details on what it accepts.
The "Use As Wallpaper" seems to be a custom activity shown only in the Photos app.

UIDocumentInteractionController opening pdf in iBooks crashes

I have a test PDF file that I want to open in iBooks through my app. I saved it in my temp directory and I use this code to load it to iBooks:
NSURL *targetURL = [NSURL fileURLWithPath:tempFullPath];
NSLog(#"Path is %#", tempFullPath);
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:targetURL];
controller.delegate = self;
controller.UTI = #"com.adobe.pdf";
[controller presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
The menu pops up just fine but when I tap the iBooks button the app crashes and hangs my Xcode.
The path to the file I get in my NSLog output is like this:
Path is /private/var/mobile/Applications/65EC4182-A79B-431C-9E74-BD72D91A31AB/tmp/TestFile.pdf
What am I doing wrong? Thanks in advance!
The use of a UIDocumentInteractionController requires that you keep a reference around until it is complete. This means you should use an instance variable, not a local variable. Implement the proper delegate methods so you can reset the ivar when you are done with the controller.
Enabling zombies will help debug such an issue. Most likely you will see that a message is being sent to a deallocated object (your controller).

Resources