Git Product home page Git Product logo

react-native-vksdk's Introduction

react-native-vksdk

A wrapper around the iOS VK (VKontakte) SDK for React Native apps.

Setup

Wrapper settings

1). Install NPM package

npm install --save git+ssh://[email protected]:kohver/react-native-vksdk.git

Now jump to /ios folder.

2). Add to your Podfile (create it by pod init, if necessary)

pod 'VK-ios-sdk', :path => '../node_modules/react-native-vksdk/vk-ios-sdk'

then type pod install

3). Add VkAppID key to Info.plist image

4). Drag'n'drop RCTVkSdkLoginManager.h and RCTVkSdkLoginManager.m to your Libraries (without coping files, just click "Finish" button). image

Native VK SDK settings

1). Add import in AppDelegate.h

  ...
  #import <UIKit/UIKit.h>
+ #import <VKSdk.h>
  ...

2). Put this code to AppDelegate.m

//iOS 9 workflow
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    [VKSdk processOpenURL:url fromApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
    return YES;
}

//iOS 8 and lower
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    [VKSdk processOpenURL:url fromApplication:sourceApplication];
    return YES;
}

Note: if you already have FaceBook SDK added and one of this methods returns [FBSDKDelegate ...] you can handle it:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

    [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    [VKSdk processOpenURL:url fromApplication:sourceApplication];
    return YES;
}

3). Add this to your Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>vk</string>
    <string>vk-share</string>
    <string>vkauthorize</string>
</array>

4). Setup URL schema of Your Application

To authorize via VK App you need to setup a url-schema for your application, which looks like vk+APP_ID (e.g. vk1234567). There is nice Twitter tutorial

5). Run your app in xcode. Done!

Usage

var Vk = require('react-native-vksdk');

// authorize and get token
Vk.authorize()
    .then((result) => {
        // your code here
    }, (error) => {
        // your code here
    });
    
// logout
Vk.logout();

// api request
Vk.callMethod('users.get', {user_ids: 1})
    .then((result) => {
        // your code here
    }, (error) => {
        // your code here
    });
    

react-native-vksdk's People

Contributors

doochik avatar drumtoad avatar ilya-ramanenia avatar kohver avatar

Watchers

 avatar  avatar

Forkers

keenubee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.