Звук уведомления Expo pu sh и всплывающее окно не работают - PullRequest
0 голосов
/ 09 мая 2020

Я разрабатываю приложение с expo и pu sh уведомление работает нормально, но без звука и не всплывает ..

Примечание: оно только вибрирует, но без звука уведомления.

Моя клиентская сторона

 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();
      console.log(token);
      this.setState({ expoPushToken: token });
    } else {
      alert('Must use physical device for Push Notifications');
    }

    if (Platform.OS === 'android') {
      Notifications.createChannelAndroidAsync('notification-sound-channel', {
        name: 'Notification Sound Channel',
        sound: true,
        priority: 'max',
        vibrate: [0, 250, 250, 250],
      });
    }

Моя серверная сторона php laravel: https://github.com/Alymosul/exponent-server-sdk-php

$notification = [
    'title' => 'test title',
    'body' => 'test body'
    'channelId' => 'notification-sound-channel',
];

Я также тестировал его с expo Pu sh инструмент уведомлений: https://expo.io/notifications и работает так же (вибрация без звука и всплывающих окон)

среда

expo: «^ 37.0.8»,

Версия SDK: 27,

Тестовое устройство android версия: 9

1 Ответ

0 голосов
/ 20 мая 2020

Я использую его с ядром PHP, и он работает (со звуком, вибрацией и всплывающим окном).

Это код m PHP, который срабатывает при нажатии кнопки.

    require_once 'vendor/autoload.php';
    $channelName = 'userdId'; // from database
    $recipient= 'ExponentPushToken[lHS_FNBss5OD-XT-rGgRLE]';

    // You can quickly bootup an expo instance
    $expo = \ExponentPhpSDK\Expo::normalSetup();

    // Subscribe the recipient to the server
    $expo->subscribe($channelName, $recipient);

    // Build the notification data
    $notification = ['title' => "Notification Title", 'body' => 'This is a testing notification.', 'channelId' => 'notification-sound-channel',];

    // Notify an interest with a notification
    $expo->notify([$channelName], $notification);

Это мой собственный код React

import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, Button, Platform } from "react-native";
import { Notifications } from "expo";
import * as Permissions from "expo-permissions";
export default function App() {
  const [expoPushToken, setExpoPushToken] = useState("");
  useEffect(() => {
    this.getPushNotificationPermissions();
  });
  getPushNotificationPermissions = async () => {
    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") {
      return;
    }

    const tok = await Notifications.getExpoPushTokenAsync();
    setExpoPushToken(tok);
  };
  if (Platform.OS === "android") {
    Notifications.createChannelAndroidAsync("notification-sound-channel", {
      name: "Notification Sound Channel",
      sound: true,
      priority: "max",
      vibrate: [0, 250, 250, 250],
    });
  }
  return (
    <View>
      <Text>PHP Notification Testing</Text>
    </View>
  );
}
...