iphone - 使用社交框架将图像添加到 Facebook

标签 iphone ios facebook afnetworking

尝试为 SLComposeViewController 上传所选照片时出现此错误:

[CFNumber retain]: 发送到释放实例 0xa1c2c00 的消息

项目构建没有错误或警告。 这是代码:

- (IBAction)test:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        API* api = [API sharedInstance];
        NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];        
        NSData *data = [NSData dataWithContentsOfURL:imageURL];
        UIImage *img = [[UIImage alloc] initWithData:data];

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [controller addURL:[NSURL URLWithString:@"http://www.appcoda.com"]];
        [controller addImage:img];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

有什么想法吗?谢谢

编辑: 这是 viewDidLoad:

-(void)viewDidLoad {

    API* api = [API sharedInstance];
    //load the caption of the selected photo
    [api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto",label.text,@"weddingID", nil] onCompletion:^(NSDictionary *json) {
        //show the text in the label
        NSArray* list = [json objectForKey:@"result"];
        NSDictionary* photo = [list objectAtIndex:0];
        lblTitle.text = [photo objectForKey:@"title"];
    }];
    //load the big size photo
    NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];
    [photoView setImageWithURL: imageURL];
           NSLog(@"image url :%@",imageURL);

}

最佳答案

首先检查您的 imageURL 是否正确, 使用 ARC 在 SLComposeViewController 中没有问题。

或者你试试你的photoView是不是imageview

- (IBAction)test:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [controller addURL:[NSURL URLWithString:@"http://www.appcoda.com"]];
        [controller addImage: photoView.image];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

关于iphone - 使用社交框架将图像添加到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18068346/

相关文章:

iOS开发证书发行

iPhone视频捕捉(最佳方法)

javascript - IFrame 中的 FB.init 导致 IE8 无限循环,并在一段时间后出现 Flash 错误消息

android - iOS 到 Android 的 Json-RPC 方法

ios - UITableViewCell 在用户触摸或点击 Cell 时动画调整大小

objective-c - iOS – 回调的设计决策(使用 NSNotifications 或 AppDelegate)

javascript - FB.api ('/photos' )在 Facebook 应用程序外部工作,但不在应用程序内部工作

iphone - retain setter 是如何用@synthesize 实现的?

ios - 使用 sectionForSectionIndexTitle 在 UITableView 中快速滚动

ios - UITableView里面UITableViewCell高度问题