【发布时间】:2020-12-21 16:24:24
【问题描述】:
我正在使用 react native expo 裸工作流
当我在 expo 客户端上打开应用程序时,我可以在屏幕上看到设备令牌,但是当我将其转换为 apk 时 通过使用 世博会构建:android 它不显示令牌。
这是我的代码。
import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View } from "react-native";
import * as Notifications from "expo-notifications";
import * as Permissions from "expo-permissions";
import { TextInput } from "react-native";
export default function App() {
const [token, setToken] = useState("");
const [value, onChangeText] = React.useState("Useless Placeholder");
useEffect(() => {
getPushNotificationPermissions();
});
getPushNotificationPermissions = async () => {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS,
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== "granted") {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== "granted") {
return;
}
console.log(finalStatus);
// Get the token that uniquely identifies this device
console.log(
"Notification Token: ",
(await Notifications.getExpoPushTokenAsync()).data,
);
setToken((await Notifications.getExpoPushTokenAsync()).data);
};
return (
<View style={styles.container}>
<Text>{token}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
而且我也没有收到关于 apk 的推送通知,但它适用于 expo 客户端。
【问题讨论】:
标签: react-native expo