Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:17:13+00:00 2026-06-18T11:17:13+00:00

I have the following code in ViewController.m : -(void) checker { UILocalNotification *notification =

  • 0

I have the following code in ViewController.m:

-(void) checker {
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    [notification setAlertBody: @"Im your local notification"];
    [notification setFireDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
    [notification setTimeZone: [NSTimeZone defaultTimeZone]];
    [UIApplication setScheduledLocalNotifications: [NSArray arrayWithObject: notification]];
}

The last line produces a warning:

Class method ‘+setScheduledLocalNotifications’ not found (return type defaults to id)

and it gives error while processing. How can I instantiate the notification? As I said I am new, if you can provide a complete answer it will be greatly appreciated.

Edit: I have a timer that repeats itself every 60 seconds and calls a function that puts a notification.

timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(checker) userInfo:nil repeats:YES];

/* ... */
-(void)checker {
    NSLog(@"Notification routine");
    UIApplication* app = [UIApplication sharedApplication];
    NSArray *oldNotifications = [app scheduledLocalNotifications];

    // Clear out the old notification before scheduling a new one.(if needed)
    if ([oldNotifications count] > 0)
        [app cancelAllLocalNotifications];

    // Create a new notification.
    UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
    if (alarm) {
        alarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.alertBody = @"Msg to show";
        [app scheduleLocalNotification:alarm];
    }
}

I can see the log only firing once a minute, but the oldNotifications count does not increase.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:17:14+00:00Added an answer on June 18, 2026 at 11:17 am

    This is how I do it,

    UIApplication* app = [UIApplication sharedApplication];
    NSArray *oldNotifications = [app scheduledLocalNotifications];
    
    // Clear out the old notification before scheduling a new one.(if needed)
    if ([oldNotifications count] > 0)
        [app cancelAllLocalNotifications];
    
    // Create a new notification.
    UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
    if (alarm)
    {
        alarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:60*60];//afterone hour
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Msg to show";
        [app scheduleLocalNotification:alarm];
    }
    

    update:

    - (void)scheduleAlarmForDate:(NSDate*)theDate andBody:(NSString*)Body
    {
        UIApplication* app = [UIApplication sharedApplication];
        NSArray *oldNotifications = [app scheduledLocalNotifications];
    
        // Clear out the old notification before scheduling a new one.
        if ([oldNotifications count] > 0)
            [app cancelAllLocalNotifications];
    
        // Create a new notification.
        UILocalNotification* alarm = [[UILocalNotification alloc] init];//Using ARC no autorelease
        if (alarm)
        {
            alarm.fireDate = theDate;
            alarm.timeZone = [NSTimeZone defaultTimeZone];
            alarm.repeatInterval = 0;
            alarm.soundName = @"alarmsound.caf";
            alarm.alertBody = Body;
            [app scheduleLocalNotification:alarm];
        }
    }
    

    now if I call this method twice,

     NSDate *fireDate1 = [NSDate dateWithTimeIntervalSinceNow:4.0];
    [self scheduleAlarmForDate:fireDate1 andBody:@"My alertBody 1"];
    
    NSDate *fireDate2 = [NSDate dateWithTimeIntervalSinceNow:6.0];
    [self scheduleAlarmForDate:fireDate2 andBody:@"My alertBody 2"];
    

    the first alarm will be canceled,,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have the following Code in my XMLAppDelegate.m file: - (void)applicationDidFinishLaunching:(UIApplication *)application { [self.window
I have the following code in viewWillAppear in my view controller. - (void) viewWillAppear:(BOOL)animated
I have the following code: -(void)textFieldDidBeginEditing:(UITextField *)textField { CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for loading image from url in xml parsing endElement method
I have following code for inserting data into database using PDO. It inserts data
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
I have following code that I am compiling in a .NET 4.0 project namespace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.