2017-05-23 55 views
0

抱歉所有的問題,即時消息新的iOS,但我想知道是否有可能設置iOS的時間框架,例如,如果用戶按鈕打電話給我之間的時間上午6時至下午6時撥號程序打開並打電話給號碼567895432,但如果是在幾小時之後,例如在6,01pm - 7,59am之間 如果按鈕打電話給我,推送用戶會打電話給89780324,我知道這是可能的PHP如果我應該創建一個Webview應用程序,但這是一個本地應用程序,我並不想訪問數據庫只是一個簡單的2way應用程序發送請求, 謝謝你提前如何打電話給2個號碼取決於時間

+0

對不起我的意思是6;下午1點 - 5; 59am – davie

+0

沒有你的默認撥號器 –

回答

3

如果我正確理解它,按鈕點擊,你想根據時間撥打兩個不同的號碼。 你爲什麼不檢查按下按鈕

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 
    } 
+0

不能那是一個好主意,讓我們感謝我嘗試一下 – davie

0

在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 
} 
相關問題