react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
740 stars 284 forks source link

invalid parameter not satisfying: identifier != nil was thrown while invoking addNotificationRequest #260

Closed irwansyafani closed 3 years ago

irwansyafani commented 3 years ago
depedencies :
"@react-native-community/push-notification-ios": "^1.8.0",
"react-native-push-notification": "^7.2.0"
// ====================> in index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import PushNotification from 'react-native-push-notification'
import { Platform } from 'react-native'

PushNotification.configure({
  onRegister: function (token) {
    console.log('TOKEN:', token)
  },
  onNotification: function (notification) {
    console.log('NOTIFICATION', notification);
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },
  onRegistrationError: function(err) {
    console.error(err.message, err);
  },
  permissions: {
    alert: true,
    badge: true,
    sound: true
  },
  popInitialNotification: true,
  requestPermissions: Platform.OS === 'ios'
})

AppRegistry.registerComponent(appName, () => App);
// my view
import PushNotificationIOS from '@react-native-community/push-notification-ios';

const showNotification = (title, message) => {
  PushNotificationIOS.addNotificationRequest({
    title: title,
    body: message,
  })
}

const handleScheduleNotification = (title, message) => {
  const date = new Date()
  date.setSeconds(date.getSeconds() * 5)
  PushNotificationIOS.addNotificationRequest({
    title: title,
    body: message,
    fireDate: date.toISOString(),
  })
}

const handleCancel = () => {
  PushNotificationIOS.removeAllDeliveredNotifications()
}

export { showNotification, handleScheduleNotification,handleCancel }
// error on simulator
invalid parameter not satisfying: identifier != nil was thrown while invoking addNotificationRequest on target RNCPushNotificationIOS with params ({
    body: "message",
    title: Immediately
})
// error on log
remote notifications are not supported in the simulator {"code": 3010, "details": {"NSLocalizedDescription": "remote notifications are not supported in the simulator"}, "message": "remote notifications are not supported in the simulator"}

anyone know how to solve it?

irwansyafani commented 3 years ago

I solved my issue with these :

For Direct Notification :

    PushNotificationIOS.addNotificationRequest({
      id: 'notificationWithSound',
      title: 'Sample Title',
      subtitle: 'Sample Subtitle',
      body: 'Sample local notification with custom sound',
      sound: 'customSound.wav',
      badge: 1,
    });

For Scheduled Notification :

    PushNotificationIOS.addNotificationRequest({
      id: 'test',
      title: 'title',
      subtitle: 'subtitle',
      body: 'body',
      category: 'test',
      threadId: 'thread-id',
      fireDate: new Date(new Date().valueOf() + 2000),
      repeats: true,
    });
AMINEDGE commented 8 months ago

To add a comment, be cautious about adding lines to AppDelegate.h and AppDelegate.mm based on document on the main page