SocialToolKit 0.2

SocialToolKit 0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Victor Amelin.


Downloads

Total51
Week0
Month0

Installs

Apps6
powered by Segment

GitHub

Stars5
Watchers3
Forks2
Issues0
Contributors1
Pull Requests0

Code

Files1
LOCLines of Code 111


 
Depends on:
FBSDKCoreKit>= 0
FBSDKLoginKit>= 0
VK-ios-sdk>= 0
 

  • By
  • Viktor Amelin

SocialToolKit

SocialToolKit purpose is to get access token from Facebook or VK. You can use it to get token from specific social network, or from several (now supports only Facebook and VKontakte).

How to install:

Requirements:

iOS 9.0+

Swift 3.0

Installing with CocoaPods:

use_frameworks!
pod 'SocialToolKit'

How to use:

For Facebook:

Update this three methods in your AppDelegate:

1.

import SocialToolKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    SocialToolKit.sharedInstance.appFBDidFinishLaunchingWithOptions(application: application, launchOptions: launchOptions)
return true
}

func applicationDidBecomeActive(_ application: UIApplication) {
    SocialToolKit.sharedInstance.appFBDidBecomeActive()
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    SocialToolKit.sharedInstance.appFBOpenURL(app: app, url: url, options: options)
    return true
}
  1. Go to Info.plist, secondary-clic Info.plist and select OpenAs -> SourceCode.

Insert the following XML snippet into the body of your file just before the final element.

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
                <array>
                    <string>fb{your-app-id}</string>
                </array>
        </dict>
    </array>
        <key>FacebookAppID</key>
            <string>{your-app-id}</string>
        <key>FacebookDisplayName</key>
            <string>{your-app-name}</string>
        <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
  • replace fb{your-app-id} with your Facebook app ID, prefixed with fb. For example, fb123456. You can find your app ID on the Facebook App Dashboard — https://developers.facebook.com/apps.
  • replace {your-app-id} with your app ID.
  • replace {your-app-name} with the display name you specified in the App Dashboard.
  • replace {human-readable reason for photo access} with the reason your app needs photo access.
  1. In yor viewController add as button-action (for example):
import SocialToolKit

SocialToolKit.sharedInstance.requestFacebookToken(permissions: ["public_profile", "user_friends"], loginBehavior: FBSDKLoginBehavior.systemAccount, { (token, error) in
    if error == nil {
        print("TOKEN: \(token)")
    } else {
        print("ERROR: \(error?.localizedDescription)")
    }
})

For VK:

  1. Update this method in your AppDelegate:
import SocialToolKit

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        SocialToolKit.sharedInstance.appVKOpenURL(sourceApplication: sourceApplication, url: url)
        return true
}
  1. Go to Project -> Targets -> Info -> URL Types and add URL Schemes vk, for example:

URL Schemes: vk1234567 Role: Editor

  1. Go to Info.plist, secondary-clic Info.plist and select OpenAs -> SourceCode. And add AppTransportSequrity:
    <key>NSAppTransportSecurity</key>
        <dict> 
            <key>NSExceptionDomains</key> 
            <dict> 
                <key>vk.com</key> 
                <dict> 
                    <key>NSExceptionRequiresForwardSecrecy</key> 
                    false/> 
                    <key>NSIncludesSubdomains</key> 
                    <true/> 
                    <key>NSExceptionAllowsInsecureHTTPLoads</key> 
                    <true/> 
                </dict> 
            </dict> 
        </dict>
  1. Add (update) LSApplicationQueriesSchemes:
        <key>LSApplicationQueriesSchemes</key> 
        <array> 
            <string>vk</string> 
            <string>vk-share</string> 
            <string>vkauthorize</string> 
        </array>

If you are using FB iOS SDK and VK iOS SDK it looks like this:

        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>fbapi</string>
            <string>fb-messenger-api</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
            <string>vk</string>
            <string>vk-share</string>
            <string>vkauthorize</string>
        </array>
  1. Then in ViewController (for example) use:
SocialToolKit.sharedInstance.requestVKToken(permissions: ["friends", "photos"], appId: "your app id") { (token, error) in
    if error == nil {
        print("TOKEN: \(token)")
    } else {
        print("ERROR: \(error?.localizedDescription)")
    }
}

LICENCE:

Copyright © 2017 Stfalcon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.