UIActivityViewController not showing "Open in iBooks" option - objective-c

I have a problem in my app. After getting some statistics, I generate a PDF file, and I want to show an UIActivityViewController with the options "Open in iBooks" and "Send By Mail" mainly (others like "Open in Dropbox" would be great to).
Well the thing is that before trying to use UIActivityViewController, I was using UIDocumentInteractionController, with the following code:
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[_docController presentOpenInMenuFromRect:_openInIBooksButton.bounds inView:self.openInIBooksButton animated:YES];
Where url is a path like /Documents/../statistics.pdf. It worked, it showed a popover with the buttons open in iBooks and open in Dropbox, but not Send by Mail. Now I've changed it with the following code:
NSArray* itemsToShare = [NSArray arrayWithObjects:pdfData, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];
Where pdfData is a NSData object. And it works too, but now it shows the option of sending it by email, but not the iBooks option. I'm going nuts because I don't find the reason of that behavior and I need the two options, iBooks and Mail.
I don't know if it has something to do with the fact that the UIDocumentInteractionController has a path which ends with .pdf and the UIActivityViewController only has a NSData object. But I can't find a solution for that.
Somebody has found that problem before?
Thank you very much.

When you use presentOpenInMenuFromRect:inView:animated: you only get a list of apps that can work with the given file.
What you want to use is presentOptionsMenuFromRect:inView:animated: which gives you the options that you are looking for.

Related

how can i show the pdf hyper link data in popover in iPad apps?

i have worked pdf file reader in iPad apps using QLPreviewcontroller but i need to show the inside of pdf hyper link show on popover in iPad any one can help out.
documentPath = [[NSBundle mainBundle] pathForResource:#"my_file" ofType:#"pdf"];
fileURL = [NSURL fileURLWithPath:documentPath];
//fileURL = [NSURL URLWithString:kStringURLUIDocumentInteractionControllerPDF];
}
//creating the object of the QLPreviewController
QLPreviewController *previewController = [[QLPreviewController alloc] init];
//settnig the datasource property to self
previewController.dataSource = self;
//pusing the QLPreviewController to the navigation stack
[[self navigationController] pushViewController:previewController animated:YES];
//remove the right bar print button
[previewController.navigationItem setRightBarButtonItem:nil];
[previewController release];
What you are asking is not impossible, but is extremely complicated and likely will take thousands of lines of code. Quartz has all the functions you'll need to do what your asking, but it will be a major undertaking into poorly documented structures.
This would be much more possible to accomplish using an external library. I've done it before with PSPDFKit as well as Foxit Embedded SDK, but neither is cheap. If your code is GPL licensed, you could consider MuPDF, but it's probably not helpful for commercial software.

Facebook, Twitter icon not showing in UIActivityViewController on iOS7

I have added this code for presenting a UIActivityViewController:
-(IBAction)activityAction:(id)sender
{
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:#"Hello Welcome!",[UIImage imageNamed:#"scene3.jpg"],nil] applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
[self presentViewController:activityViewController animated:YES completion:nil];
}
Facebook, Twitter and Weibo icons are not showing in iOS7. In iOS6, all the icons are showing correctly. See the screenshot below:
How can I solve this?
You're probably not logged in to Facebook or Twitter in the devices Settings. They won't show up here unless the user is logged in. File a bug with Apple.
Look at the name of the property excludedActivityTypes, you are excluding facebook, twitter, ...
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
excludes only Weibo and Assign to contact
Make sure that you don't exclude the Activities that you want to use.
So, remove "UIActivityTypePostToFacebook" & "UIActivityTypePostToTwitter" from "activityViewController.excludedActivityTypes" object.
Also, Make sure that you are logged in into Facebook and Twitter accounts in order to post on respective social platform.
Please note that this is working on simulator and real devices.
Hope this helps you.
Your code,
activityViewController.excludedActivityTypes = #[UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
Change to this,
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
And if you have to logged into facebook, twitter on your device settings. Then only it will be visible.
Thanks,
Don't include UIActivityTypePostToFacebook in
activityViewController.excludedActivityTypes = #[UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
[self presentViewController:activityViewController animated:YES completion:nil];

iOS - Only first line of text is viewable

