RNFetchBlob.fs.writeFile как получить уведомление о завершении (NOT ALERT MESSAGE) - PullRequest
0 голосов
/ 19 января 2020

Как уведомить пользователя об успешной записи файла.

RNFetchBlob.fs.writeFile(path, Base64Code[1], 'base64')
        .then(res => {
            console.log(res);
            if (res > 0) {
                alert('download_success');
            } else {
                alert('download_failed');
            }
        });

1 Ответ

0 голосов
/ 20 января 2020

Вы можете попробовать использовать локальное уведомление с act-native-pu sh -notification

Вот как вы можете это сделать:

в первую очередь, импортировать библиотеку

import PushNotification from 'react-native-push-notification'

, а затем саму функцию:

RNFetchBlob.fs.writeFile(path, Base64Code[1], 'base64')
        .then(res => {
            console.log(res);
            if (res > 0) {
                PushNotification.localNotification({
                    id: '69',
                    ticker: "Download sucess!",
                    autoCancel: true,
                    vibrate: true,
                    vibration: 300,
                    ongoing: false, 
                    priority: "high",
                    visibility: "private",
                    importance: "high", 
                    title: "My app name",
                    message: "Your file has now ben saved!"
                });
            } else {
                PushNotification.localNotification({
                    id: '69',
                    ticker: "Download error!",
                    autoCancel: true,
                    vibrate: true,
                    vibration: 300,
                    ongoing: false, 
                    priority: "high",
                    visibility: "private",
                    importance: "high", 
                    title: "My app name",
                    message: "Errors ocurred while saving the file!"
                });
            }
        });

...