1

Hello every one, I want to update my local database every morning 10.00 AM. it doesn't matter that application is running or killed or in background. is there any mechanism in IOS like service class in android or anything?

I know we can achieve this by using Local Notification but Is there a way to do this without using Local Notifications?

Bandish Dave
  • 791
  • 1
  • 7
  • 27
  • First of all we cant do updation if our app is not running , and how can you achieve this using localNotification because updation process can't be done until u click on notification and app opens. – baydi Sep 03 '15 at 11:21
  • @baydi please carefully read above question first....and i know very well how local notification is work ...http://stackoverflow.com/questions/16653991/calling-a-method-at-specific-time-every-day ... refer this link.... – Bandish Dave Sep 03 '15 at 11:33

2 Answers2

1

It seems that you need Silent Push Notification, but in this case the schedule should be on your server.

AlexZd
  • 2,152
  • 2
  • 18
  • 29
-1

You cannot achieve this..

As Apple is not allow to run any method continuously even the app is in Background...

Only solution is to use local notifications.

I know you are don't what to use Local Notifications but I am keeping code that might be helpful...

ViewController.m

UIApplication* app = [UIApplication sharedApplication];
    NSArray*    oldNotifications = [app scheduledLocalNotifications];

    if ([oldNotifications count] > 0)
        [app cancelAllLocalNotifications];

    NSCalendar* myCalendar = [NSCalendar currentCalendar];
    NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit
                                          fromDate:[NSDate date]];

    [components setHour: 10];
    [components setMinute: 00];
    [components setSecond: 0];
     NSDate *alertTime = [myCalendar dateFromComponents:components];

    NSLog(@"@@@@@@@@@@@@Local Notification Set Time is:%@",alertTime);

    UILocalNotification  *notifyAlarm = [[UILocalNotification alloc]
                   init];
    if (notifyAlarm)
    {
        notifyAlarm.fireDate = alertTime;
        notifyAlarm.userInfo=[[NSDictionary alloc]initWithObjectsAndKeys:@“ViewController”,@“Home”, nil];
        //notifyAlarm.applicationIconBadgeNumber=1;
        notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
        notifyAlarm.repeatInterval = NSHourCalendarUnit;
        notifyAlarm.soundName = @"iPhone_Tritone.mp3";
        notifyAlarm.alertBody = @“Calling Method”;
        [app scheduleLocalNotification:notifyAlarm];
    }

AppDelegate.m

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    NSLog(@"@@@@@@@@@@Did Receive Local Notification@@@@@@@@@@@ is:%@",notification.userInfo);

    [self callingUrMethod];
}

Else you achieve it by using Push Notifications to be fired by server everyday at 10AM based on iPhone Device Time...

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59