尝试为 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/