UIDocumentInteractionController and print button issues: print option won't disappear - ipad

I've a problem with UIDocumentInteractionController. I'm able, through presentOptionsMenuFromBarButtonItem, to display the popover correctly.
When the user touch the barbuttonitem I fire the following method:
- (IBAction)share:(id)sender {
if (docIntController) {
[docIntController dismissMenuAnimated:NO];
docIntController = nil;
}
NSString *fileURL = [(Documents *)(self.detailItem) url];
NSArray *subStrings = [fileURL componentsSeparatedByString:#"/"];
NSString *filePath = [[self documentsDirectory] stringByAppendingPathComponent:[subStrings lastObject]];
docIntController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
docIntController.delegate = self;
docIntController.UTI = #"com.adobe.pdf";
[docIntController presentOptionsMenuFromBarButtonItem:sender animated:YES];
}
Anyway, when the user touches the print button, and then again the barbutton, the print option menu will not disappear, as you can see in the following image:
Moreover, if the user touches the print option again, the option popover will disappear (but not the old print option) and another print option popover will be created.
Indeed if the user touches outside of the popover to dismiss it, only the first one will be dismissed and the old one is empty as shown below:

I solved this by calling the dismissAnimated method on the UIPrintInteractionController
- (IBAction)share:(id)sender {
[[UIPrintInteractionController sharedPrintController] dismissAnimated:NO];
// remainder of share method code
}
You may want to break the dismissal code (both the UIPrintInteractionController and the DocumentInteractionController) into a separate method and simply call it in the share method. I ran into an issue where the print menu didn't dismiss in portrait mode on the iPad so I added a call to dismiss it in viewWillDisappear.

Related

ios webview won't stop loading..kind of

So in my web view controller pertaining to the UIWebViewNavigationTypeLinkClicked part, I have override methods.
Some pointing to urls which fire a download manager, and one part pertaining to a image view controller, in which it loads the image and allows me to save it.
It is held in a navigation controller just as my whole app is.
The first time I tap a image it loads fine, the previous view doesn't open the image as I have called [webView stopLoading]. The second time, maybe third time I tap the same image, the image loads in the same webview BUT also pushes my view controller.
I'm stuck as to why the first/second time i tap the image it's fine, but other times, it does it's own thing.
Below is the relevant code. Any help in solving this would be greatly appreciated.
///////////////
//IMAGE CODE///
///////////////
NSURL *imageURl = [request URL];
NSString *imageFileExtension = [[imageURl absoluteString] pathExtension];
NSLog(#"imageExtension is: %#", imageFileExtension);
NSSet *supportedFileExtensions = [NSSet setWithObjects:#"bmp", #"gif", #"jpg", #"jpeg", #"png", #"psd", #"pspimage", #"tga", #"tif", #"tiff", #"yuv", #"pdf", #"raw", nil];
if ([supportedFileExtensions containsObject:[imageFileExtension lowercaseString]]) {
[webView stopLoading];
//Image manager
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
WebImageViewController *vc = [[WebImageViewController alloc] initWithURL:[request URL]];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
NSLog(#"imageURL");
return NO; ///PART THAT WAS LEFT OUT.
}
Update right above.
Somewhere in updating my app to support iOS 8, I believe I managed to leave out my "return NO;" to each of my if/else statements.
Adding that in stops the webview from loading while passing the image to my custom view controller.

Application tried to present inside popover with transition style other than UIModalTransitionStyleCoverVertical before printing

I am trying to print a txt file from within a iPad 8.x application. So, I have this code:
- (void)onOpenWith:(UIButton *)theButton path:(NSString *)path
{
NSURL *URL = [NSURL fileURLWithPath:path];
if (URL) {
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
self.documentInteractionController.delegate = self;
[self.documentInteractionController presentPreviewAnimated:YES];
}
}
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}
Now everything is going as expected, I see a preview of the file, then I touch the icon on the top right corner of the screen and I am able to share the document in those applications that can handle it. However, if I touch PRINT I get this error message:
Application tried to present inside popover with transition style
other than UIModalTransitionStyleCoverVertical
and the app crashes. Sure, i understand it, but to which viewcontroller should I apply this transition? I have no control on the popover showing the print dialog...
In iOS 7 (real iPad not simulator) everything works...
Can anybody help me?
Thanks
Fabio
I also came across this issue, and the solution was that I had to build and run my app with Xcode 6 installed.
On my older machine, I have Xcode 5.1.1, and when run from there, this same issue appeared, and some more issues from this view (like cannot dismiss mail controller when opened from the top right corner).

iOS - how to let a view both respond a touch and let it pass through it

I'd like to have my UIWebView respond to touch event from user, and also let views from behind respond to touch. Is it possible?
basically, i'd like to have my UIWebView interact with a touch but not "swallowing" it, and let it go through for another lower view too.
The short answer, I believe, is no.
The best that you could do is to capture the touches in the UIWebView using one or more UIGestureRecognizers and then manually manipulate or trigger actions in the lower UIViews.
This is possible if an only if your webview is made by you. It will be done in PHP code for that site ie. when you tap on any button or any event is detected on your webview, then a parameter can be passed by PHP code from server in form of hidden field. You can recieve this by following code:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//NSString *html = [webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];
//NSLog(#"%#",html);
NSString *hdnPaymentStatusId = [webView stringByEvaluatingJavaScriptFromString: #"document.getElementById('yourParametrer1').value"];
NSLog(#"value%#",hdnPaymentStatusId);
if ([hdnPaymentStatusId integerValue] == 1)
{
DWMyOrdersViewController *myOrderVC = [self.storyboard instantiateViewControllerWithIdentifier:#"DWMyOrdersViewController"];
[self.navigationController pushViewController:myOrderVC animated:YES];
}
NSString *hdnCancelStatusId = [webView stringByEvaluatingJavaScriptFromString: #"document.getElementById('yourParametrer2').value"];
NSLog(#"value%#",hdnCancelStatusId);
if ([hdnCancelStatusId integerValue] == 1)
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}

Force "open in..." selection

My code at the moment looks like this:
- (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL
usingDelegate:(id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL:fileURL];
interactionController.delegate = interactionDelegate;
[interactionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
return interactionController;
}
- (void)showOptionsMenu
{
NSURL *fileURL = [NSURL fileURLWithPath:#"2bm.key"];
docController = [self setupControllerWithURL:fileURL
usingDelegate:self];
}
- (IBAction)KeynoteButton:(id)sender {
[self showOptionsMenu];
}
This generates an open in keynote bubble at the top left of the screen. Is it possible for me to move where this bubble appears? Or even better can I force a touch event on this bubble so the user does not have a choice, keynote opens automatically? I cannot use an URL reference scheme for this as keynote does not support this.
Thanks
You specify where the popover appears by specifying the proper location in the presentOpenInMenuFromRect:inView:animated: method. Right now you specify CGRectZero. Pass in the proper CGRect that indicates where you want it to appear.
You can't force a specific app. Many users will have several apps that can open the given file. Let the user choose where it is to go.

Another (!) Activity Indicator Issue

Well, after reading a bunch of SO posts on this issue, I still can't fix problems with my activity indicator. This indicator is in a view in a tab under the control of its own view controller. It has a view with a UIWebView which loads a local html page just fine. The view is loaded with initWithNibName and then awakeFromNib. Here's the part I think is relevant:
#implementation HelpViewController
#synthesize webView = _webView;
#synthesize back = _back;
#synthesize forward = _forward;
#synthesize aI = _aI;
- (void) viewDidLoad {
_aI = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_aI stopAnimating];
// Now add the web view
NSString *filePath = [[NSBundle mainBundle]
pathForResource:#"Help"
ofType:#"html"];
[self.view addSubview:_webView];
_webView.delegate = self;
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[_webView loadRequest:request];
[super viewDidLoad];
}
-(void) webViewDidStartLoad:(UIWebView *)webView {
[_aI startAnimating];
_back.enabled = NO;
_forward.enabled = NO;
}
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[_aI stopAnimating];
if (webView.canGoBack) {
_back.enabled = YES;
_back.highlighted = YES;
}
if (webView.canGoForward) {
_forward.enabled = YES;
_forward.highlighted = YES;
}
}
The navigation buttons work fine. The activity indicator was placed in the nib, but in the main view, not on/over/under the webView. In the attributes, I have Hides When Stopped checked. If I check Animating the indicator is always visible and animated, no matter how I navigate through the UIWebView.. If I uncheck Animating, Hidden is automatically checked for me. In this case, the indicator never shows up. So it's either always on or always off.
I've read quite a bit about cases where you need to have the indicator on a different thread. I'm not sure, but I don't think that applies here (I load a local html page but allow users to navigate off and then back to the local page). But, I seem to have some disconnect; perhaps it is the fact that the indicator is in the main view but the pages are in the webView? Or I'm not calling things in the right methods. Or who knows... Thanks for any help!
You overwrite _aI in your viewDidLoad and never place it in your view hierarchy, so the object you are sending the messages to is never visible and the activity indicator placed in interface build will never change its state, so thats why its either always animating or hidden.

Resources