0

I want to set local Notification notify the message on every week when application is installed and notification message will be randomisation.

// Notification Random Message Array
    messgeArray = [NSMutableArray arrayWithObjects:@"Welcome",@"Hello",@"How about you",@"Good Day",nil];

// Notification for Every Week

  NSDate *date = [NSDate date];
    NSDate *oneDaynotification = [date dateByAddingTimeInterval:60*60*24*7];
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
    srand((unsigned)time(NULL));
    localNotification.fireDate = oneDaynotification;
    randomMessage = [messgeArray objectAtIndex:arc4random() % [notificationArray count]];
    localNotification.alertBody = randomMessage;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

After i change my system time i do not see any notification message, Can any one advice me how to implement a Notification trigger every week with random notification message with it.

kiran
  • 4,285
  • 7
  • 53
  • 98

1 Answers1

0

The problem is you are depending on the phone's time and date. For your purpose, you might have to connect to some server to get date time. There is another problem which you might come across, that is if the user doesn't open the app then, your app might not run any code hence won't show any notification.

1.So the solution will be setting up a push notification server. So here is what you can do :

  • Setup a push notification to the server and iDevice(Tutorial).
  • Make a logic for in the server such that first time the app registers and sends the device token id, save the date time also.
  • And run a Cronjob(what is it?) application in a server which will take the date and time and send messages based on the device token.

2.And in case you want to do it in the phone itself without depending upon server then. Here are the things you have to concern :

  • Make a logic, to save the date and time in database or user preferences.
  • Add any of the background services to awake the app from the suspended mode once every day.
  • Calculate the date and show push notification.
Community
  • 1
  • 1
MD Aslam Ansari
  • 1,565
  • 11
  • 19
  • In my case there is no push notification will be used. – kiran Aug 18 '16 at 07:46
  • Ok then you might have to use database to save the date time first time it runs and check every day if from saved date 6 days have passed or not. Use CLVisit and locaiton service to awake the app every day once. – MD Aslam Ansari Aug 18 '16 at 07:51