Show set local notifications in table view

Discussion in 'iOS Programming' started by newtoiphonesdk, Feb 10, 2012.

  1. macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    Trying to get a tableview class set up to display local notifications that the user can set within the application.
    The view controller that sets the notification:
    Code:
    - (void)scheduleNotification {
    	
    	[reminderText resignFirstResponder];
    
    	Class cls = NSClassFromString(@"UILocalNotification");
    	if (cls != nil) {
    		
    		UILocalNotification *notif = [[cls alloc] init];
    		notif.fireDate = [datePicker date];
    		notif.timeZone = [NSTimeZone defaultTimeZone];
    		
    		notif.alertBody = reminderText.text;
    		notif.alertAction = @"Ok";
    		notif.soundName = UILocalNotificationDefaultSoundName;
    		notif.applicationIconBadgeNumber = 1;
    		
    		NSInteger index = [scheduleControl selectedSegmentIndex];
    		switch (index) {
    			case 1:
    				notif.repeatInterval = NSDayCalendarUnit;
    				break;
    			case 2:
    				notif.repeatInterval = NSWeekCalendarUnit;
    				break;
    			default:
    				notif.repeatInterval = 0;
    				break;
    		}
    		
    		NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
    												forKey:kRemindMeNotificationDataKey];
    		notif.userInfo = userDict;
    		
    		[[UIApplication sharedApplication] scheduleLocalNotification:notif];
    		[notif release];
    	}
    }
    viewDidLoad of the tableview class:
    Code:
     NSMutableArray * notifications = [[[UIApplication sharedApplication] scheduledLocalNotifications]mutableCopy];
    NSLog(@"%i", notifications.count);
    But, the log always returns 0. Any thoughts?
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    A wild guess, before going through all your code, is your firedate, AFTER you are logging the message? :)
     

Share This Page