嘿那里我的应用程序几乎准备好发布,但我想添加Facebook分享按钮。事情是我不知道场景和viewcontroler之间的沟通是如何工作的。我做了我的研究,但只发现在OBJ-C代码这样一个swift spritekit Facebook的分享按钮
- (void)lkFaceBookShare {
NSString *serviceType = SLServiceTypeFacebook;
if (![SLComposeViewController isAvailableForServiceType:serviceType])
{
[self showUnavailableAlertForServiceType:serviceType];
}
else
{
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:serviceType];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.5f);
[self.view drawViewHierarchyInRect:rect afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[composeViewController addImage:viewImage];
NSString *initalTextString = [NSString stringWithFormat:@"Let's join together in the form of underground catch word go along with me!! Link: https://itunes.apple.com/us/app/uoi-hinh-bat-chu-gioi-duoi/id907330926?ls=1&mt=8"];
[composeViewController setInitialText:initalTextString];
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController:composeViewController animated:YES completion:nil];
}
}
- (void)showUnavailableAlertForServiceType:(NSString *)serviceType
{
NSString *serviceName = @"";
if (serviceType == SLServiceTypeFacebook)
{
serviceName = @"Facebook";
}
else if (serviceType == SLServiceTypeSinaWeibo)
{
serviceName = @"Sina Weibo";
}
else if (serviceType == SLServiceTypeTwitter)
{
serviceName = @"Twitter";
}
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Account"
message:[NSString stringWithFormat:@"Please go to the device settings and add a %@ account in order to share through that service", serviceName]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alertView show];
}
我的经验和知识太低端口这也太迅速,所以我需要一些帮助,这d:
感谢
[夫特和在同一项目中的Objective-C](https://developer.apple。 com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html),他们很容易在Swift中使用现有的Objective-C类。 – chuckus 2014-08-31 19:57:02