我是cocoa2d的新手。我正在尝试使用presentViewController进行Facebook分享。
这是代码:
-(void)shareFB:(NSString *)text
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:text];
[[CCDirector sharedDirector]presentViewController:controller animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"Please add Facebook account in settings menu" delegate:Nil cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
[alert show];
}
}
它发出警告:
[[CCDirector sharedDirector]presentViewController:controller animated:YES completion:nil];
那: CCDirector可能无法响应' presentviewcontroller:animated:completion:'
答案 0 :(得分:1)
好的,我得到了解决方案。
我的 CCDirector
是 NSObject
类型。我只需将其更改为 UIViewController
即可。
感谢@Blisskarthik的帮助。
答案 1 :(得分:0)
您好我已经编辑了您的代码,几乎没有更正并粘贴在下面。它工作正常
SLComposeViewController *faceBookPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[faceBookPost setInitialText:@"I am playing game"];
[faceBookPost addURL:[NSURL URLWithString:@"http://www.yourlink.com"]];
[[CCDirector sharedDirector]presentViewController:faceBookPost animated:YES completion:nil];
faceBookPost.completionHandler = ^(SLComposeViewControllerResult result)
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];
[[CCDirector sharedDirector]dismissViewControllerAnimated:YES completion:nil];
};
其他请按照此步骤进行操作
使用像这样的uinavigationcontroller在AppController中创建一个接口
@interface MyNavigationController : UINavigationController <CCDirectorDelegate>
@end
@interface AppController : NSObject <UIApplicationDelegate>
{
UIWindow *window_;
MyNavigationController *navController_;
CCDirectorIOS *director_;
}
在app controller的didFinishLaunchingWithOptions中设置导航控制器
navController_ = [[MyNavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
[director_ setDelegate:navController_];
// set the Navigation Controller as the root view controller
[window_ setRootViewController:navController_];
然后在你调用SLComposeViewController的类中出现像这样的视图
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentViewController:faceBookPost animated:YES completion:nil];
两种类型都运行良好