Ios Facebook好友邀请的Swift 2.0代码
我一直在为iOS应用程序的Facebook好友邀请寻找等效的Swift代码示例。但是我找不到他们 我知道Facebook页面上有Objective-C版本。然而,因为我是从斯威夫特开始的,所以我发现很难翻译 有人能给我指点消息来源吗?谢谢。代码正在运行: -在viewDidLoad中:Ios Facebook好友邀请的Swift 2.0代码,ios,facebook,swift,facebook-graph-api,swift2,Ios,Facebook,Swift,Facebook Graph Api,Swift2,我一直在为iOS应用程序的Facebook好友邀请寻找等效的Swift代码示例。但是我找不到他们 我知道Facebook页面上有Objective-C版本。然而,因为我是从斯威夫特开始的,所以我发现很难翻译 有人能给我指点消息来源吗?谢谢。代码正在运行: -在viewDidLoad中: let content = FBSDKAppInviteContent() content.appLinkURL = NSURL(string: "https://test/myapplink") content
let content = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "https://test/myapplink")
content.appInvitePreviewImageURL = NSURL(string: "https://test/myapplink")
// Old Way, now depreciated :
//FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self)
//New way :
FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self)
// Do any additional setup after loading the view.
-在viewController中,要符合协议委托,请执行以下操作:
extension InviteFriendsViewController: FBSDKAppInviteDialogDelegate{
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) {
//TODO
}
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) {
//TODO
}
}
Benobab解决方案是完美的,我只想在我尝试运行的案例中添加这一点
FBSDKAppInviteDialog.showFromViewController在VIEW上的效果似乎更好。Swift 3.0中的Facebook好友邀请 首先,导入FBSDKCoreKit,FBSDKShareKit并添加代理fbsdkapinvitedialogdelegate。然后,单击“邀请朋友”按钮,添加以下代码:
let inviteDialog:FBSDKAppInviteDialog = FBSDKAppInviteDialog()
if(inviteDialog.canShow()){
let appLinkUrl:NSURL = NSURL(string: "http://yourwebpage.com")!
let previewImageUrl:NSURL = NSURL(string: "http://yourwebpage.com/preview-image.png")!
let inviteContent:FBSDKAppInviteContent = FBSDKAppInviteContent()
inviteContent.appLinkURL = appLinkUrl as URL!
inviteContent.appInvitePreviewImageURL = previewImageUrl as URL!
inviteDialog.content = inviteContent
inviteDialog.delegate = self
inviteDialog.show()
}
然后,添加以下方法的FBSDKAppInviteDialogDelegate:
func appInviteDialog (_ appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [AnyHashable : Any]!) {
let resultObject = NSDictionary(dictionary: results)
if let didCancel = resultObject.value(forKey: "completionGesture")
{
if (didCancel as AnyObject).caseInsensitiveCompare("Cancel") == ComparisonResult.orderedSame
{
print("User Canceled invitation dialog")
}
}
}
func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: Error!) {
print("Error tool place in appInviteDialog \(error)")
}
//FBSDKAppInviteDialog.showWithContent(content,delegate:self)折旧//使用showFromViewController而不是旧的。
您可以更新代码。有没有办法将SKView用作UIViewController,以便我可以在SpriteKit中使用它:FBSDKAppInviteDialog.showFromViewController(self,withContent,delegate:self)你知道为什么Xcode在我想添加FBSDKAppInviteDialogDelegate时会这样做吗:“不能符合协议”@Nour添加两种委托方法,就像我在回答中添加的那样。谢谢你,我不知道在哪里添加它们,但最后它起作用了这应该是Swift 3的答案!