Local notifications – ShiVa Engine

Local notifications

Nav Gupta: “We got a head start luckily with http://stackoverflow.com/questions/8965695/ios-simple-local-notification-3-days-prior. We will be going over a SIMPLIFIED version of the code just to show you how to do a simple notification from ShiVa.”


First let us differentiate the two types of notifications. There is PUSH notification which requires your own server and approval from Apple to start doing client-server push notifications. If you are interested in this option, for now you can use the service from Urban Airship (http://www.urbanairship.com) which allows you free 1 million push notifications per month for your app, but you still need to register for Apple Push Notification Service (APNS).
There are LOCAL notifications sent by your app that is running on a device. Let us begin our tutorial on simple LOCAL iOS Notifications (These are the ones that show up with an icon and message outside of your app, even in the home screen when device is locked).


– NOTE: Local notifications will only work on an actual device and not the simulator.
– Complete previous HOOKS AND CALLBACKS tutorial for iOS
– We are going to assume you have created a function following the HOOKS AND CALLBACKS iOS for passing a value (STRING VALUE – specifically char *) using a function such as S3DEngine_sYourString ( ).

XCode Steps

Open up S3DEngine_EAGLView.m and on line 13 paste the following:


Go down to – (void) drawView (Line 259) and inside the function after the if ( S3DEngine_iPhone_Stopped ( ) ) statement on approx. line 372 type the following:

	if ( SINGLE_MSG == NO )
		// *******************
		// *******************
		// Create the local notification
		UILocalNotification *localNF = [[UILocalNotification alloc] init];
		// Check to see that the notification is not nil
		if (localNF == nil)
		// Chose the date to send the notification
		// (In this case we are firing it off IMMEDIATELY so it is a nil value)
		localNF.fireDate = nil;
		// Chose the timezone for the notification
		localNF.timeZone = [NSTimeZone defaultTimeZone];
		// Chose the notification message (Note: We are assuming your ShiVa argument you passed
		// is inside the function S3DEngine_sYourString ( ) for this example.)
		localNF.alertBody = [NSString stringWithUTF8String:S3DEngine_sYourString ( ) ];
		// Set the action to complete with the alert (We want it firing now so nil value is used)
		localNF.alertAction = nil;
		// Set the notification sound
		localNF.soundName = UILocalNotificationDefaultSoundName;
		// Set the notification number for icon
		localNF.applicationIconBadgeNumber = 0;
		// Schedule the notification accordingly
		[[UIApplication sharedApplication] scheduleLocalNotification:localNF];
		// This just makes sure we only run this code once in the main game loop

Save, Compile, and Test. If all was done correctly, simply exit your app and PULL DOWN the notification bar window (Drag your finger from top of screen on iPhone/iPad down) and you should see your notification listed there.

Need more answers?

  • slackBanner