push notification react native

Solutions on MaxInterview for push notification react native by the best coders in the world

showing results for - "push notification react native"
Julian
27 Aug 2019
1import PushNotificationIOS from '@react-native-community/push-notification-ios';
2import { Platform } from 'react-native';
3import PushNotification from 'react-native-push-notification';
4
5class NotificationManager {
6    configure = () => {
7        PushNotification.configure({
8            onRegister: function (token: any) {
9                console.log('TOKEN:', token);
10            },
11            onNotification: function (notification: any) {
12                console.log('NOTIFICATION:', notification);
13                notification.finish(PushNotificationIOS.FetchResult.NoData);
14            },
15            permissions: {
16                alert: true,
17                badge: true,
18                sound: true,
19            },
20            popInitialNotification: true,
21            requestPermissions: true,
22        });
23        PushNotification.createChannel(
24            {
25                channelId: 'fcm_fallback_notification_channel', // (required)
26                channelName: 'Channel', // (required)
27            },
28            (created) => console.log(`createChannel returned '${created}`),
29        );
30    };
31
32    buildAdroidNotification = (id: number, title: string, message: string, data = {}, options = {}) => {
33        return {
34            id: id,
35            autoCancel: true,
36            largeIcon: options.largeIcon || 'ic_launcher',
37            smallIcon: options.smallIcon || 'ic_launcher',
38            bigText: message || '',
39            subText: title || '',
40            vibration: options.vibration || 300,
41            vibrate: options.vibrate || false,
42            priority: options.priority || 'high',
43            importance: options.importance || 'high',
44            data: data,
45        };
46    };
47    buildIOSNotification = (id: number, title: string, message: string, data = {}, options = {}) => {
48        return {
49            alertAction: options.alertAction || 'view',
50            category: options.category || '',
51            userInfo: {
52                id: id,
53                item: data,
54            },
55        };
56    };
57    cancelAllNotification = () => {
58        console.log('cancel');
59        PushNotification.cancelAllLocalNotifications();
60        if (Platform.OS === 'ios') {
61            PushNotificationIOS.removeAllDeliveredNotifications();
62        }
63    };
64
65    showNotification = (id: number, title: string, message: string, data = {}, options = {}, date: Date) => {
66        PushNotification.localNotificationSchedule({
67            //Android
68            ...this.buildAdroidNotification(id, title, message, data, options),
69
70            // iOS
71            ...this.buildIOSNotification(id, title, message, data, options),
72
73            // Android and iOS
74            title: title || '',
75            message: message || '',
76            playSound: options.playSound || false,
77            soundName: options.soundName || 'default',
78            date: date,
79        });
80    };
81    unregister = () => {
82        PushNotification.unregister();
83    };
84}
85export const notificationManager = new NotificationManager();
86
Yacine
18 Sep 2016
1/**
2 * @format
3 */
4
5import PushNotificationIOS from '@react-native-community/push-notification-ios';
6import { AppRegistry } from 'react-native';
7import PushNotification from 'react-native-push-notification';
8import App from './App';
9import { name as appName } from './app.json';
10
11// Must be outside of any component LifeCycle (such as `componentDidMount`).
12PushNotification.configure({
13  // (optional) Called when Token is generated (iOS and Android)
14  onRegister: function (token) {
15    console.log('TOKEN:', token);
16  },
17
18  // (required) Called when a remote is received or opened, or local notification is opened
19  onNotification: function (notification) {
20    console.log('NOTIFICATION:', notification);
21
22    // process the notification
23    // (required) Called when a remote is received or opened, or local notification is opened
24    notification.finish(PushNotificationIOS.FetchResult.NoData);
25  },
26
27  // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
28  onAction: function (notification) {
29    console.log('ACTION:', notification.action);
30    console.log('NOTIFICATION:', notification);
31    // process the action
32  },
33
34  // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
35  onRegistrationError: function (err) {
36    console.error(err.message, err);
37  },
38
39  // IOS ONLY (optional): default: all - Permissions to register.
40  permissions: {
41    alert: true,
42    badge: true,
43    sound: true,
44  },
45
46  // Should the initial notification be popped automatically
47  // default: true
48
49  popInitialNotification: true,
50
51  /**
52   * (optional) default: true
53   * - Specified if permissions (ios) and token (android and ios) will requested or not,
54   * - if not, you must call PushNotificationsHandler.requestPermissions() later
55   * - if you are not using remote notification or do not have Firebase installed, use this:
56   *     requestPermissions: Platform.OS === 'ios'
57   */
58
59  requestPermissions: true,
60});
61
62AppRegistry.registerComponent(appName, () => App);
63
queries leading to this page
react native push notification action on open notificationreact native notification pagesetup react native notificationnotification page react nativereact native push notificationreact native add notificationpush notification react native silencewhat is push notifications react nativeremote push notification react nativepush notification reacthow to change the push notification ui in react nativereact native push notificatyionpush notification ios react nativehow to add push notification in react nativereact native push notification when app is closednotification application in react nativern push notificationspush notification in react native androidreact native notificationreact native push notification linkpush notification using firebase in react nativehow to send push notification react nativereact native allow push notificationreact native push notifications examplehow to setup push notification in react nativereact native push notification on action 40react navigationreact native notification push androidreact native push notification npmlocal push notification in react native androidremove notification push android react nativereact native push notificationpush notification not working when app is closed in react native push notificationreact native notificationsreact native push notifications setupreact native notification exampleremote notification react nativereact native push notifications firebasereact native firebase push notificationsnotification push react nativepush notification in react native firebasehow to use push notification in react nativereact native push notification showing message as objectreact native push notification npmpush notification to react appreact native setup push notification iospush notification react native firebasereact native push notificationpush notification firebase in react nativepush notification in react nativenotification in android react nativereact native cli push notificationspush notification react nativereact native push notification examplepush notification in react native when app is openreact native push notification npmreact native push notifications for android and iospush notification ios react nativereact native how to send push notifications to userpush notifications react nativehow to make push notifications from backend in react nativenotification react nativepush notification reactjsreact native remote push notifications examplereact native local push notificationsios push notification react nativereact native push notifications ios in react natiev how to enable push notifications in ios react native appreact natiev push notificationdoes push notification show when app is open react nativereact native push notification npmwhat is push notification react nativereact native firebase push notification examplereact native push notifications providerspush notifications react native firebaserun onaction in react native push notificationreact native firebase push notificationsdreact native push notificationsreact native push notification without firebasereact native push notifications npmpush notification in react native using firebaseract native push notificationreact native ios push notificationreact native push notification remove notificationsreact native push notifications iosreact native push notification not working uireact native notification send notification afterreact native push notifications push notifications in react nativereact native push notification send remotefirebase react native push notificationsreact native push notifications without firebasenotifications in react native appreact push notificationpush notification firebase react nativereact native in app notificationreact native push notification iospush notifications react native not working on iosremote push notifications react nativereact native firebase push notificationpush notification in react native using nodejsreact native push notification onclickreact native push notification npmreact native firebase push notificationnotification in react nativereact native push notifications without firebasenotifications in react nativereact native notification pushpush notification react native