使用社交框架向Facebook添加图像

使用社交框架向Facebook添加图像

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

[CFNumber保持]:消息发送到释放实例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/

10-11 05:36