title: How to set the alarm in iPhone and save in local notification?
body: <p>I am creating an alarm application in iPhone which makes use of SQLite and local notification. I have class with tableview which contains 4 rows for selecting time,repeat interval, sound etc. When I select all these factors these are stored in  global variables.</p>
  
  <p>In my tableview where I am selecting these rows I have a save button. When I click on the save button after choosing the particular rows the values of time, repeat and sound are saved in SQLite database through this global variables. Now I am passing this variables to my notification objects so that alarm should get set when I click on the save button. But notification is not getting set.</p>
  
  <p>This is my code for notification:</p>
  
  <pre><code>//
  //  TAddAlarmController.m
  //  StopSnooze
  //
  //  Created by raji.nair on 7/18/11.
  //  Copyright 2011 __MyCompanyName__. All rights reserved.
  //
  
  #import "TAddAlarmController.h"
  //#import "CustomCell.h"
  #import "StopSnoozeAppDelegate.h"
  #import "Alarm.h"
  #import "TAlarmNewController.h"
  #import "global.h"
  #import "TTimePickerController.h"
  #import "TAlarmSoundController.h"
  #import "AlarmMessageController.h"
  #import "TPenaltyController.h"
  #import "TSnoozeIntervalController.h"
  
  #define DATABASE_TITLE @"StopSnooze.sqlite"
  #define DATABASE_NAME @"StopSnooze"
  
  @implementation TAddAlarmController
  @synthesize dateFormatter;
  @synthesize am;
  @synthesize undoManager;
  @synthesize time;
  @synthesize tblView;
  @synthesize detailTxt;
  //@synthesize controller;
  
  
  #pragma mark -
  #pragma mark View lifecycle
  
  
  - (void)viewDidLoad {
  
  
      [super viewDidLoad];
      self.title = @"Add Alarms";
      newtemp = anew.temp;
      UIBarButtonItem * saveButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
          self.navigationItem.rightBarButtonItem = saveButton;
          [saveButton release];
  
  }
  
  
  -(void)schedulealarm
  {
      UILocalNotification *localNotif = [[UILocalNotification alloc] init];
      if (localNotif == nil)
          return;
      localNotif.fireDate = (NSDate*)lblDate.text;
  //lblDate.text is where my date is getting saved through the picker but in the fireDate it is showing null.
      localNotif.timeZone = [NSTimeZone defaultTimeZone];
  
      // Notification details
      localNotif.repeatInterval = (int)newrepeat;
  //newrepeat is the global variable where is select the repeat interval for alarm.
      localNotif.alertBody = newmessage;
      // Set the action button
      localNotif.alertAction = @"View";
  
      localNotif.soundName = UILocalNotificationDefaultSoundName;
      localNotif.applicationIconBadgeNumber = 1;
  
      if (localNotif == nil) {
          NSLog(@"Yes");
      }
      else {
          NSLog(@"Notification called");
      }
  
  
      // Specify custom data for the notification
      NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
      localNotif.userInfo = infoDict;
  
      // Schedule the notification
      [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
      [localNotif release];
  
  
  }
  
  
  - (void)viewDidUnload {
      // Release any properties that are loaded in viewDidLoad or can be recreated lazily.
      self.dateFormatter = nil;
  }
  -(void)saveInDatabase
  {
      app = (StopSnoozeAppDelegate*)[[UIApplication sharedApplication] delegate];
      [app copyDatabaseIfNeeded];
      NSString *filePath  =[app getDBPath];
      sqlite3 *database;
  
      NSTimeInterval timeStamp = [[NSDate date]timeIntervalSince1970];
      NSNumber *timeStampObj = [NSNumber numberWithInt:timeStamp];
      NSLog(@"%d",timeStampObj);
  
      AlarmID =(int)timeStampObj;
      NSLog(@"%@",AlarmID);
  
      NSDate *date = [NSDate date];
      NSDateFormatter *formatter = [[[NSDateFormatter alloc]init]autorelease];
      [formatter setDateFormat:@"HH:MM"];
  
      NSString *str = [formatter stringFromDate:date];
      NSLog(@"%@",str);
  
      if (sqlite3_open([filePath UTF8String], &amp;database) == SQLITE_OK) {
          const char *sqlStatement = "insert into AlarmsInformation(alarm_id,alarm_time,snooze_interval,sound_file,alarm_message) VALUES (?,?,?,?,?)";
          sqlite3_stmt *compiledStatement;
          if (sqlite3_prepare_v2(database,sqlStatement ,-1, &amp;compiledStatement,NULL) == SQLITE_OK) {
              //sqlite3_bind_text(compiledStatement, 1, [AlarmID UTF8String], -1, SQLITE_TRANSIENT);
              sqlite3_bind_int(compiledStatement, 1, AlarmID);
              sqlite3_bind_text(compiledStatement, 2, [lblDate.text UTF8String], -1, SQLITE_TRANSIENT);
              sqlite3_bind_int(compiledStatement, 3, databaseinterval);
              sqlite3_bind_text(compiledStatement,4 , [newsound UTF8String], -1, SQLITE_TRANSIENT);
              sqlite3_bind_text(compiledStatement, 5, [newmessage UTF8String], -1, SQLITE_TRANSIENT);
          }
          if (sqlite3_step(compiledStatement)!= SQLITE_DONE) {
              NSLog(@"Save Error:%s",sqlite3_errmsg(database));
          }
          else {
              sqlite3_reset(compiledStatement);
              UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Alarm Set" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
              [alert show];
              [alert release];
              alert = nil;
          }
          sqlite3_finalize(compiledStatement);
      }
      sqlite3_close(database);
  
  }
  
  -(IBAction)save{
  
      if (lblDate.text == NULL &amp;&amp; interval == NULL &amp;&amp; newsound == NULL)
      {
          UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Set Date,interval,sound for alarm" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
          [alert release];
          alert = nil;
      }
      else {
          [self saveInDatabase];
          [self schedulealarm];
      }
  
      //[self.navigationController popViewControllerAnimated:YES];
  }
  
  @end
  </code></pre>
  
  <p>And in the appDelegate I have created a method for didReceiveNotification. But notification does not work. My fire date shows null value.</p>
  
  <p>What might be the problem? I want to pass values to firedate that I stored in my variable.</p>