iPhone - sending an image with Sharekit to Facebook

六眼飞鱼酱① 提交于 2019-12-05 06:54:57

问题


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


回答1:


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];
            }



回答2:


UIImage *image = imageview.image
SHKItem *item;

item = [SHKItem image:image title:@"Hi"];

[NSClassFromString([NSString stringWithFormat:@"SHKFacebook"]) 
    performSelector:@selector(shareItem:) withObject:item];


来源:https://stackoverflow.com/questions/5977684/iphone-sending-an-image-with-sharekit-to-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!