# rn-file-opener
**Repository Path**: thor.qin/rn-file-opener
## Basic Information
- **Project Name**: rn-file-opener
- **Description**: clone from :
https://github.com/huangzuizui/react-native-file-opener
modify android source to support higher version android device.
upgrade gradle version.
- **Primary Language**: JavaScript
- **License**: Unlicense
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-11-17
- **Last Updated**: 2022-05-27
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 使用
import FileOpener from 'rn-file-opener';
......
componentDidMount() {
DeviceEventEmitter.addListener('inited', (e: Event) => {
// handle event.
this.setState({
initState: "已经初始化!" + JSON.stringify(e)
})
});
DeviceEventEmitter.addListener('onToken', (e: Event) => {
// handle event.
this.setState({
tokenState: "Token信息:" + JSON.stringify(e)
})
});
DeviceEventEmitter.addListener('pushMsg', (e: Event) => {
// handle event.
this.setState({
messageInfo: "message信息:" + JSON.stringify(e)
})
});
DeviceEventEmitter.addListener('pushState', (e: Event) => {
// handle event.
this.setState({
pushState: "pushState改变:" + JSON.stringify(e)
})
});
DeviceEventEmitter.addListener('debug', (e: Event) => {
// handle event.
this.setState({
debug: "debug信息:" + JSON.stringify(e)
})
});
FileOpener.notifyJSDidLoad((d) => {
// alert("服务器返回" + d);
})
}
## 关于PUSH的额外说明
- 非华为小米的Android和所有iOS的PUSH,走极光通道
- 调用华为小米的PUSH消息API,发送的消息类型为自定义消息类型(PUSH带action的)
- 华为小米的appID和Key信息再gradle文件里查找配置com.mi.appid等
- Android 的MainActivity加如下代码:
void handlePushMessage(android.content.Intent intent) {
if (intent.hasExtra("PUSH")) {
String value = intent.getStringExtra("PUSH");
FileOpener.sendToClient(value);
Log.d("===MAIN===", value);
}
}
@Override
public void onNewIntent(android.content.Intent intent) {
handlePushMessage(intent);
}
## 关于热更新的代码
- Android 部分主要代码如下
private static final String bundleFile = "index.android.bundle";
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
......
@Nullable
@Override
protected String getJSBundleFile() {
String path = String.format("%s%s%s",Environment.getDataDirectory() , File.separator ,bundleFile);
if(new File(path).exists()){
return path;
}
return super.getJSBundleFile();
}
@Override
protected String getBundleAssetName(){
return bundleFile;
}
- iOS 部分主要代码如下
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"app_name" initialProperties:nil launchOptions:launchOptions];
## 关于升级
### Android 升级
- appName应用名称、
- releaseNode 更新说明、
- url 升级地址、
- cancelable 是否可以取消(强制升级使用)
-
public void showUpdate(final String appName,String releaseNode, final String url,boolean cancelable)
### iOS 升级
- 使用Link直接打开浏览器升级,如果直接升级,浏览器地址就对应下载的plist文件地址
var url = 'http://tsd.com/d.plist';
Linking.openURL(url)
.catch((err)=>{
console.log('An error occurred', err);
});