How to add different text to UIActivityViewController objects - iphone

I have implemented a UIActivityViewController, for sharing some information. In this case I have a question: Is it possible to make a different text between the facebook sharing/twitter sharing/ or mail sharing? That the text which is set is different from the others...
A good UIActivityViewController tutorial would be very useful.
My code at the time is, for displaying text and image:
NSString *text = #"Lime Cat";
UIImage *image = [UIImage imageNamed:#"MyApp Icon 512x512.png"];
NSArray *items = [NSArray arrayWithObjects:text,image , nil];
But how can I manage it that the NSString is just for the mail, and make a seperate NSString for the facebook share option?
Any suggestions?
Thanks.

you can go to the link bellow, there is a tutorial that can help you :
https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/

You can have your class conform to the UIActivityItemSource protocol and implement activityViewController:itemForActivityType:. The activityType will be FB, Twitter, Messages app, etc, so you can do a switch on it and return a different object based on the activity.

-(void)ShareImageandText:(UIButton *)sender
{
NSString *texttoshare =#"http://qrs.ly/l851gh4";
UIImage *image = [UIImage imageNamed:#"default"];
NSString *noteStr = [NSString stringWithFormat:#"Please follow this link below to install the Freedom.desi application on your IPhone. %#",texttoshare];
NSURL *url = [NSURL URLWithString:texttoshare];
NSArray *activityItems = #[noteStr,image];
NSLog(#"this %#",activityItems);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr,image] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
//if iPad
else {
// Change Rect to position Popover
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr, url] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

Related

iOS UIActivity View Controller: Add To Reading List Button?

Is there a service to be able to add a URL to the iOS Safari's Reading List from in a app.
I would have a url to add and a UIWebView,but I have researched and I can't find anything.
Here is my working UIActivityViewController.
-(IBAction)actionButton:(id)sender;{
NSLog(#"shareButton pressed");
NSURL *URL = [NSURL URLWithString:self.feedItem[#"url"]];//this is your text string
NSArray *activityItems = #[URL];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
TUSafariActivity *TUSafari = [[TUSafariActivity alloc] init];
MLCruxActivity *cruxActivity = [[MLCruxActivity alloc] init];
NSArray *applicationActivities = [NSArray arrayWithObjects:TUSafari,chromeActivity,cruxActivity, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities: applicationActivities];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
UPDATE: iOS 7 added an API to accomplish this:
#import <SafariServices/SafariServices.h>
SSReadingList * readList = [SSReadingList defaultReadingList];
NSError * error = [NSError new];
BOOL status =[readList addReadingListItemWithURL:[NSURL URLWithString:urlToAdd] title:titleToAdd previewText:previewText error:&error];
if(status)
{
NSLog(#"Added URL");
}
else NSLog(#"Error");
Currently (iOS SDK 6.1) there is no way to add a item to the Reading List from a third party app.
There are some alternatives like Readability you could use.

Can I use UIActivityViewController to share on Facebook ?

I am trying to use UIActivityViewController to share on facebook.
When I am using the
UIImage* image = [UIImage imageNamed:#"image1.png"];
NSArray* dataToShare = #[#"test",image];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
I can't see the "Share on Facebook" icon although I didn't exclude "UIActivityTypePostToFacebook". isn't there a predefined UIActivity for facebook ?
Thanks
you must be logged in your iphone settings:
Settings -> facebook
Try this: if you want only facebook icon to share:
-(IBAction)shareButtonPressed:(id)sender { NSLog(#"shareButton pressed");
NSString *texttoshare = _txt;
UIImage *imagetoshare = _img;
NSArray *activityItems = #[texttoshare, imagetoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
//in the list of excluded activity type insert any other kind of activitytypes you want to exclude

Photo Posting in Twitter in iOS5

I am new one to twitter integration in iOS5.
I need to post photos in twitter coming from services.
I have searched many and also practiced sample tutorials on this.
I am getting only photo URL. I need to post photo.
Can anyone help me regarding this?
Thanks in advance.
First you need to save the images and then you can post saved image to twitter
self.shareImg.image = [UIImage imageNamed:#"Your Saved image"];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
NSString *str = [NSString stringWithFormat:#"I created this photo http://%#", iTune];
// Optional: set an image, url and initial text
[twitter addImage:self.shareImg.image];
[twitter setInitialText:[NSString stringWithFormat:#"I created this photo using USC Project Trojan App:http://uslofphoto.com. Download http://%#", iTune]];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}

Would like to keep cache data when changing to other UIView

i would love to have some help or any keyword that i can use to search for.
My problem is I have one UIView, called "UpdateViewController.xib" that load 20 small images and text below those images by programmatically.
and when user click on those images it will change to next view that i created by IB, called "imageSumVuew.xib" and i have a button to link back to UpdateViewController.
#import "imageSumView.h" // next view that i wanna load//
// the transition to next view
imageSumView *nextView = [[imageSumView alloc]init];
self.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:nextView animated:YES completion:NULL];
[nextView release];
in the nextView i have code similar to this which come back to this view
#import "UpdateViewController.h" // old that i wanna load back//
// the transition to old view
UpdateViewController *oldView = [[UpdateViewController alloc]init];
self.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:oldView animated:YES completion:NULL];
[oldView release];
the problem is when it did load back to UpdateViewController, all my images and text has to reload all over again.
The question is " how can i keep cache of the UpdateViewController view?", i don't want user to reload images all over again because they have to go back and forth between this page for several times to see which image that they wanna pick.
Think of Instragram that you see list of your friends images then you wanna check your first friends's photo and after that you come back to overall image of your friends without loading and choose second friends.
Store image data with unique id to temporary directory once it is downloaded for the first time. For the next time check for that user id's image in your directory, if it is there then load image from there. For example :
#define TMP NSTemporaryDirectory()
NSString *filename=[NSMutableString stringWithFormat:#"userimage_%#",userId];
NSString *uniquePath = [TMP stringByAppendingPathComponent:filename];
NSData *dataImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]
UIImage *image = [[UIImage alloc] initWithData: dataImage];
[UIImageJPEGRepresentation(image, 1.0f) writeToFile: uniquePath atomically: YES];
[image release];
To get ur image you can do something like below:
- (NSData *) getImage: (NSString *)userId
{
NSString *filename=[NSMutableString stringWithFormat:#"userimage_%#,userId];
NSString *uniquePath = [TMP stringByAppendingPathComponent: filename];
if([[NSFileManager defaultManager] fileExistsAtPath: uniquePath])
{
return [[NSData alloc] initWithContentsOfFile:uniquePath];
}
return nil;
}

iPhone SMS Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilĂ  !