iOS 7 UIActivityViewController Email Attachments - email

I have reviewed a bunch of posts here, numerous online tutorials/sample code and I'm stumped. In my app I have no problem displaying the UIActivityController natively provided by iOS7 with the sharing options appropriate to my app (AirDrop and mail).
The specific problem I'm having is getting my saved document attached to the email message when the user selects the option to share via mail. The message body is being set to the text, but the attachment is MIA. The relevant code is:
// Generate the XML file to be shared for the currently displayed record...
NSURL *url = [self createShareFile];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[#"Data shared from my app.", url] applicationActivities:nil];
// Filter out the sharing methods we're not interested in....
controller.excludedActivityTypes = #[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
// Now display the sharing view controller.
[self presentViewController:controller animated:YES completion:nil];
What am I missing? My file is being properly created, the contents is correct and the NSURL object contains the proper path to the file.
Thanks!

Problem solved.....
The code posted in my original post is 100% accurate. The issue ended up being in the way I was constructing the NSURL being returned in my createShareFile method:
Incorrect (original way):
return [NSURL URLWithString:[docFile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Correct way:
return [NSURL fileURLWithPath:docFile];
As soon as I fixed that, it started working, even with my custom file type.

I had a similar problem where the mail app was the only one I couldn't add a pdf to. Here is my code in Swift as well as handling iPad popup.
var filesToShare = [Any]()
filesToShare.append(self.myUrl)
let activityViewController = UIActivityViewController(activityItems: filesToShare as [Any], applicationActivities: nil)
present(activityViewController, animated: true)
// for iPad -> where to present on screen
if let popOver = activityViewController.popoverPresentationController {
//action button being my top left icon
popOver.barButtonItem = self.actionButton
}
My issue was as well handling the URL differently

Related

UIActivityView Controller add "Print"

I have added an 'UIActivityViewController' this works very well but the "Print" button is not shown.
How can I add the "Print" Button? I will print out the actual PDF file which is shown in an 'UIWebView' named "background".
Perfectly: That not the URL will be sent by email oder post on twitter/facebook special the pdf as Picture
here is my code:
NSArray *items = #[self.background.request.URL.absoluteString];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
};
activityViewController.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard];
EDIT:
How Can I print out the actual PDF shown in UIWebView as Image?
And how can I add the Printer Button?
Try to explicitly include a UIActivity of type UIActivityTypePrint in your applicationActivities when initialising the activity view controller.

Initial text and paperclipped-URL for action in UIActivityViewController & UIActivityItemSource?

Finally been making it through Apple's (rather dismal) documentation on the new UIActivityViewController class and the UIActivityItemSource protocol, and I'm trying to send different data sets to different actions called from the activity view. To simplify things, I'm looking at two things.
A Facebook posting action, which should say "Check this out!" and also attach a URL to the post (with that cute little paperclip).
A Twitter posting action, which should say "Check this out, with #hashtag!" and also attach that same URL (with the same paperclip).
Here's the code I've got implemented right now.
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return #"Check this out!";
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return #"Check this out, with #hashtag!";
}
return #"";
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return #"";
}
And then when I set up this activity view controller (it's in the same class), this is what I do.
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:#[self] applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
My dilemma is how to attach that NSURL object. It's relatively easy when calling the iOS 6 SL-class posting modals; you just call the individual methods to attach a URL or an image. How would I go about doing this here?
I'll note that instead of returning NSString objects from -activityViewController:itemForActivityType, if I return just NSURL objects, they show up with that paperclip, with no body text in the post. If I return an array of those two items, nothing shows up at all.
Evidently it was as simple as this: passing in an array to the first argument of UIActivityViewController's init call, with each item in the array handling a different data type that will end up in the compose screen. self handles the text, and the second object (the NSURL) attaches the URL.
NSArray *items = #[self, [NSURL URLWithString:#"http://this-is-a-url.com"]];
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
Really wish there was more on this, but here it is.

How to use the existed sample application to integrate google credentials in the iphone app

From the below link I download the .zip file it contains some example. In that I played the OAuthSampleTouch application.
http://code.google.com/p/gdata-objectivec-client/downloads/list
This is the file I downloaded :
gdata-objectivec-client-1.11.0.zip
I gone through it but I am getting confusion how to pass input that is email and password and then how to connect through google form my iphone app.
Newly edited code:
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please refer http://code.google.com/p/gdata-objectivec-client/downloads/list in that OAuthSampleTouch application.
- (void)signInToGoogle
{
[self signOut];
NSString *keychainAppServiceName = nil;
if ([self shouldSaveInKeychain])
{
keychainAppServiceName = kAppServiceName;
}
// For GData applications, the scope is available as
// NSString *scope = [[service class] authorizationScope];
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GDataOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GDataOAuthViewControllerTouch *viewController = [[[GDataOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainAppServiceName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please check it. What is the scope and from where I need to pass credentials. If I run this I am getting the log as Authentication error:
Please help me, I am trying it from three days.
Any help is much appreciated.
Thank you,
Madan Mohan.
Search for this method
(GDataServiceGoogleContact *)contactService
Here you will be giving username and password for google account..

TTStyledTextLabel

I'm trying to get this control to work with a hypertext link with not much success. I have looked at TTCalaog and tried to replecate but does not work.
I have this working as far as displaying the hypertext link but it does not fire.
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(5, 0, 315, 175)] autorelease];
NSString* labelText = #"This should work";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[self.view addSubview:label];
I thing I am missing the point here perhaps with the placement of the google url? I have seen a post on this forum that makes use of custom-uri://some/url that is then set up in TTURLMap and TTNavigator, but I need to open a url from the hypertext in a webview so I need the url to run a method in my class that creates my webview controller etc.
I have tried to cusomise TTURLMap to work without a TTNavigator but completely pickled?
Any help gratefullt appreciated ;-)
Thanks
I've just found myself a solution to catch the clicked URL on a TTStyledTextLabel. I hope this could help in your case too.
This's what I have done.
1. Create TTNavigator
TTNavigator *navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeNone;
navigator.delegate = self;
2. Create TTNavigatorDelegate
As you assigned self as delegate of the navigator object. Therefore, please remember to add protocol in the header file .h before you continue.
In the implementation, create this method
- (BOOL) navigator:(TTBaseNavigator *)navigator shouldOpenURL:(NSURL *)URL {
// Now you can catch the clicked URL, and can do whatever with it
// For Example: In my case, I take the query of the URL
// If no query is available, let the app open the URL in Safari
// If there's query, get its value and process within the app
NSString *query = URL.query;
if (query == nil) {
return YES;
} else {
// process the query
}
}
I hope this helps! Please vote for me if this helps to solve your issue!
Best Regards,
Thang

How to add hyperlink in iPhone app?

In my iPhone app, I require to show the hyperlink to a website
How can I add hyperlink for a website in iPhone programming?.
Actually i want to pass the link from my app onto facebook using facebook API.
So how should I format my text such that it works as hyperlink on facebook?
I am still stuck with this issue.
It depends on where you want to put this link.
If it is in a UITextView, you just have to enable it.
textView.text = #"Some text with link in it : http://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;
More info on iOS reference library.
Or, if you want to open Safari programmatically:
NSURL *url = [ [ NSURL alloc ] initWithString: #"http://stackoverflow.com" ];
[[UIApplication sharedApplication] openURL:url];
[url release];
If you want to share on Facebook, you need to tell Safari to open a URL which will display a Facebook page that allows the user to share. Here is an example:
NSString *urlString = #"http://stackoverflow.com";
//The url you want to share
NSString *title = "The Title of the Page";
//The title you want to be displayed on Facebook
NSString *shareUrlString = [NSString stringWithFormat:#"http://www.facebook.com/sharer.php?u=%#&t=%#", urlString , title];
//Create the URL string which will tell Facebook you want to share that specific page
NSURL *url = [ [ NSURL alloc ] initWithString:shareUrlString ];
//Create the URL object
[[UIApplication sharedApplication] openURL:url];
//Launch Safari with the URL you created
[url release];
//Release the object if you don't need it
Drag a textView in your View Controller and select it's attribute inspector:
Set your text as "My website: www.mywebsitelink.com" and make sure
that text type should be plain.
Tick your behavior as Selectable and not Editable.
Tick on detection as Links.
Run your project. You can see link in View Controller. Click on link, that will take you to safari and open a new tab on it.
Parth
Can you mention where you need to insert hyperlink ,this is my way to insert link in iPhone app:
NSMutableString *err=[[NSMutableString alloc] init];
[err appendString:#"<html><body style=\"background-color:black\" ><font size=3 face=\"helvetica\" color=\"white\" align=\"center\"><H3>Login Error</H3><p> "];
[err appendString:#"Please try again. If you forgot your password, you can retrieve it at<font color=\"red\"> ENTER LINK TEXT</font>.</font></p></body></html>"];
}
My favorite library for sharing would be ShareKit. It's really easy to setup in your app, and will allow people to share via Facebook, and other services too. It's customizable too, so you can skin it, change colors, and control which services you want users to share with.
Check out, http://www.getsharekit.com/
Once you add it to your app you can integrate it very easily by creating a button
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(share)];
//add the button to a navigation bar or tool bar.
and then creating the share method in your controller.
- (void)share
{
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:#"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:#"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromToolbar:navigationController.toolbar];
}
extension NSAttributedString{
add a new swift file for adding link in ios
static func makeHyperlink(for path: String, in string: String, as substring: String) -> NSAttributedString {
let nsString = NSString(string: string)
let substringRange = nsString.range(of: substring)
let attributedString = NSMutableAttributedString(string: string)
attributedString.addAttribute(.link, value: path, range: substringRange)
return attributedString
}
}
And then use this makehyperlink function in your text view function.
let attributedString = NSAttributedString.makeHyperlink(for: link, in: paragraph, as: "text to use for link")