Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBAction func vkAutorize(_ sender: UIButton) {
- VKSdk.authorize(["photos"])
- }
- let SCOPE = ["wall", "photos", "email", "friends"] //то к чему нужно получить доступ см. VKPermissions.h
- override func viewDidLoad() {
- //Initialize SDK with your APP_ID for any delegate.
- VKSdk.initialize(withAppId: VK_ID).register(self)
- ...
- }
- func vkButtonPressed(){
- self.initWorkingBlock { (finished) -> Void in
- // пользователь авторизован
- }
- }
- func initWorkingBlock (_ completion: ((Bool) -> Void)!){
- VKSdk.wakeUpSession(SCOPE as [AnyObject], complete: { (state, error) -> Void in
- if (state == VKAuthorizationState.authorized) {
- print("Authorized and ready to go")
- } else if ((error) != nil) {
- print("Some error happend, but you may try later: (error)")
- } else {
- VKSdk.authorize(self.SCOPE as [AnyObject])
- }
- completion(true)
- self.vkGetUser()
- print("completion VKSdk.wakeUpSession")
- })
- }
- func vkGetUser(){
- if VKSdk.isLoggedIn() {
- let userId = VKSdk.accessToken().userId
- if (userId != nil) {
- VKApi.users().get([VK_API_FIELDS:"first_name, last_name, id, photo_100, sex, bdate, country",
- VK_API_USER_ID: userId]).execute(resultBlock: { (response) -> Void in
- let user = response?.parsedModel.fields[0] as! VKUser
- print("Пользователь ВК: (user.fields)")
- }, errorBlock: { (error) -> Void in
- print("Error2: (error)")
- })
- }
- }
- }
Add Comment
Please, Sign In to add comment