【问题标题】:how to make call to 2 numbers depending om the time如何根据时间拨打2个号码
【发布时间】:2017-05-23 12:23:03
【问题描述】:

抱歉,对于 iOS 新手的所有问题,但我想知道是否可以在 iOS 中设置时间范围,例如,如果用户在早上 6 点到下午 6 点之间按下按钮呼叫我,拨号器打开并拨打电话给 nr 567895432 但如果是下班后,例如下午 6,01 - 早上 7,59 如果按下按钮调用我,用户将调用 89780324,我知道如果我应该创建一个 Webview 应用程序,这在 php 上是可能的,但这是一个本机应用程序,我真的不想访问数据库,只是一个简单的 2way 应用程序发送要求, 提前谢谢你

【问题讨论】:

  • 对不起,我的意思是下午 6:01 - 早上 5:59
  • 不,你不能使用默认拨号器

标签: ios objective-c native


【解决方案1】:

如果我理解正确,点击按钮,您想根据时间拨打两个不同的号码。 你为什么不检查按钮按下

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
    }

【讨论】:

  • 嘿,兄弟,因为争论而发自内心的抱歉...感谢纠正我。
【解决方案2】:

在 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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多