index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import 'react-native-gesture-handler'
  2. import { LogBox, AppRegistry, Platform } from 'react-native'
  3. import App from './App'
  4. import { name as appName } from './app.json'
  5. import PushNotificationIOS from '@react-native-community/push-notification-ios'
  6. import PushNotification from 'react-native-push-notification'
  7. AppRegistry.registerComponent(appName, () => App)
  8. // Must be outside of any component LifeCycle (such as `componentDidMount`).
  9. PushNotification.configure({
  10. // (optional) Called when Token is generated (iOS and Android)
  11. onRegister: function (token) {
  12. console.log("TOKEN:", token);
  13. },
  14. // (required) Called when a remote is received or opened, or local notification is opened
  15. onNotification: function (notification) {
  16. console.log("NOTIFICATION:", notification);
  17. // process the notification
  18. // (required) Called when a remote is received or opened, or local notification is opened
  19. notification.finish(PushNotificationIOS.FetchResult.NoData);
  20. },
  21. // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
  22. onAction: function (notification) {
  23. console.log("ACTION:", notification.action);
  24. console.log("NOTIFICATION:", notification);
  25. // process the action
  26. },
  27. // (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)
  28. onRegistrationError: function(err) {
  29. console.error(err.message, err);
  30. },
  31. // IOS ONLY (optional): default: all - Permissions to register.
  32. permissions: {
  33. alert: true,
  34. badge: true,
  35. sound: true,
  36. },
  37. // Should the initial notification be popped automatically
  38. // default: true
  39. popInitialNotification: true,
  40. /**
  41. * (optional) default: true
  42. * - Specified if permissions (ios) and token (android and ios) will requested or not,
  43. * - if not, you must call PushNotificationsHandler.requestPermissions() later
  44. * - if you are not using remote notification or do not have Firebase installed, use this:
  45. * requestPermissions: Platform.OS === 'ios'
  46. */
  47. requestPermissions: Platform.OS === 'ios',
  48. });
  49. PushNotification.createChannel(
  50. {
  51. channelId: "testChanne0", // (required)
  52. channelName: "testChanne0", // (required)
  53. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  54. playSound: true, // (optional) default: true
  55. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  56. importance: 0, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  57. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  58. },
  59. );
  60. PushNotification.createChannel(
  61. {
  62. channelId: "testChanne1", // (required)
  63. channelName: "testChanne1", // (required)
  64. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  65. playSound: true, // (optional) default: true
  66. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  67. importance: 1, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  68. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  69. },
  70. );
  71. PushNotification.createChannel(
  72. {
  73. channelId: "testChanne2", // (required)
  74. channelName: "testChanne2", // (required)
  75. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  76. playSound: true, // (optional) default: true
  77. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  78. importance: 2, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  79. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  80. },
  81. );
  82. PushNotification.createChannel(
  83. {
  84. channelId: "testChanne3", // (required)
  85. channelName: "testChanne3", // (required)
  86. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  87. playSound: true, // (optional) default: true
  88. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  89. importance: 3, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  90. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  91. },
  92. );
  93. PushNotification.createChannel(
  94. {
  95. channelId: "testChanne4", // (required)
  96. channelName: "testChanne4", // (required)
  97. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  98. playSound: true, // (optional) default: true
  99. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  100. importance: 4, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  101. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  102. },
  103. );
  104. PushNotification.createChannel(
  105. {
  106. channelId: "testChanne5", // (required)
  107. channelName: "testChanne5", // (required)
  108. channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
  109. playSound: true, // (optional) default: true
  110. soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
  111. importance: 5, // (optional) default: Importance.HIGH. Int value of the Android notification importance
  112. vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
  113. },
  114. );
  115. LogBox.ignoreAllLogs(true)