Notifications Tutorial

Notifications Tutorial
0

It’s finally here, the plugin for our Cocos Helper allowing you to use Notifications.

ATM the Helper has iOS C++ and JavaScript local notifications with Android coming soon.

Firstly setup Cocos Helper using one of the following links:

Once your setup, using push notification is ridiculously easy with just a single line of code

C++
SonarCocosHelper::Notifications::scheduleLocalNotification( delay, text to display );
e.g.
SonarCocosHelper::Notifications::scheduleLocalNotification( 5.0, “You now have a new life” );

JavaScript
SonarCocosHelper.Notifications.scheduleLocalNotification( delay, text to display );
e.g.
SonarCocosHelper.Notifications.scheduleLocalNotification( 5.0, “You now have a new life” );

Delay - is how long after the local notification is shown
Text to display - the text that the notification displays to the user

3 Likes

I didn’t use your tutorial still, but I have a suggestion…
It would be essential feature that I can unschedule or reschedule a notification. In android you give any notification a key for this purpose.

Hope for a comprehensive Notification System Tutorial from you soon :smile:

Thank you for your feedback.

Would it be possible to get support for hooking into when the application is launched/foregrounded by touching a notification? Perhaps even allowing us to provide associated user data for a notification.

Also push notification support? :wink:

Notification system has now been updated to supported unscheduling and notification repeating along with a custom lock screen slide message.

Could you explain this in more depth as we don’t quite understand what you are asking for.

Push notification is also coming :smiley:

Use case:

  • User buys castle upgrade, upgrade will take 2 hours.
  • We register notification with userdata=“castleupgrade”.
  • User closes application and 2 hours later a notification pops up.
  • User touches notification which launches application
  • Application receives (or polls) an event stating it was opened by a notification carrying userdata=“castleupgrade”
  • Instead of showing the normal initial screen we direct the user straight to castle UI and display a celebration animation

OK, the current notification system has all of that apart from userdata on the notification as the delay parameter allows notifications to be called x amount of time in the future. userdata sounds really cool. I will start working on it immediately.

1 Like

Wow ! You’re wonderful !

1 Like

:smiley: thank you very much

Hy @almax27 did you achieve this thing ?

We are still working on it.

What about Android support? @SonarSystems

It will have both :smiley:

@SonarSystems is this open-sourced? i think, we should get helps from all… :slight_smile:

It is indeed, feel free to add to it https://github.com/SonarSystems/Cocos-Helper

for cocos2d-x(c++) & android

I used below code in AppDelegate.cpp

void AppDelegate::applicationDidEnterBackground() {
SonarCocosHelper::Notifications::scheduleLocalNotification(0,"test","now",1234);
Director::getInstance()->stopAnimation();
}

but in my android phone, noting was happened

so, i checked your SonarFrameworks.cpp

void Notifications::scheduleLocalNotification( float delay, cocos2d::__String textToDisplay, cocos2d::__String notificationTitle, cocos2d::__String notificationAction , int notificationTag )
{
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    #if SCH_IS_NOTIFICATIONS_ENABLED == true
    IOSCPPHelper::scheduleLocalNotification( delay, textToDisplay, notificationTitle, notificationAction ,notificationTag);
#endif
#endif
}

Where is code for android platform??
is it work without any code? or something i misunderstood??

Android support isn’t available ATM.