I connected the library itself through pods. I also connected vk_ios_sdk.framework to General -> Linked Frameworks and Libraries. Then in my login controller I imported vksdk:

import VK_ios_sdk 

Added delegates:

 class LoginVC: UIViewController, VKSdkDelegate, VKSdkUIDelegate 

Then I registered the application id, which I took from the settings on VC. And also prescribed delegates:

  let VK_APP_ID = "--" // Идентификатор Вашего VK-приложения override func viewDidLoad() { super.viewDidLoad() let sdkInstance = VKSdk.initializeWithAppId(self.VK_APP_ID) sdkInstance.registerDelegate(self); sdkInstance.uiDelegate = self; } 

Then I implemented all the methods:

  // Методы протоколов VK SDK func vkSdkAccessAuthorizationFinishedWithResult(result:VKAuthorizationResult?) -> Void { print("vkSdkAccessAuthorizationFinishedWithResult = \(result)") } func vkSdkUserAuthorizationFailed() -> Void { print("vkSdkUserAuthorizationFailed") } func vkSdkAccessTokenUpdated(newToken:VKAccessToken?, oldToken:VKAccessToken?) -> Void { print("vkSdkAccessTokenUpdated = \(newToken)") } func vkSdkAuthorizationStateUpdatedWithResult(result:VKAuthorizationResult) -> Void { print("vkSdkAuthorizationStateUpdatedWithResult = \(result)") } func vkSdkShouldPresentViewController(controller:UIViewController?) -> Void { print("vkSdkShouldPresentViewController") } func vkSdkNeedCaptchaEnter(captchaError:VKError?) -> Void { } 

Print methods I put in purely to keep track of what is happening. And I call the login itself when I press the button:

  @IBAction func loginVKbtn(sender: UIButton) { let SCOPE = [VK_PER_EMAIL, VK_PER_NOHTTPS] VKSdk.initializeWithAppId(VK_APP_ID) VKSdk.authorize(SCOPE) } 

I also added the keys to the plist file (for the domains I already had my key there, I just added the key for VC there):

  <key>LSApplicationQueriesSchemes</key> <array> <string>vk</string> <string>vk-share</string> <string>vkauthorize</string> </array> <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>frienddime.com</key> <dict> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> <key>vk.com</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> </dict> </dict> 

I also read somewhere that you need to add a function to appDelegate, but there was a swift 3, I tried to convert to swift 2.3, but I don’t know if it’s right, anyway it’s not any better. Here is the code I added to appDelegate (in this class I also imported VK_ios_sdk):

  //MARK: - VKSdk setup //iOS 9 workflow func application(app: UIApplication, url: NSURL, options: NSDictionary) -> Bool { VKSdk.processOpenURL(url as NSURL, fromApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String) return true } 

In general, the problem is : when you click the button (with which I start authorization), nothing happens, but this message pops up - canOpenURL: failed for URL: "vkauthorize://authorize" - error: "The operation couldn't be completed. (OSStatus error -10814.)"

Question : What am I doing wrong? After all, as I understand it, if the application is not installed, then the browser should start? In the simulator, there seems to be a browser, as I understand it. Or does it only work on a real device?

Another question - where to get ios app id? In VK in the settings of the application you need to add this id. But I did not understand where to get it. I was told that this is the application id in appstore. But my application is only in development. Or is it not necessary to specify this id in VK yet? Here I am interested in this field (1), as well as the field (2), I filled the second one, but just in case specify what to write there, all of a sudden I filled it up incorrectly.

enter image description here

UPDT: Yesterday, I’ve got to know that in order for authorization to open, you need to implement it yourself in the method:

  func vkSdkShouldPresentViewController(controller:UIViewController?) -> Void { print("vkSdkShouldPresentViewController") presentViewController(controller!, animated: true, completion: nil) } 

After that, the authorization began to open. Tested on a real device and when the application is installed, when you first click, the application starts up and after confirming the permission, the application starts up the user’s page, which is strange and does not return any data. If you log into my application again and press the login again, this time the safari opens and you can also confirm the authorization there, after which the error about the inability to open the page pops up. And the result is returned to the application, but all keys are nil.

Then I tested on the simulator and, when logging in, the safari always writes that there is no access to the page (after authorization is enabled) and the type of connection to the Internet must be checked. But I have all the schemes like added to plist (above in the text).

  • Hmm, and you are not bothered by the phrase "Application is disabled"? - Roman Podymov
  • @RomanPodymov Well, I do not know what this setting affects, but the android application works. In the application on the android, the user is also authorized through VC and the application receives a token and mail, according to which it is either registered or logged in on our website. But there was no difficulty in the android. But in ios something does not come out. Although yesterday I added something to the code (I’ll update the question text) and after that, the VC application started and there after confirming the authorization permission, it just went to the user’s page in VC and that's it, but nothing returns to the application. - cheerful_weasel

0