iPhone - sending an image with Sharekit to Facebook
I'm using ShareK开发者_JAVA技巧it 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];
精彩评论