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