Reputation: 157
sorry for all the questions im new to iOS but im wondering is it possible to set a time frame in iOS for example if user push button call me between the time 6am - 6pm the dialer opens and makes the phone call to a nr 567895432 but if it is after hours for example between 6,01pm - 7,59am if button call me pushed the user would call 89780324, I know this is possible on php if I should create a Webview app but this is a native app and I don't really want to access a data base just a simple 2way app that sends requests, thank you in advance
Upvotes: 0
Views: 77
Reputation: 624
In swift 3.0
var components: DateComponents? =
Calendar.current.dateComponents(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit, from: Date())
var currentHour: Int? = components?.hour
var currentMinute: Int? = components?.minute
var currentSecond: Int? = components?.second
if (currentHour > 6) && (currentHour < 18) {
call
567895432
}
else {
call
89780324
}
Upvotes: 0
Reputation: 374
If I understood it correctly,On button tap, you want to call two different numbers based on time. Why don't you check on button press
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currentHour = [components hour];
NSInteger currentMinute = [components minute];
NSInteger currentSecond = [components second];
if ((currentHour > 6) && (currentHour < 18)) {
call 567895432
}
else{
call 89780324
}
Upvotes: 3