-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First steps into starting onesignal on DidFinishLaunching event #38
Conversation
Hi @williamrijksen We have the method
And if I send and click to open a notification it works and I can see the User opened notification message on the Console! Awesome!
but inside
or
for example. Can you understand why we can't use "self" here? I really want to have this feature but I'm running out of ideas now. |
@chmiiller It's a class method, so there is no |
@hansemannn @chmiiller I created a way to get the module instance, but it looks like the opened/received events are not always triggered. I'm looking forward for a better solution, do you have some suggestions? |
instance = nil; | ||
// release any resources that have been retained by the module | ||
[super dealloc]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it ARC ;-)
Thanks guys! It makes sense. Now the
is false. Is it because we shouldn't use Update: Update 2
And then, |
@chmiiller Cool! Would we introduce |
Guys, please check this PR for a solution that does not require delays. |
Thanks @hansemannn but I can't understand what we're missing. As far as I see, One Signal SDK has implemented it already here: https://github.com/OneSignal/OneSignal-iOS-SDK/blob/01a340b9a86fb2add5a7407da763bd615265d1b6/iOS_SDK/OneSignalSDK/Source/OneSignal.m |
@hansemannn @chmiiller This evening I worked on the NSNotificationCenter within this PR. I introduced a
The delay is necessary because otherwise there's something wrong with the event listeners. @hansemannn Do you know why that's delay is necessary? Thanks in advance! |
[super startup]; | ||
NSLog(@"[INFO] started %@", self); | ||
_instance = self; | ||
// [self performSelector:@selector(handleQueuedBootEvents) withObject:self afterDelay:10.0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hansemannn Do you know why this is not working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any selector for that message. But as you moved to queuing now, it should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, my bad. It should be launch
. When it's launch
, I see launch is being called, but the fireEvent is not working. When I call
launch` like this (#38 (comment)) it's working properly. Do you know why that's failing?
Sounds great! You have implemented what @hansemannn suggested, hope we manage to make it work somehow.
If we click the notification to start the app it prints |
@chmiiller For the null-checks, you could use the |
NSDictionary* notificationData = @{ | ||
@"title": title, | ||
@"body": body, | ||
@"additionalData": additionalData}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chmiiller This for example could be a dictionaty holding non-JS types like NSData
, so ensure to map those (in this example, an NSData
instance would be mapped with [[TiBlob alloc] initWithData:data mimetype:@"text/plain"]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you want to change? The additionalData
or the notificationData
?
@chmiiller If there's an |
Blocked by experiencing this issue: https://jira.appcelerator.org/browse/MOD-2249. @hansemannn @chmiiller do we have a workaround for this? |
Commented on the ticket why it is invalid and proposed a fix (use the delegate-pattern) for it. Same would apply for this one, with the exact same reasons to avoid the race-condition. |
-(void)notificationOpened:(NSNotification*)info | ||
{ | ||
if (_instance != nil) { | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use TiDispatchOnMainThread
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hansemannn is this a method or something else? I can't find anything in the titanium_mobile repository with the name TiDispatchOnMainThread
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it.... I think you meant TiThreadPerformOnMainThread
@"body" : [[info userInfo] valueForKey:@"body"], | ||
}]; | ||
NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE notificationOpened: %@" , event); | ||
[self fireEvent:TiNotificationOpened withObject:event]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the proxy has listeners first, e.g if ([self _hasListener:fireEvent:TiNotificationOpened])
@hansemannn we've updated the PR by removing the NSNotification approach and replace it with a delegate pattern solution. The code is now way cleaner, but in the end we face the same problem. The event is not fired. Once the fireevent is executed, we end up here: Do you have any tips why this could happen? It has do something with context.... but what? Should we create separate TiProxy based class with its own context to be able to overcome this issue? |
ios/Classes/OneSignalManager.m
Outdated
@"title": title, | ||
@"body": body, | ||
@"additionalData": additionalData}; | ||
[self.delegate notificationReceived:notificationData]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williamrijksen a copy and paste issue here... this should be notificationOpened
OK the non firing events only seem to be an issue on 5.5.1, not 6.1.1. @chmiiller could you test this PR as well? I have successful results now on 6.1.1. |
@williamrijksen @jvandijk You got me between two holidays. The reason that the event was not firing (the loopCount was 0, there were no event listeners) is because the proxy did not load up at the state that you trier to communicate with it. That's also the reason we handle background-notifications and background services in the ‘booted‘ delegate and moved from timeouts to that solution recently. Not 100 % sute if that was in 6.1.x, but the change may also affect / fix other state-related issues like the one you had. Let me know if 6.1.1/6.1.2 works for everyone now, I'll return tomorrow 🏄. |
I also tried to build it because travis-ci got an error. I can not build last commit with error.
But, Its one pre-commit is no problem, build is successful. |
@hansemannn thanks for replying / @gimdongwoo thanks for testing. I think I've found a way combining OneSignal and the structure of Titanium that fits. When all listeners are setup, the notification is handled via the OneSignal library. Unfortunately OneSignal doesn't expose the way they create their notification data structure, so I had to replicate that. Due to taking this approach, the code became way simpler again. Hopefully this works out for everyone. |
awesome! Looking forward to see it. @gimdongwoo maybe you're not able to build it because of the /platform/OneSignal.framework missing in your "xcodeproj" file. You can open the Xcode Project and import the OneSignal.framework again. This should fix your issue. |
Context
#28.
What has been done
UIApplicationDidFinishLaunchingNotification
, because it looks like it has missing context.promptForPushNotificationsWithUserResponse
to skip thedidRegisterForRemoteNotificationsWithDeviceToken
methodonAppCreate
How to test
Todo
onesignal.promptForPushNotificationsWithUserResponse
Notes
[iOS] Thenotificationopened
/notificationreceived
is broken since it's removed (see todo)