VK-ios-sdk

VK iOS SDK

Description

The VK iOS SDK is a library provided by VK (formerly known as VKontakte) that enables developers to integrate VK features into their iOS applications. With this SDK, developers can authenticate users, make API calls, post on their wall, and more.

Features

  • Easy integration of VKontakte into iOS applications.
  • Authentication using VKontakte credentials.
  • Access to VKontakte API for various functionalities.
  • Post on the user’s wall and share content.
  • Obtain user information such as name, profile picture, etc.
  • Ability to perform VK actions like adding comments, likes, and more.
  • Support for VKontakte SDK methods like “one-click” invite and share.
  • Support for VK widgets like the comments widget, like widget, and others.

Installation

To install the VK iOS SDK, follow these steps:

Step 1: Add the VK iOS SDK to Your Project

1. Download the VK iOS SDK from the official VK GitHub repository (link: https://github.com/VKCOM/vk-ios-sdk).

2. Unzip the downloaded file.

3. Open your Xcode project.

4. Right-click on your project in the Project Navigator, and select “Add Files to ‘Your Project’”.

5. Navigate to the unzipped VK iOS SDK folder and select “VK_ios_sdk.framework”. Make sure “Copy items if needed” is checked.

6. Click “Add”.

Step 2: Configure Your Project

1. In your Xcode project, navigate to your app target’s settings (General tab).

2. In the “Frameworks, Libraries, and Embedded Content” section, click the “+” button.

3. Select “VK_ios_sdk.framework” from the list.

4. Set the “Embed” option to “Embed & Sign”.

5. Close the settings.

6. Using the Project Navigator, open the “Info.plist” file of your app.

7. Right-click on a blank space and select “Add Row”.

8. Add “URL types” as the key.

9. Expand the added “URL types” row, and add an item in the “URL Schemes” field.

10. Set the “URL Schemes” value to “vkYOUR_APP_ID” (replace “YOUR_APP_ID” with your VKontakte application ID).

11. Close the “Info.plist” file.

Step 3: Configure Your AppDelegate

Add the following code to your AppDelegate.swift file:


import VK_ios_sdk

// ...

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    VKSdk.processOpen(url, fromApplication: options[.sourceApplication] as? String)
    return true
}

Usage

To use the VK iOS SDK in your app, follow these steps:

Step 1: Import VK_ios_sdk

Import the VK_ios_sdk framework in your view controller’s Swift file(s):


import VK_ios_sdk

Step 2: Authenticate the User

Use the VKSdk.authorize(_:) method to authenticate the user.


VKSdk.authorize(["email", "friends", "wall"])

Step 3: Handle the Authentication Result

Implement the vkSdkAccessAuthorizationFinished(with result: Bool) method to handle the authentication result.


func vkSdkAccessAuthorizationFinished(with result: VKAuthorizationResult!) {
    if result.token != nil {
        // User is authenticated
    } else if result.error != nil {
        // Error in authentication
    }
}

Step 4: Make API Calls

Use the VKApi.request(with:methodName, andParameters: parameters) method to make API calls.


VKApi.request(with: "users.get", andParameters: ["user_ids": "1", "fields": "photo_100"])?.execute(resultBlock: { (_ response: VKResponse?) -> Void in
    // Handle the response
}, errorBlock: { (_ error: Error?) -> Void in
    // Handle the error
})

Step 5: Post on the User’s Wall

Use the VKSdk.authorize(_:) method to authenticate the user and the VKApi.wall.post() method to post on their wall.


VKSdk.authorize(["wall"])
VKApi.wall().post(withMessage: "Hello, World!", friendsOnly: false, fromGroup: 0, attachments: nil, location: nil, postId: nil, guid: nil, resultBlock: { (_ response: VKResponse?) -> Void in
    // Handle the response
}, errorBlock: { (_ error: Error?) -> Void in
    // Handle the error
})

Step 6: Log Out the User

Use the VKSdk.forceLogout() method to log out the user.


VKSdk.forceLogout()

Examples

Example 1: Authenticate User and Fetch User Information


VKSdk.authorize(["wall", "friends", "users"])
VKApi.users().get(["user_ids": "1", "fields": "photo_100"]).execute(resultBlock: { (_ response: VKResponse?) -> Void in
    // Handle the response
}, errorBlock: { (_ error: Error?) -> Void in
    // Handle the error
})

Example 2: Post on User’s Wall


VKSdk.authorize(["wall"])
VKApi.wall().post(withMessage: "Hello, World!", friendsOnly: false, fromGroup: 0, attachments: nil, location: nil, postId: nil, guid: nil, resultBlock: { (_ response: VKResponse?) -> Void in
    // Handle the response
}, errorBlock: { (_ error: Error?) -> Void in
    // Handle the error
})

Support

If you encounter any issues or need assistance with the VK iOS SDK, you can refer to the following resources for support:

Documentation

Visit the official VK iOS SDK documentation for detailed information and guides: VK iOS SDK Documentation

Issues

If you encounter any issues or need to report a bug, please create a new issue on the official VK iOS SDK GitHub repository: VK iOS SDK Issues

Community

Join the VKontakte community and connect with other developers for support and discussions: VKontakte Developer Community