In two places in our app the text that the user types in only shows first line of text. Both occurances are in external frameworks, first in UIActivityView, the other in Freshdesk MobiHelp.
First, with UIActivityView, when using Twitter:
The problem is that if the text goes beyond one row in the modal, the text goes transparent:
NSString *textToShare = [NSString stringWithFormat:NSLocalizedString(#"CHALLENGE-TWITTER- DEFAULT-TEXT", nil), [UserManager currentUser].displayName];
NSString *urlToShare = [NSURL URLWithString:#"http://example.com"];
NSArray *activityItems = #[textToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
Second, in Freshdesk submit a ticket:
I should also add that the Facebook modal from UIActivityView works just fine:
Would really appreciate any tips here, as I'm lost.
I think in the second sreenshot that you have attached here, there is a white screen over a red area which probably might be your label or the text area and I guess its blocking your text area. If the view was added by you, you can get the particular text area to front so that its not blocked and you can see your text. Hope this helps
Can you see a white box inside the one I highlighted? There is some view over your textarea. How are you adding your textarea? As a subview?? Can you just get log the main views subviews?? Like
NSLog (#"%#",[self.view subviews]);
And now check the view hierarchy.

NSTextFinder set search string and clear visual feedback programmatically

I have an NSTextView that uses the find bar ([textView setUsesFindBar:YES];).
I have 2 questions.
How do I clear the visual feedback from a find operation?
My problem happens when I programmatically change the content of the textView. The visual feedback for a search operation on the previous content remains after the content change. Obviously these yellow boxes do not apply to the new content so I need a way to clear them when changing the textView content.
Note: I did not implement the NSTextFinderClient protocol because I have a simple textView and the find bar just works without any other effort.
How can I send a search string to the find bar?
I found my answers, so for others here's how to do it.
First you need an instance of NSTextFinder so you can control it. We set that up in code.
textFinder = [[NSTextFinder alloc] init];
[textFinder setClient:textView];
[textFinder setFindBarContainer:[textView enclosingScrollView]];
[textView setUsesFindBar:YES];
[textView setIncrementalSearchingEnabled:YES];
First answer: To clear visual feedback I can do either of 2 things. I can just cancel the visual feedback...
[textFinder cancelFindIndicator];
Or I can alert NSTextFinder that I'm about to change my textView content...
[textFinder noteClientStringWillChange];
Second answer: There's a global NSFindPboard. You can use that to set a search.
// change the NSFindPboard NSPasteboardTypeString
NSPasteboard* pBoard = [NSPasteboard pasteboardWithName:NSFindPboard];
[pBoard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString, NSPasteboardTypeTextFinderOptions, nil] owner:nil];
[pBoard setString:#"new search" forType:NSStringPboardType];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSTextFinderCaseInsensitiveKey, [NSNumber numberWithInteger:NSTextFinderMatchingTypeContains], NSTextFinderMatchingTypeKey, nil];
[pBoard setPropertyList:options forType:NSPasteboardTypeTextFinderOptions];
// put the new search string in the find bar
[textFinder cancelFindIndicator];
[textFinder performAction:NSTextFinderActionSetSearchString];
[textFinder performAction:NSTextFinderActionShowFindInterface]; // make sure the find bar is showing
There's a problem though. The actual text field in the find bar does not get updated after that code. I found that if I toggle the first responder then I can get it to update...
[myWindow makeFirstResponder:outlineView];
[myWindow makeFirstResponder:textView];

Need to post to facebook and twitter from an ios app

I've been doing some research on how to post to fb and to twitter... I know there is a library called Sharekit and I also know I can post using the new iOS6 feature SLComposeViewController... I just need to post a text, that's all... It's not necessary that the user can edit the message...
I need some advice, what would you use?
If you're ok supporting only iOS6, SLComposeViewController is probably easiest. On the Facebook side, you lose nice little features offered via the Facebook SDK for iOS (e.g., the ability to have the Facebook post bear some indication that it came from your app, the graceful inclusion of both images and URLs, etc.).
Bottom line, if you're ok with iOS6-only and you want to keep it simple, SLComposeViewController is probably easiest and can do both Twitter and Facebook. If you want to make the most of Facebook or if you have to support iOS 5, you really have to pursue the Facebook SDK, but it takes a little more code. On the Twitter side, if you need to support iOS 5, then you need to use TWTweetComposeViewController.
Try this one:
- (IBAction)share:(id)sender
{
NSString *text = #"Your message";
UIImage *image = [UIImage imageNamed:#"yourimage.png"];
NSArray *items = [NSArray arrayWithObjects:text,image , nil];
UIActivityViewController *avc = [[avcClass alloc] initWithActivityItems:items applicationActivities:nil];
avc.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypeMail];
[self presentViewController:avc animated:YES completion:nil];
}
This should work for you. Just set the NSString and if you want an image.
No frameworks needed!