NBus
1.3.0
NBus是微信、QQ、微博等中文社群應用程式的分享和登入庫。 NBus也支援系統分享和Apple登入。
處理程式 | 文字 | 影像 | 聲音的 | 影片 | 網頁 | 文件 | 小程式 |
---|---|---|---|---|---|---|---|
QQ處理程序 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
QQSDKHandler | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
微信處理程序 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
微信SDKHandler | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
微博處理程序 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ||
微博SDKHandler | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ||
系統處理程式 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
處理程式 | 認證 |
---|---|
QQ處理程序 | ✔️ |
QQSDKHandler | ✔️ |
微信處理程序 | ✔️ |
微信SDKHandler | ✔️ |
微博處理程序 | ✔️ |
微博SDKHandler | ✔️ |
系統處理程式 | ✔️ |
處理程式 | 小程式 |
---|---|
QQ處理程序 | ✔️ |
QQSDKHandler | ✔️ |
微信處理程序 | ✔️ |
微信SDKHandler | ✔️ |
微博處理程序 | |
微博SDKHandler | |
系統處理程式 |
- ✔️ - 支持
- ⭕ - 實驗支持
- - 不支持
Info.plist
中編輯LSApplicationQueriesSchemes
。 <? xml version = " 1.0 " encoding = " UTF-8 " ?>
<! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
< plist version = " 1.0 " >
< 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 >
</ plist >
Info.plist
中的CFBundleURLTypes
。 <? xml version = " 1.0 " encoding = " UTF-8 " ?>
<! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
< plist version = " 1.0 " >
< 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 >
</ plist >
TARGET.entitlements
中的com.apple.developer.associated-domains
。 <? xml version = " 1.0 " encoding = " UTF-8 " ?>
<! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
< plist version = " 1.0 " >
< array >
< string >applinks:www.example.com</ string >
</ array >
</ plist >
func application (
_ application : UIApplication ,
didFinishLaunchingWithOptions launchOptions : [ UIApplication . LaunchOptionsKey : Any ] ?
) -> Bool {
let qqHandler = QQHandler (
appID : " tencent123456 " ,
universalLink : URL ( string : " https://www.example.com/qq_conn/123456/ " ) !
)
Bus . shared . handlers = [ qqHandler ]
}
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 )
}
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 )
}
}
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 )
}
}
let program = Messages . miniProgram (
miniProgramID : " 123456 " ,
path : " /example " ,
link : URL ( string : " https://www.example.com " ) ! ,
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/NBus/Config.xcconfig
文件,然後先從範例目錄執行bundle install && bundle exec fastlane setup && open Example/NBus.xcworkspace
。
您可以直接使用NBus
,其中包含所有 SDK 橋接處理程序。
pod "NBus" # default subspecs "SDKHandlers"
或所有開源處理程序。
pod "NBus/BusHandlers"
或者你喜歡什麼。
pod "NBus/QQSDKHandler"
pod "NBus/QQHandler"
pod "NBus/WechatSDKHandler"
pod "NBus/WechatHandler"
pod "NBus/WeiboSDKHandler"
pod "NBus/WeiboHandler"
pod "NBus/SystemHandler"
甚至那些 SDK。
pod "NBusQQSDK"
pod "NBusWechatSDK"
pod "NBusWeiboSDK"
WeiboSDK.bundle
必須保存在App的根路徑下。 糯米1, 糯米[email protected]
NBus 在 MIT 許可證下可用。有關詳細信息,請參閱許可證文件。