0
我的應用程序是一個VOIP電話工具箱。UISwitch調用失敗的Restful API調用,想要恢復UISwitch值
我有一系列UISwitch控件,用戶可以使用這些控件來更改它們的設置,例如,如果他們想要更改其來電者ID設置。
當用戶更改設置時,我需要通過其Restful API調用Telephony平臺。如果Restful呼叫失敗,那麼我想將交換機重置回其先前的設置。例如,如果用戶打開了主叫方ID,並且由於連接失敗而失敗,我希望該交換機恢復爲關閉狀態。
我在我的switchChangedValue方法中實現了它,但是它創建了一個令人討厭的循環。當發生故障時,我將UISwitch設置爲其先前的設置,但又將其再次調用switchChangedValue方法,從而導致循環失敗等等
這是我的switchChangedValue方法的一部分,歡迎提供任何想法。
//Check if its a valid response from the XSI server
if ([bs getHTTPResponseCode] >= 200 && [bs getHTTPResponseCode] < 300) {
//This is the successful case
}
else
{
// I throw an alert here
//Id really like to change the UISwitch back if it goes wrong but it causes a bad loop.
if (buttonstate == false){
[switchbutton setOn:YES animated:YES];
//This invokes my switchChangedValue again
}
else if (buttonstate == true){
[switchbutton setOn:NO animated:YES];
//This invokes my switchChangedValue again
} else{
NSLog(@"Something went bad");
}
[bs release];
不是真的,如果用戶手動關閉開關,那麼我需要進行API調用,以在Voip平臺上設置關閉。 –
更新!這應該有所幫助。 – codykrieger