0

I am implementing alarm functionality for Apple's Watch application. So here I have to compare current time with user time and I have to get current time for every 1 sec, so that I have implemented the code like below but this is not working. Can any body please post appropriate code in Objective-C..

for (int i=0; i<86400; i++)
{  
    if ([getTotalDate isEqualToString:self.curTime])
        {
            NSLog(@"It's Alarm Time");
            [self presentControllerWithName:@"FifthViewController" context:nil];
            break;
        }
    else
        {
            NSLog(@"not alarm time");
            //[self currentTime];
        }
}
David Walschots
  • 12,279
  • 5
  • 36
  • 59

2 Answers2

0

The best way is to set Local Notification for that particular time. And you should open FifthViewController in didReceiveLocalNotification. You can check the answer of following for how to use local notifications.

How to implement LocalNotification using objective C?

Nikunj Damani
  • 753
  • 3
  • 11
  • Hi..Thanks for your reply ..actually I am implementing this for apple watch. So can you please suggest me how to implement alarm functionality through local notifications for Apple Watch.. – Pradeep Sharma Mar 16 '18 at 11:36
  • here it was not mentioned so how I could know that it's apple watch program. You can check this link for apple watch notifications. https://www.natashatherobot.com/watchkit-actionable-notifications/ – Nikunj Damani Mar 16 '18 at 11:56
-1

Try using Stride

Here is an Apple provided solution (loop iteration over time constraints): Swift control flow with Stride

Some users might want fewer tick marks in their UI. They could prefer one mark every 5 minutes instead. Use the stride(from:to:by:) function to skip the unwanted marks.

let minuteInterval = 5
for tickMark in stride(from: 0, to: minutes, by: minuteInterval) {
    // render the tick mark every 5 minutes (0, 5, 10, 15 ... 45, 50, 55)
}



let hours = 12
let hourInterval = 3
for tickMark in stride(from: 3, through: hours, by: hourInterval) {
    // render the tick mark every 3 hours (3, 6, 9, 12)
}
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • @Tj3n - Yes dear, I know, but OP has added a tag `swift` and he may use Swift code in Objective-C project also. And apple may not have provided this solution in Objective-C. So if OP can inject Swift code in Objective-C project, then this can be helpful to him. – Krunal Mar 16 '18 at 11:29
  • Hi..Thanks for your reply.. Actually I am developing in Objective C, So is this stride is there in objective c also? if yes can you please post code in objective c.. – Pradeep Sharma Mar 16 '18 at 11:54