#android #react-native
#Android #react-native
Вопрос:
Недавно я был интегрирован в проект, который является приложением, и мне нужно настроить всю среду разработки. Итак, загрузите Android Studio, Java 8 и Node.js . Настройте переменные среды, виртуальные устройства для выполнения приложения. Как только весь этот процесс завершен, я запускаю эмулятор мобильного устройства и в терминале Android Studio выполняю:
npm i
После этого:
npx react-native run-android
После выполнения некоторых задач приложение устанавливается внутри устройства и начинает загружаться, но через несколько секунд оно закрывается и появляется это сообщение:
** rnpushnotification.requestpermissions получил 1 аргумент, ожидаемый 0 **
Это часть имеющейся у меня информации об окружающей среде:
React Native Environment Info:
System:
OS: Windows 10
CPU: (8) x64 Intel (R) Core (TM) i7 CPU 860 @ 2.80GHz
Memory: 16.60 GB / 23.99 GB
Binaries:
npm: 6.14.8 - C: Program Files nodejs npm.CMD
IDEs:
Android Studio: Version 4.1.0.0 AI-201.8743.12.41.6858069
Версия react-native, которая находится внутри проекта, равна 0.59.10, а версия react-native-push-notification — 3.3.0. Я рассматривал проблему в течение нескольких дней и не нашел решения. код, в котором используется PushNotification, следующий:
import PushNotification from 'react-native-push-notification';
import DeviceInfo from 'react-native-device-info';
import { PushNotificationIOS, Platform } from 'react-native';
import { Actions } from 'react-native-router-flux';
import { store } from './../Store';
import { REGISTER_DEVICE } from './../actions/types';
import ImageService from '../services/ImageService';
class NotificationService {
static configure() {
PushNotification.configure({
// Register token logic
onRegister: function(token) {
const device = {
tokenDispositivo: token.token,
plataforma: token.os,
imei: DeviceInfo.getUniqueID(),
};
store.dispatch({
type: REGISTER_DEVICE,
payload: device
});
},
// Logic process notification
onNotification: function(notification) {
// Notification
const type = Platform.OS === 'ios' ? notification.data.type : notification.type;
const alert = Platform.OS === 'ios' ? notification.data.alert : notification.message;
const title = Platform.OS === 'ios' ? notification.data.title : notification.title;
switch (type) {
case 'another':
const url = Platform.OS === 'ios' ? notification.data.fotoPerfil.replace( /ss /g, ' ' ).trim() : notification.fotoPerfil.replace( /ss /g, ' ' ).trim();
const user = Platform.OS === 'ios' ? notification.data.usuario.replace( /ss /g, ' ' ).trim() : notification.usuario.replace( /ss /g, ' ' ).trim();
const loanId = Platform.OS === 'ios' ? notification.data.idPrestamo.replace(' ','') : notification.idPrestamo.replace(' ','');
store.dispatch({
type: 'SHOW_MODAL',
modalProps: {
open: true,
title: title,
message: alert,
url: ImageService.getUrlFormat(url),
backdrop: false,
closeModal: () => {
store.dispatch({
type: 'HIDE_MODAL'
});
PushNotification.cancelAllLocalNotifications();
Actions.summaryLoanAccepted({loanId});
}
},
modalType: 'approved'
});
break;
case 'another':
store.dispatch({
type: 'SHOW_MODAL',
modalProps: {
open: true,
backdrop: false,
message: alert,
title: title,
closeModal: () => {
store.dispatch({
type: 'HIDE_MODAL'
});
const loanId = Platform.OS === 'ios' ? notification.data.idPrestamo.replace( /ss /g, ' ' ).trim() : notification.idPrestamo.replace( /ss /g, ' ' ).trim();
PushNotification.cancelAllLocalNotifications();
Actions.infoLoanOutstanding({ loanId: loanId });
}
},
modalType: 'billError'
});
break;
case 'another':
const urlComprobante = Platform.OS === 'ios' ? notification.data.urlComprobante.replace( /ss /g, ' ' ).trim() : notification.urlComprobante.replace( /ss /g, ' ' ).trim();
store.dispatch({
type: 'SHOW_MODAL',
modalProps: {
open: true,
backdrop: false,
message: alert,
closeModal: () => {
store.dispatch({
type: 'HIDE_MODAL'
});
store.dispatch({
type: 'SHOW_MODAL',
modalProps: {
open: true,
imagesUrl: Platform.OS === 'ios' ? [notification.data.urlComprobante.replace(' ','')]:[notification.urlComprobante.replace(' ','')],
backdrop: false,
closeModal: () => {
Actions.reset('layoutApplicant');
store.dispatch({
type: 'HIDE_MODAL'
});
},
},
modalType: 'image'
});
PushNotification.cancelAllLocalNotifications();
}
},
modalType: 'review'
});
break;
case 'another' :
store.dispatch({
type: 'SHOW_MODAL',
modalProps:{
open:true,
message: Platform.OS === 'ios' ? notification.data.message : notification.message ,
closeModal:()=>{
store.dispatch({
type:'HIDE_MODAL'
})
}
},
modalType: 'emptyState'
})
break;
default:
Actions.applicantHome();
}
const message = store.getState()
notification.finish(PushNotificationIOS.FetchResult.NoData);
PushNotification.setApplicationIconBadgeNumber(message.auth.messages);
},
// Android
senderID: 'SenderId',
// iOS
permissions: {
alert: true,
badge: true,
sound: true
},
permissions: { alert: true, badge: true, sound: true },
popInitialNotification: true,
requestPermissions: Platform.OS === 'ios'
});
}
};
export default NotificationService;
Комментарии:
1. эта проблема связана с push-уведомлением, покажите код push-уведомления
2. Я добавил код
3. PushNotificationIOS устарел