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 许可证下可用。有关详细信息,请参阅许可证文件。