ReactNative 低版本Jpush集成遇坑记录
对应jpush版本
“jcore-react-native”: “^1.8.0”
“jpush-react-native”: “^2.8.1”
对应Rn版本
“react-native”: “0.44.3”
相对版本较低,原来老项目需要进行改造集成推送,遇到坑跟码友共享,并自我记录,以便自身查看!
针对xcode11 报错
报错信息
getCurrentAppState:error
解决方法
在对应目录下/Users///node_modules/react-native/React/Base/RCTModuleMethod.m
static BOOL RCTParseUnused(const char **input)
{
return RCTReadString(input, "__unused") ||
RCTReadString(input, "__attribute__((__unused__))") || //lzj fixed
RCTReadString(input, "__attribute__((unused))");
}
Error: Could not find iPhone 6 simulator
解决方法
在对应目录下/Users///node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js替换代码块
function findMatchingSimulator(simulators, simulatorName) {
if (!simulators.devices) {
return null;
}
const devices = simulators.devices;
var match;
for (let version in devices) {
console.log(" version in devices ");
console.log(version);
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
continue;
}
for (let i in devices[version]) {
let simulator = devices[version][i];
// Skipping non-available simulator
if (simulator.isAvailable !== true) {
continue;
}
let booted = simulator.state === 'Booted';
if (booted && simulatorName === null) {
return {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
if (simulator.name === simulatorName && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
// Keeps track of the first available simulator for use if we can't find one above.
if (simulatorName === null && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
}
}
if (match) {
return match;
}
return null;
}
module.exports = findMatchingSimulator;
Android低版本ContextCompat.checkSelfPermission不支持
解决方案
直接注释掉响应代码并将targetSdkVersion改成23,23版本不对权限做相应校验
notificationExtra没有toHashMap
解决方案
JPushModule.java中的方法将获取部分重写,通过迭代器去构造map
HashMap hashMap = new HashMap();
ReadableMapKeySetIterator iterator = notificationExtra.keySetIterator();
while (iterator.hasNextKey()){
String nextValue = iterator.nextKey();
hashMap.put(nextValue,notificationExtra.getString(nextValue));
}