iphone - How to initialize local notification? -
i want implement local notification in clock app.basically want music file should played after every half hour in ship's clock in chimes played after every 30 minutes.
can give rough idea how can implement functionality when app enters in background?
i used local notification stuff , used following functions
//setting local notifications
for (int i= 1 ; i<=10; i++) { //we here set 10 notification after every 30 minutes can modify accordingly nsdate *scheduled = [[nsdate date] datebyaddingtimeinterval:60*30*i]; //these seconds nsdictionary* datadict = [nsdictionary dictionarywithobjectsandkeys:scheduled,fire_time_key,@"background notification received",notification_message_key,nil]; [self schedulenotificationwithitem:datadict]; }
where schedulenotificationwithitem defined
- (void)schedulenotificationwithitem:(nsdictionary*)item { uilocalnotification *localnotification = [[uilocalnotification alloc] init]; if (localnotification == nil) return; localnotification.firedate = [item valueforkey:fire_time_key]; localnotification.timezone = [nstimezone defaulttimezone]; localnotification.alertbody = [nsstring stringwithformat:nslocalizedstring(@"%@", nil), [item valueforkey:notification_message_key]]; localnotification.alertaction = nslocalizedstring(@"view details", nil); localnotification.soundname = uilocalnotificationdefaultsoundname; localnotification.userinfo = item; [[uiapplication sharedapplication] schedulelocalnotification:localnotification]; [localnotification release]; }
finally can handle these notifications
you can handle these notifications follows
- (void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification { // required work can obtain additional info via notification.userinfo happens dictionary }
reading developer documentation more understand stuff.hope helps
Comments
Post a Comment