React Native bridging library that integrates QQ SDKs. QQ login and sharing, the react-native version requires 0.40.0 and above
First of all, I declare to you that this library is rewritten on the basis of react-native-qq .
It is maintained for its own use. Considering its own use and the needs of other developers, I finally decided to open a new warehouse for new projects.
Finally, thanks to lvbingru , tdzl2003 and all developers for their contributions to react-native-qq.
Android SDK version: v3.3.9 (2020-04-27)
IOS SDK version: v3.3.9 (2020-04-27)
yarn add git+https://github.com/haxibiao/react-native-qq-lib.git
or
npm install -D git+https://github.com/haxibiao/react-native-qq-lib.git
Then execute
cd ios && pod install && cd ..
Add qq whitelist to the project plist file: (Required for ios9 or above) Please open Info.plist in text mode and add it
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- QQ、Qzone URL Scheme 白名单-->
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdk</string>
</array>
The Info->URL Types
increase in the QQ scheme: Identifier
set qq
, URL Schemes
set your registered developer account QQ in APPID, need to add a prefix tencent
, such astencent1104903684
AppDelegate.m
Add the following code to your project file:
#import <React/RCTLinkingManager.h>
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
In android/app/build.gradle
, add the following code under the defaultConfig column:
manifestPlaceholders = [
QQ_APPID: "<平台申请的APPID>"
]
If you need to modify the APPID in the future, you only need to modify this one.
Also, make sure your MainActivity.java have onActivityResult
achieved:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
mReactInstanceManager.onActivityResult(requestCode, resultCode, data);
}
import * as QQAPI from 'react-native-qq-lib';
Calling QQ login, you may jump to the QQ application or open a web browser for the user to log in. Before this login returns, all subsequent login calls will fail directly.
Return an Promise
object. The callback on success is an object like this:
{
"access_token": "CAF0085A2AB8FDE7903C97F4792ECBC3",
"openid": "0E00BA738F6BB55731A5BBC59746E88D"
"expires_in": "1458208143094.6"
"oauth_consumer_key": "12345"
}
Share to QQ friends, the parameters are the same as QQAPI.shareToQzone, return an Promise
object
Share to QZone, the parameter is an object, which can have the following forms:
// Share graphic message
{
type : 'news' ,
title : share title ,
description : description ,
webpageUrl : webpage address ,
imageUrl : remote image address ,
}
// share text message
{
type : 'text' ,
text : share content ,
}
// Share the picture
// By: The imageUrl and imageLocalUrl here must be passed and kept consistent (don’t ask me why I buried this pit, I asked Tencent’s SDK to do this)
// Supported paths such as: file:// content :// /data/user/0/com.xxxxx/cache/
{
type : 'image' ,
imageUrl : image path ,
imageLocalUrl : image path ,
}
// The remaining formats have not yet been implemented.
The image path does not support http and https network addresses (for the network address, download the image yourself first, the rn-fetch-blob library is recommended here ).
import RNFetchBlob from 'rn-fetch-blob';
const _image = 图片地址或路径;
if (RegExp(/http:\/\//).exec(_image) || RegExp(/https:\/\//).exec(_image)) {
// 判断是网络地址的话先下载图片,然后再分享图片
RNFetchBlob.config({
fileCache: true,
appendExt: "png",
})
.fetch("GET", _image)
.then((res) => {
const qq = QQAPI.shareToQzone({
type: "image",
imageUrl: res.path(),
imageLocalUrl: res.path(),
});
qq.then(() => {
__onSucceed();
}).catch(() => {
});
})
.catch((error) => {
});
} else {
const qq = QQAPI.shareToQzone({
type: "image",
imageUrl: _image,
imageLocalUrl: _image,
});
qq.then(() => {
}).catch(() => {
});
}
Usually this reason is because the Manifest is not configured properly. Check the configuration of the Activity in the Manifest.
Usually this reason is because of the lack of onActivityResult call in MainActivity.java.
Author: haxibiao
Source Code: https://github.com/haxibiao/react-native-qq-lib
#react-native #react #mobile-apps