sharing multiples items with sharekit on facebook - iphone

I know how to share an image lonely:
// Create a UIImage.
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
// Wrap the UIImage within the SHKItem class
SHKItem *item = [SHKItem image:image title:#"This image was sent with ShareKit!"];
// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];
and how to share a link lonely:
// Create an NSURL. This could come from anywhere in your app.
NSURL *url = [NSURL URLWithString:#"http://mobile.tutsplus.com"];
// Wrap the URL within the SHKItem Class
SHKItem *item = [SHKItem URL:url title:#"Mobiletuts!"];
// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];
but I don't know how to share both link and image in the same time. Can anyone help me on this?

You can do this one of two ways.
1. Through the URL property of SHKItem.
#property (nonatomic, retain) NSURL *URL;
Like so:
NSURL *url = [NSURL URLWithString:#"http://mobile.tutsplus.com"];
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
SHKItem *item = [SHKItem image:image title:#"This image was sent with ShareKit!"];
[item setURL:url];
2. Using the +[itemFromDictionary:] class method of SHKItem
+ (SHKItem *)itemFromDictionary:(NSDictionary *)dictionary;
Like so:
NSString *urlString = #"http://mobile.tutsplus.com";
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:urlString, #"URL", image, #"image", #"This image was sent with ShareKit!", #"title", nil];
SHKItem *item = [SHKItem itemFromDictionary:dictionary];
... and then sharing your item as desired. In your case, you can display using the -[actionSheetForItem:] method.

Related

iphone: Three20 library's MockPhoto with server images

I am trying to download images from server and display in 320 library's TTThumbsViewController. I am not able to get this working!
Following works for me when I have images locally stored:
//Create thumbnails
[ImageUtils checkAndSaveThumbnail:imageName andSize:CGSizeMake(100.0, 100.0) andLocation:NO andPrefixof:#"small"];
NSString *fullImageName = [NSString stringWithFormat:#"documents://%#",imageName];
NSString *imageSmallName = [NSString stringWithFormat:#"documents://small-%#",imageName];
NSString *caption = [tempDict objectForKey:#"Comment"];
UIImage *tempImage = [UIImage imageWithContentsOfFile:[appDelegate filePath:imageName]];
MockPhoto *tempPicture = [[MockPhoto alloc] initWithURL:fullImageName smallURL:imageSmallName size:tempImage.size caption:caption photoname:imageName];
[photoArray addObject:tempPicture];
Adding photoArray into MockPhotoSource:
self.photoSource = [[MockPhotoSource alloc]
initWithType:MockPhotoSourceNormal
title:#"Photos"
photos:photoArray
photos2:nil
];
[photoArray release];
...But when I give download location like following it doesn't work! Doesn't show me thumbnails and neither large pics!
NSString *url = [delegate downloadImageUrl];
MockPhoto *tempPicture = [[MockPhoto alloc] initWithURL:url smallURL:url size:tempImage.size caption:caption photoname:imageName];
[photoArray addObject:tempPicture];
I have been using same same URL with AsyncImage and it downloads image and show in ImageView fine!
NSURL *url = [NSURL URLWithString:[delegate downloadImageUrl]];
UIImageView *profileimage = [[UIImageView alloc] init];
AsyncImageView* asyncImage = [[[AsyncImageView alloc] initWithFrame:CGRectMake(0, 10, 60, 60)] autorelease];
asyncImage.imageName = [[users objectAtIndex:indexPath.row] objectForKey:#"Key"];
[asyncImage loadImageFromURL:url];
[profileimage addSubview:asyncImage];
Could you please let me know what's wrong am I doing with MockPhoto?
Thanks.

uploading image in facebook

While uploading image in facebook wall, image is not at all getting on the wall.
I tried:
[[FBRequest requestWithDelegate:self] call:#"facebook.Users.setStatus" params:
params dataParam:UIImagePNGRepresentation(img)];
to no avail.
You can do it using Sharekit....
Try this code...
-(void)shareOnFacebook {
//take screenshot
UIImage *image = "Your image";
//for debug purpose the image can be stored to photo album
//UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
SHKItem *fbItem = [SHKItem image:image title:#"Check out my Image!"];
[SHKFacebook shareItem:fbItem];
}
Using sharekit you can try following code:
-(IBAction)btnSendToFacebookPressed:(id)sender
{
NSString *var = [[NSUserDefaults standardUserDefaults] valueForKey:#"IMAGE_INDEX"];//This line may not be useful to you...
NSString *imageIndex = [[NSBundle mainBundle] pathForResource:var ofType:#"jpg"];
SHKItem *item = [SHKItem image:[UIImage imageWithContentsOfFile:imageIndex] title:#"Your Title"];
[NSClassFromString(#"SHKFacebook") performSelector:#selector(shareItem:) withObject:item];
}
Try to do it using Sharekit.
Add Sharekit framework to your project.
Change the setting from shkconfig.h file.
pass the key which you can generate from facebook->developer->apps->create new app->generate keys pass it to shkconfig.h
-(IBAction) tryItOnFb:(id)sender
{
SHKItem *item = [SHKItem image:[UIImage imageNamed:#"YES.png"]title:#"FB Test"];
[NSClassFromString(#"SHKFacebook") performSelector:#selector(shareItem:) withObject:item];
}
Images will get into your photo Album and information about it on the wall.
NSMutableDictionary *params =[NSMutableDictionary dictionaryWithObjectsAndKeys:#"Testmessage", #"message", imageData, #"picture", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

iPhone - sending an image with Sharekit to Facebook

I'm using ShareKit to send a comment and an image to facebook. Everything's working fine except that if no user image exists (in the coredata/sqlite db) I would like to send a default image instead. Here's my code, with example.png being the default image and initWithData:entity.userImage being the image the user added with their iPhone. Maybe there's something wrong with my if else statement.
-(IBAction) fbButton {
SHKItem *item;
NSURL *url = [NSURL URLWithString:#"http://itunes.apple.com/ae/artist/XXX"];
item = [SHKItem URL:url title:[NSString stringWithFormat:#"Take a look at %#", entity.name]];
[SHKFacebook shareItem:item];
if (entity.image = nil) {
UIImage *image = [UIImage imageNamed:#"example.png"];
SHKItem *item2 = [SHKItem image:image title:nil];
[SHKFacebook shareItem:item2];
} else {
UIImage *image = [[[UIImage alloc] initWithData:entity.userImage] autorelease];
SHKItem *item2 = [SHKItem image:image title:nil];
[SHKFacebook shareItem:item2];
}
[SHK flushOfflineQueue];
}
The problem is that if there is no image in the database Sharekit gives a UIAlert saying that a file must be present in the upload. I was trying to get around this by always providing a default image in case the record in the database doesn't have one.
as always, thanks for any help
USE if (entity.image == nil)
instead this if (entity.image = nil) {
if (imageView.image == nil) {
imageView.image = [UIImage imageNamed:#"fbicon.png"];
SHKItem *item2 = [SHKItem image:imageView.image title:#"Hi"];
[SHKFacebook shareItem:item2];
}
else {
SHKItem *item1 = [SHKItem image:imageView.image title:#"Hi"];
[SHKFacebook shareItem:item1];
}
UIImage *image = imageview.image
SHKItem *item;
item = [SHKItem image:image title:#"Hi"];
[NSClassFromString([NSString stringWithFormat:#"SHKFacebook"])
performSelector:#selector(shareItem:) withObject:item];

iphone multiple image url loading in tableview

I want to display or load multiple images from a server and load it in tableview or image view ...if a single url with image is coming then imageview or tableview loads the image, but more that one image is coming then it did not load the multiple images,
my code is
NSString *urlVal = #"http://at.azinova.info/green4care/iphone/viewImage.php?id=";
NSString *urlVal1 = [urlVal stringByAppendingString:selectedCountryw];
NSURL *url1 = [NSURL URLWithString:urlVal1];
NSString *resultString = [NSString stringWithContentsOfURL:url1 encoding:NSUTF8StringEncoding error:nil];
resultString=[resultString stringByReplacingOccurrencesOfString:#"\n" withString:#""];
NSArray *profileedit = [resultString componentsSeparatedByString:#"#***#"];
lbl.text = resultString;
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:lbl.text]]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:#selector(tick) userInfo:nil repeats:YES];
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"ALERT" message:resultString delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert1 show];
[alert1 release];
selectedCountryw is just an id
resultstring is the url from the server ,it may be one image or more than one image
You need to create a function that takes a parameter for selectedCountryw
The function returns a UIImage
Call the function every time you need an image, the function makes the request and creates the image
Set the image in the UITableView
Once you've gotten this far, let us know where you are and we'll jump right in and help.
-(UIImage*)getImage:(NSString*)country
{
NSString *urlString = [NSString stringWithFormat: #"http://at.azinova.info/green4care/iphone/viewImage.php?id=%#", country];
NSURL *url = [NSURL URLWithString: urlString];
NSString *strImage = [NSString stringWithContentsOfURL:url];
UIImage *image = [[UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:strImage]]] retain];
return image;
}
Better yet..Do a search on SO or Google for Lazy TableView Loading. That'll get you started.
Edited to provide additional information:
I'll leave it up to you to optimize.
Better option is the SDwebimage which is very simple to use and is the best library to do this kind of stuff here's the link to that

how to load image in background in UITableCell in iphone application

I have develop an RSS application. in My table cell I am displaying images which i retrive from imge link in RSS feed and Title.
Images are loaded successfully but the problem is that it hang my application.
as there any way to load image in background.
my current code is.
int blogEntryIndex1 = [indexPath indexAtPosition: [indexPath length] -1];
imgstring=[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: #"image"];
NSURL *url = [NSURL URLWithString:imgstring];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
cell.imageView.image=[img autorelease];
any idea please, Thanks in advance...
Repost... You should also look at lazy table loading via Apple's sample code http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html
Update another example here: http://www.markj.net/iphone-asynchronous-table-image/
Well guys i have done it the code is...
- (void) loadImage:(id)object {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Get the data to pass in
NSDictionary *dict = (NSDictionary *)object;
// Get the cell and the image string
NSString *imgstring = [dict objectForKey:#"imgstring"];
MyfirstCell *cell = [dict objectForKey:#"cell"];
NSURL *url = [NSURL URLWithString:imgstring];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
cell.myimnage.image = img;
[pool release];
}
I will call the above method in my code...
if(searching) {
//cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
int blogEntryIndex = [indexPath indexAtPosition: [indexPath length] -1];
// Tell your code to load the image for a cell in the background
NSString *imgstring =[[blogEntries objectAtIndex: blogEntryIndex] objectForKey: #"image"];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:cell, #"cell", imgstring, #"imgstring", nil];
[self performSelectorInBackground:#selector(loadImage:) withObject:dict];
//background code end here..
Thanks to deanWombourne who has given me this code....
And take a look to this document also from Apple.
http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html
Most the time I use NSURLConnection to download things.
You can use this way:
((UIImageView *)cell.backgroundView).image = bgImage;
((UIImageView *)cell.selectedBackgroundView).image = bgImage;