Force "open in..." selection - ios

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.

Related

iOS share image AND text to WhatsApp

I have googled, and get some solutions, it seems the only possible way is thru UIDocumentInteractionController. I have found the result that able to share text ONLY, also found result that share image ONLY.
But what I want is share BOTH.
I know this question may be duplicated, I just wanted to make it clear, here is the screenshot...
(This is shared from Android)
You can use UIActivityViewController to share image , text or URL .Here is a small example :
NSString *textToShare = #"Enter your text to be shared";
UIImage * image = [UIImage imageNamed:#"imagename"];
NSArray *objectsToShare = #[textToShare, image];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
Run the above code and select whats app to share if you want you can share by other mediums also . This is apple'
s default share method
something not usually mentioned the user doesn't actually needs to share a text message and an image.
If your text contains URL then the whatsapp application will try to retrieve info about the URL and show a preview
In order for this to work you need to make the URL conform to open graph protocol. that basically means that the URL needs to have meta tags in its DOM which contain the relevant preview data
Good one,
As I know it is not possible in ios.
But I am having an alternate solution for it by which you can share text and image both.But it's a tricky or I think stupid solution.
Create a View where you can put your image.Write text on that view whatever you want to write.
Take Screen shot of that view with help of code.You will get image (image of view where text and image added).
Just share that image via document interaction controller.
This is just a possible solution if you want text and image both.But if you want to share link with text than . . . . . . .
You can use UIDocumentInteractionController for this purpose like this:
#property (retain) UIDocumentInteractionController * documentInteractionController;
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"whatsapp://app"]]){
UIImage * iconImage = [UIImage imageNamed:#"YOUR IMAGE"];
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/whatsAppTmp.wai"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = #"net.whatsapp.image";
_documentInteractionController.delegate = self;
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"WhatsApp not installed." message:#"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Check this answer for reference: https://stackoverflow.com/a/20601051/2082569
Also you can have a look at Socialize SDK that is also very easy to use and integrates with various social SDKs. Check this documentation for Whatsapp sharing: http://socialize.github.io/socialize-sdk-ios/whatsapp.html
Please check below project on github
https://github.com/salesawagner/SharingWhatsApp
typedef enum{
kSendText = 0,
kSendImage,
kSendTextWithImage,
kSendAudio,
kSendCancel
} options;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case kSendText:
[[WASWhatsAppUtil getInstance] sendText:#"Text"];
break;
case kSendImage:
[[WASWhatsAppUtil getInstance] sendImage:[UIImage imageNamed:#"image.jpg"] inView:self.view];
break;
case kSendTextWithImage:
NSLog(#"Send text with image");
case kSendAudio:
[[WASWhatsAppUtil getInstance] sendAudioinView:self.view];
break;
default:
NSLog(#"Cancel send");
break;
}
}

Is a custom UIActivity with the bookmark icon possible?

Part of my iOS app is a file viewer with a UIActivityViewController. From it, I would like users to be able to do normal activity view stuff with the file, like mailing it, saving it to photos (if it's a photo), and everything else. However, my app has a bookmarks feature. I would like for users to be able to bookmark files from this menu. I have created a custom UIActivity to add the object to the bookmarks list, but I have not been able to figure out how to have it use the system bookmark icon. Is this even possible?
EDIT: For clarification, this is in the menu that you get when you click a "share" button.
Easy peasy. It all depends on how you are initiating it, is it in a navigation controller, swipe gesture, toolbar item or just a regular button? Either way it doesn't matter but if you want a specific answer you'll have to ask a specific question.
Here is an example how to accomplish your goal buy using a bookmark button that is connected in Storyboard interface, however the IBActions for addToFav and download aren't an interface and don't need to be:
-(IBAction) moreActions:(id)sender {
UIActionSheet *moreActions = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Add To Favorites", #"Download For Offline View",#"Open Document In :", nil];
[moreActions showInView:self.view];
}
And the way you perform actions is by calling the method below:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0: [self addToFav:self]; //See IBAction below
break;
case 1: [self download:self]; //See IBAction below
break;
case 2: {
//UIDocumentInteractionController:
NSURL *docURL = [NSURL URLWithString:#"filePathStringHere"];
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:docURL];
[documentInteractionController setDelegate:self];
[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
break;
}
}
- (IBAction)download:(id)sender {
//enter your download code here
}
- (IBAction)addToFav:(id)sender {
//Code to add to your favorites
}

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).

how to get UIPopoverController from UIWebView

I load a webpage in a uiwebviewcontroller,after click one link, it will pop a popovercontroller, is it possible to get this controller in my code?
Actually, this popovercontroller is not created by my code. The html detect the webpage is loaded by iDevice and pop this. That means, if I use safari to open webpage, it also will display this popovercontroller.
Thanks.
implement the UIWebView delegate method.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if([urlString isEqualToString :#"abc.com") // link on which want to open popoverview
{
UIPopoverController itemPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
[itemPopover presentPopoverFromRect:customCell.addImage.bounds inView:webViewpermittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
return NO; //if wanted to load the link on UIWebview return YES else return NO
}
return YES;
}

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

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.

Resources