React native 将功能组件转换为类组件
我刚开始学习react native大约一个月,只关注类,但我发现我的推送通知(expo docs)是用react挂钩编写的,我在边类上有一些访问问题,但我对挂钩一无所知。。。。请帮我换个班。谢谢大家。我试着换课,但犯了很多错误 对于exp推送通知(类类型组件),请使用以下命令:React native 将功能组件转换为类组件,react-native,React Native,我刚开始学习react native大约一个月,只关注类,但我发现我的推送通知(expo docs)是用react挂钩编写的,我在边类上有一些访问问题,但我对挂钩一无所知。。。。请帮我换个班。谢谢大家。我试着换课,但犯了很多错误 对于exp推送通知(类类型组件),请使用以下命令: import React, {Component} from 'react'; //import { Notifications } from 'expo'; import * as Notifications fr
import React, {Component} from 'react';
//import { Notifications } from 'expo';
import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
import Constants from 'expo-constants';
import {
Alert,
Vibration, Platform,
Image,
StyleSheet,
View,
AsyncStorage,
TextInput,
Text,
TouchableOpacity,
} from 'react-native';
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
export default class xxxxxx extends Component {
state = {
expoPushToken: '',
notification: {},
};
registerForPushNotificationsAsync = async () => {
let token;
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
//this.setState({
// xbuttonstate: false
// })
this.setState({expoPushToken:token})
// alert(this.state.expoPushToken);
// unremark the above if you want to see the expoPushToken
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
};
/// Add other codes you want (e.g. render /view )
}