Closed Adesh closed 7 years ago
+1 on this issue.
@Adesh you found any workarounds?
@stillalive not yet.
I think the device event isn't called because listener events doesn't add when app kill & open again (guess). Should check if listener events have been added or not..
When app killed: Maybe the thread setBridge function in RCTOneSignal.m doesn't run. remoteNotificationOpened / handleRemoteNotificationReceived doesn't fire => handle something in didReceiveRemoteNotification
Please try upgrading to version 2 and see if the problem persists?
@avishayil it still occurs on version 2.0.0
Can you please set up an example project which the issue persists?
Thanks you very much @avishayil . I created a refresh project and it works now. Then I try to remove a line by line in my code. I found the problems => OneSignal.sendTag("userId", userId); in componentDidMount.
class PushNotificationsController extends React.Component {
....
componentDidMount () {
const { userId, dispatch } = this.props;
OneSignal.configure({
onIdsAvailable: (device) => {
this.setState({oneSignalId: device.userId});
},
onNotificationReceived: (notification) => {
if (notification.isAppInFocus) {
this.processPushType(notification.payload.additionalData, notification.payload.body, notification.isAppInFocus);
}
},
onNotificationOpened: (openResult) => {
const { notification } = openResult;
this.processPushType(notification.payload.additionalData, notification.payload.body, notification.isAppInFocus);
}
});
// OneSignal.sendTag("userId", userId);
if (Platform.OS === 'android') {
OneSignal.inFocusDisplaying(0);
}
}
...
render () {
return <View />; // null;
}
}
@congnguyen91 Glad you sorted it out!
Are you able to use sendTag
outside componentDidMount
?
Yes, I am @avishayil . I don't know what happen But the first screen contains a map view which should finish loading before do something like routing to second screen. I guess that some function of OneSignal need prepare something. Maybe it lacks of condition for running these functions.
I appreciate that this module has used 'autoregister' before. I suggest that it should remove asking permission when init or add another option. When Notification feature is used, It asks permission automatically.
- (id)initWithLaunchOptions:(NSDictionary *)launchOptions appId:(NSString *)appId settings:(NSDictionary*)settings {
[OneSignal setValue:@"react" forKey:@"mSDKType"];
// [OneSignal initWithLaunchOptions:launchOptions
// appId:appId
// handleNotificationReceived:^(OSNotification* notification) {
// [self handleRemoteNotificationReceived:[notification stringify]];
// }
// handleNotificationAction:^(OSNotificationOpenedResult *result) {
// if (!curRCTBridge)
// coldStartOSNotificationOpenedResult = result;
// else
// [self handleRemoteNotificationOpened:[result stringify]];
// }
// settings:settings];
return self;
}
I found a problems. if request permission isn't accepted => 'OneSignal.configure' doesn't return result of 'onIdsAvailable'. So I think You should add a warning whether the configure failed or not. Another option is we can return a promise after requestPermission then we can config
requestPermission(permission).then((result) => {
OneSignal.configure({
onIdsAvailable: (device) => {
},
onNotificationReceived: (notification) => {
},
onNotificationOpened: (openResult) => {
}
});
})
Don't forget iOS will request permissions by default at the first run - but you can request the permissions later if you like.
If you want, you have checkPermissions
function which returns a callback, to use before calling configure:
let pushPermissions;
OneSignal.checkPermissions((permissions) => {
pushPermissions = permissions;
});
if (pushPermissions == 'something valid') {
OneSignal.configure({
...
});
}
I can't figure this out either. Same problem but anyone have an idea the general reason why it gets frozen at the white screen when someone opens a notification after the app has been killed?
I see LaunchScreen after OneSignal was initialised and nothing helped. Main thread is waiting for something...
[OneSignal initWithLaunchOptions:launchOptions
appId:@"id"
handleNotificationReceived:^(OSNotification *notification) {
NSString *title = notification.payload.title;
NSString *body = notification.payload.body;
if (title && body) {
[UIAlertView showWithTitle:title message:body];
}
}
handleNotificationAction:^(OSNotificationOpenedResult *result) {}
settings:@{kOSSettingsKeyInFocusDisplayOption: @(OSNotificationDisplayTypeNone)}
];
same problem here, can't find a proper solution for it, anyone managed to solve it? or a workaround?
@rwkyyy I found that it can be when user deny push notifications or on simulator. If you start check if pushs is allowed before OneSignal configure it will work
@Screon I have the push notifications allowed (real device - testflight), but if the app is killed, it will just open a white screen 😓
@rwkyyy even if you comment OneSignal initWithLaunchOptions
? Try to completely turn it off. May be OneSignal is not your problem.
I'm having the same issue. Anything that can solve it?
@Screon I don't have any iniWithLaunchOptions
😕
In my case, the problem was from OneSignal.configure(); function. I used OneSignal.addEventListener(); function instead.
@nanokid same here, can confirm that.
For me it appeared to have something to do with some navigation in the app. Removing OneSignal.configure() fixed the issue for you?
Yes, this resolved my issue
Thanks @nanokid, that's quite curious though!
@dprogramming, I hope this is useful for you
I didn't have a chance to try it yet, but I hope so too! I already found a workaround, but it's quite ugly, so if this works I can change that. Thank you very much!
For anyone that comes here via Google, OneSignal.configure
is no longer valid, use addEventListener
like the README says. 👍
Notifications work correctly while opening it when the app is in the background state. However doing the same when the app is killed makes the UI unresponsive and the white screen appears. (in android everything works perfectly)