GithubHelp home page GithubHelp logo

nbus's Introduction

NBus

CI Status Version License Platform

Introduction

NBus is a sharing and signin library for Chinese Social Application, such as WeChat, QQ and Weibo. NBus also supports system's sharing and Sign in with Apple.

Feature

Share

Handler Text Image Audio Video WebPage File MiniProgram
QQHandler ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
QQSDKHandler ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
WechatHandler ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
WechatSDKHandler ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
WeiboHandler ✔️ ✔️ ✔️ ✔️ ✔️
WeiboSDKHandler ✔️ ✔️ ✔️ ✔️ ✔️
SystemHandler ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

Oauth

Handler Oauth
QQHandler ✔️
QQSDKHandler ✔️
WechatHandler ✔️
WechatSDKHandler ✔️
WeiboHandler ✔️
WeiboSDKHandler ✔️
SystemHandler ✔️

Launch

Handler MiniProgram
QQHandler ✔️
QQSDKHandler ✔️
WechatHandler ✔️
WechatSDKHandler ✔️
WeiboHandler
WeiboSDKHandler
SystemHandler
  • ✔️ - Support
  • ⭕ - Experimental support
  • ❌ - NOT support

Requirements

Usage

  1. Edit LSApplicationQueriesSchemes in Info.plist.
<array>
    <string>mqq</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdklaunchminiapp</string>
    <string>mqqopensdkminiapp</string>
    <string>mqqopensdknopasteboard</string>
    <string>weixin</string>
    <string>weixinULAPI</string>
    <string>sinaweibo</string>
    <string>weibosdk</string>
    <string>weibosdk3.3</string>
</array>
  1. Edit CFBundleURLTypes in Info.plist.
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>QQ</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>tencent123456</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>Wechat</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>wx123456</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>Weibo</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>wb123456</string>
        </array>
    </dict>
</array>
  1. Edit com.apple.developer.associated-domains in TARGET.entitlements.
<array>
    <string>applinks:www.example.com</string>
</array>
  1. Register handler(s) before using NBus.
func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    let qqSDKHandler = QQHandler(
        appID: "tencent123456",
        universalLink: URL(string: "https://www.example.com/qq_conn/123456/")!
    )

    Bus.shared.handlers = [qqSDKHandler]
}
func application(
    _ app: UIApplication,
    open url: URL,
    options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
    Bus.shared.openURL(url)
}
func application(
    _ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
    Bus.shared.openUserActivity(userActivity)
}
  1. Share message using NBus.
let message = Messages.text(text: "NBus")
let endpoint = Endpoints.QQ.friend

Bus.shared.share(message: message, to: endpoint) { result in
    switch result {
    case .success:
        print("Success")
    case let .failure(error):
        print(error)
    }
}
  1. Oauth using NBus.
let platform = Platforms.qq

Bus.shared.oauth(with: platform) { result in
    switch result {
    case let .success(parameters):
        let accessToken = parameters[Bus.OauthInfoKeys.QQ.accessToken]
        let expirationDate = parameters[Bus.OauthInfoKeys.QQ.expirationDate]
        let openID = = parameters[Bus.OauthInfoKeys.QQ.openID]

        print(accessToken, expirationDate, openID)
    case let .failure(error):
        print(error)
    }
}
  1. Launch Mini Program using NBus.
let program = Messages.miniProgram(
    miniProgramID: "123456",
    path: "/example",
    link: URL(string: "https://www.example")!,
    miniProgramType: .release,
    title: "NBus",
    description: "NBus",
    thumbnail: UIImage(named: "example")?.jpegData(compressionQuality: 1)
)

let platform = Platforms.qq

Bus.shared.launch(program: program, with: platform) { result in
    switch result {
    case .success:
        print("Success") // Never happen
    case let .failure(error):
        print(error)
    }
}

Example

To run the example project, clone the repo, edit the Example/NBus/Config.xcconfig file, and run bundle install && bundle exec fastlane setup && open Example/NBus.xcworkspace from the Example directory first.

Installation

CocoaPods

You can use NBus directly which is including all SDK bridging handlers.

pod "NBus" # default subspecs "SDKHandlers"

or all open source handlers.

pod "NBus/BusHandlers"

or what you like.

pod "NBus/QQSDKHandler"
pod "NBus/QQHandler"

pod "NBus/WechatSDKHandler"
pod "NBus/WechatHandler"

pod "NBus/WeiboSDKHandler"
pod "NBus/WeiboHandler"

pod "NBus/SystemHandler"

WARNING

  1. WeiboSDK.bundle must saved in App's root path.

Author

nuomi1, [email protected]

Related articles

Thanks

License

NBus is available under the MIT license. See the LICENSE file for more info.

nbus's People

Contributors

nuomi1 avatar

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.