1

尝试为 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);

}
4

1 回答 1

2

首先检查您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];
    }
}
于 2013-08-06T05:02:28.413 回答