J. Doe
J. Doe

Reputation: 671

React-native - Alert.alert, unrecognized selector sent to instance

For unknown reasons my Alert.alert refuse to work. I am basically reusing the code from earlier where it is working. Getting the error:

Exception NSArrayl length; unrecognized selector sent to instance 0x170623440 was thrown while invoking alertWithArgs on targer Alertmanager with params.

Thanks

acceptFriendRequest(friendsName){
    Alert.alert(
      friendsName + ' wants to add you',
      [
        {text: 'Decline', onPress: () => console.log('Cancel Pressed'), style: 'cancel',
      },
      {text: 'Accept', onPress: () =>  this.confirmFriendRequest(this), style: 'accept'},

    ],
    )
  }

Upvotes: 1

Views: 2968

Answers (1)

Roy Wang
Roy Wang

Reputation: 11260

You need to pass the second argument (the alert body message), which you can use undefined/null if you don't need a body message:

Alert.alert(`${friendsName} wants to add you`, undefined, [
  {
    text: 'Decline',
    onPress: () => console.log('Cancel Pressed'),
    style: 'cancel',
  },
  { text: 'Accept', onPress: () => this.confirmFriendRequest() },
]);

You might need to close your app fully and restart it after applying the changes due to a bug in RN.

Also note:

  • style: 'accept' is not valid and will be ignored.
  • you don't need to pass this as argument to this.confirmFriendRequest().

Upvotes: 1

Related Questions