推送通知expo / react-native

时间:2017-11-05 04:48:24

标签: reactjs react-native notifications expo

我可以将通知推送到Android设备但是当我在iOS上时我没有收到它们。我尝试了不同的配置,仍然没有在我的iPhone上发送通知。

是的,我正在使用设备/是我的设备上的通知已开启。

"dependencies": {
 "expo": "22.0.0",
 "native-base": "2.3.1",
 "react": "16.0.0-alpha.12",
 "react-native": "0.49.3",
}

pushNotification.js

const PUSH_ENDPOINT = 'http://rallycoding.herokuapp.com/api/tokens';
export default async () => {
let previousToken = await AsyncStorage.getItem('pushtoken');    
if(previousToken){
    return;
}else{
  let { status } = await Permissions.askAsync(Permissions.REMOTE_NOTIFICATIONS);

  if(status !== 'granted'){
      return;
  }

  let token = await Notifications.getExpoPushTokenAsync();

  console.log('token ',token)
  await axios.post(PUSH_ENDPOINT, {token: {token} });
  AsyncStorage.setItem('pushtoken', token)
}
};

Index.js

import registerForNotification from "./helpers/pushNotification";
ComponentDidMount(){
registerForNotification();    
Expo.Notifications.addListener((notification) => {
  const {data: {text}, origin } = notification;
  console.log(notification);
  if (origin === 'received') {
    Alert.alert(
      'New Push Notification',
      text,
      [{ text: 'Ok'}]
    );
  }
});
}

0 个答案:

没有答案