chabokpush / chabok-client-rn

Chabok react native wrapper
https://doc.chabokpush.com/react-native-bridge/introducing.html
5 stars 5 forks source link

app will crash while on receiving notification #8

Open aminvb12 opened 5 years ago

aminvb12 commented 5 years ago

Hi first of all thanks for your support. My react-native app will crash & also freeze, sometimes while receiving notification but there is no error on xcode or react-native console ,just show : #11 0x000000010277162c in -[RCTEventEmitter sendEventWithName:body:] at /projectPath/projectName/node_modules/react-native/React/Modules/RCTEventEmitter.m:39 and : Thread 1: signal SIGABRT.

I will be thankful from your team if you answer my issue.

Husseinhj commented 5 years ago

Could you give us your notification payload? It helps us to find out what is the problem. For enabling the Chabok framework logs, Put this code in your iOS AppDelegate.m class.

[PushClientManager defaultManager].enableLog = YES;
aminvb12 commented 5 years ago

@Husseinhj Do you mean this ? screen shot 1397-06-08 at 18 06 18 2

Husseinhj commented 5 years ago

It's hard to find the exact notification payload. Did you send the notification with the Chabok panel or API?

If using the API so give me the notification payload here to see this or using the Chabok panel give me the JSON of data in push message.

aminvb12 commented 5 years ago

@Husseinhj I'm using sandbox api, here you are the payload :

[{
  "user": "apple09176062135",
  "content": "test",
  "inApp": false,
  "live": false,
  "useAsAlert": true,
  "alertText": "test",
  "notification": {
    "title": "test",
    "body": "test1",
    "sound": "string"
  }
}
]
Husseinhj commented 5 years ago

I think your app crashed when reloading the JS. This was only happening on Reload. If it's true I'll fix the iOS bridge in a new version.

NOTE: In your payload set sound key with a valid value. by default sound value is default.

NOTE: The Chabok platform by default get device type for sending a push notification with segmentation so you don't need to start your userId with the device type.

aminvb12 commented 5 years ago

@Husseinhj no!not only happening on Reload . This was happening meantime using an application. I mean sometimes i received notification , this will happen for me.

Husseinhj commented 5 years ago

I mean sometimes i received notification

If you give me the scenario it helps me to fix this. But you can update AdpPushClient.h file in node_module to this :

#import "React/RCTBridgeModule.h"
#import "React/RCTEventEmitter.h"

@interface AdpPushClient : RCTEventEmitter <RCTBridgeModule,RCTInvalidating>

@end

Test with this change.

aminvb12 commented 5 years ago

@Husseinhj Every time the application crash , after the application carsh i will see this : ../node_modules/react-native-chabok/ios/AdpPushClient.m: runtime: UI API called from background thread: -[UIApplication registerUserNotificationSettings:] must be used from main thread only

behrad commented 5 years ago

Are you calling any SDK methods in your app's background thread @aminvb12 ?

aminvb12 commented 5 years ago

@behrad No

behrad commented 5 years ago

This error shows that Chabok methods may have been called from background threads.

@aminvb12 Please give some details or a simulation of your code path (sample of how are you calling chabok methods) so that we can re-generate this.

And that method is not related to receiving notification. Make sure you are giving us correct details.

aminvb12 commented 5 years ago

@behrad Here is my javascript code we are calling to receive notification from chabok and we were checking user parameter not to be null.

init_chabok_notification = async()=>{
        const options = {
            "appId": "*************************",
            "apiKey": "/*/*/*/*",
            "username": "****",
            "password": "&&&&&",
            "isDev": true
        };

        let USER = await AsyncStorage.getItem('user');

        if(!USER){
            return
        }
        USER = 'apple'+JSON.parse(USER).username;
        // let phone = ;
        var channels = ["adv", "news" , USER ];
        this.chabok = new chabok.AdpPushClient();

        this.chabok.initializeApp('ashawash', options , (response) => {

        });

        const chabokEmitter = new NativeEventEmitter(NativeModules.AdpPushClient);

        chabokEmitter.addListener(
            'connectionStatus',
            (status) => {
                console.log('connectionStatus', status)
            }
        );

        chabokEmitter.addListener(
            'ChabokMessageReceived',
            (message) => {
                console.log("\nChabok Message Received :", message);
            }
        );
        this.chabok.register(USER, channels);
        this.chabok.addTag(USER)

// // subscribe to channel
//         this.chabok.subscribe(channels[0]).then(res => () => {
//             console.log(res);
//             alert('subscribe success');
//         });
    }
behrad commented 5 years ago

We will go through your code and test it @aminvb12

However I see some strange points in your code:

  1. Why are you appending apple prefix to your userIds? Chabok handles platform segmentation for you

  2. Why are you subscribing to USER channel? chabok already does this for you automatically

  3. You are adding USER tag! why?

  4. You also don't need to store USERID, chabok handles that. And that's not secure to store it plain text by application

Husseinhj commented 5 years ago

@aminvb12 Did you update the Chabok to the last version (v1.0.0)?

Husseinhj commented 5 years ago

@aminvb12 آیا مشکل شما حل شده است؟