Ios 使用本机Facebook帐户(在设置中)登录Facebook而不使用web视图
我用Swift 3在iOS上创建了一个Facebook登录按钮,它可以工作,但我想知道如何使我的按钮不会打开一个新的web视图页面来请求权限。我想向用户显示: 有人知道怎么做吗Ios 使用本机Facebook帐户(在设置中)登录Facebook而不使用web视图,ios,swift3,facebook-login,Ios,Swift3,Facebook Login,我用Swift 3在iOS上创建了一个Facebook登录按钮,它可以工作,但我想知道如何使我的按钮不会打开一个新的web视图页面来请求权限。我想向用户显示: 有人知道怎么做吗 我到处搜索,但不知道如何找到它。下面的代码帮助您提供已登录设备的用户的访问令牌。这个用户档案的访问令牌可以帮助您直接登录Facebook 在AppDelegate中: func application(_ application: UIApplication, didFinishLaunchingWithOp
我到处搜索,但不知道如何找到它。下面的代码帮助您提供已登录设备的用户的访问令牌。这个用户档案的访问令牌可以帮助您直接登录Facebook 在AppDelegate中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
return FBSDKApplicationDelegate .sharedInstance() .application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
在ViewController中:
import Social
import Accounts
@IBAction func fbLoginButton(_ sender: Any)
{
var facebookAccount: ACAccount?
let accountStore = ACAccountStore()
let accountType = accountStore.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierFacebook)
let options = [ACFacebookAppIdKey: "YOUR_FB_APP_ID_KEY", ACFacebookPermissionsKey: ["public_profile","email"],ACFacebookAudienceKey:ACFacebookAudienceFriends] as [String : Any]
let facebookAccountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierFacebook)
accountStore.requestAccessToAccounts(with: facebookAccountType, options: options) { (success, error) -> Void in
if success
{
let accounts = accountStore.accounts(with: accountType)
facebookAccount = accounts?.last as? ACAccount
let accountsArray=accountStore.accounts(with: accountType) as NSArray
facebookAccount=accountsArray.lastObject as? ACAccount
print(facebookAccount!)
var dict:NSDictionary
dict=NSDictionary()
dict=facebookAccount!.dictionaryWithValues(forKeys: ["properties"]) as NSDictionary
let properties:NSDictionary=dict["properties"] as! NSDictionary
print("facebook Response is ::::",properties)
print((facebookAccount?.credential.oauthToken)!)
}
else
{
print("Access denied")
print((error?.localizedDescription)!)
}
}
}
它在图片中要求什么权限?它要求公开个人资料和好友列表。我这样做了,但我有了safari web视图,我会有与图片相同的弹出窗口:/elaborate“我做到了”是您上述评论的一部分@CusmarI创建了一个登录按钮,并要求获得我所需的权限,但与此图像类似的弹出窗口不同,safari web视图显示在经典的Facebook权限页面上。更清楚吗?我从解释中得到的是:您希望“弹出窗口”如“图像”中所示出现,而不是新的权限网页(正在出现)。对吗?你有错误域=com.apple.accounts代码=6\“(空)”吗?如果是,您是如何处理的?我发现用户必须在设置中添加帐户。我她/他没有发生这个错误。@PiotrBadura很快我就不会有这样的错误,如果以后我有这个错误的话。。我会告诉你答案。@PiotrBadura,我还建议你看看这个: