-(IBAction)post:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
mySocialComposer = [[SLComposeViewController alloc]init];
mySocialComposer = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySocialComposer setInitialText:@"Hello World"];
[mySocialComposer addImage:[IIImage imageNamed:@"myImage.png"]];
[self presentViewController:mySocialComposer animated:YES completion:nil];
}
[mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){
NSString *outout = [[NSString alloc] init];
switch (result) {
case SLComposeViewControllerResultCancelled:
outout = @"Post Cancled";
break;
case SLComposeViewControllerResultDone:
outout = @"Post Done";
default:
break;
}
UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"FaceBook"
message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[myalertView show];
}];
}我想在facebook上发布一些没有图片的东西,但当我发布图片时,它没有工作,并给出了一个错误警报。但是当我在我的帖子中添加一张图片时,它将会成功发布。我只想在没有图片的情况下发布。有没有办法做到这一点。?
发布于 2012-10-04 20:59:33
尝试去掉SLComposeViewController的alloc和init行,因为您正在使用类方法composeViewControllerForServiceType重新创建,它返回一个自动释放的对象.....(除非在ARC下)
所以它看起来像这样:
-(IBAction)post:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
mySocialComposer = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySocialComposer setInitialText:@"Hello World"];
[self presentViewController:mySocialComposer animated:YES completion:nil];
}
[mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){
NSString *outout = [[NSString alloc] init];
switch (result) {
case SLComposeViewControllerResultCancelled:
outout = @"Post Cancled";
break;
case SLComposeViewControllerResultDone:
outout = @"Post Done";
default:
break;
}
UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"FaceBook"
message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[myalertView show];
}];否则,代码在我看来没问题,除非您在其他地方对这个mySocialComposer实例执行某些操作
https://stackoverflow.com/questions/12727079
复制相似问题