Question: So I have an app that runs on iOS 3.2 - 4.x. It uses ASIHTTPRequest to make all the REST API calls. Ever since my team and I upgraded three of our iPhone 4's to iOS 5, The app will hang and show the ActivityIndicator indefinitely. I looked at the server logs and the requests aren't hitting the server. 

However, if I press the iPhone home button then open the app again, the request will go through and I will receive the data, business as normal. For some reason the requests are never triggered until I reopen the app.

Another weird tidbit, the app works in Xcode 4.2 and the iPhone simulator. The app also works on an iPad2 with iOS 5 (the app is iPhone only). 

Would this be an ASIHTTPRequest issue? Not too sure how to pinpoint the issue since there is no crash and only happens on the phone.

Any insight would be much appreciated! Thanks.

Answer: 
If you are using a UISwitch, then as seen in the developer API, the task `setOn: animated:` should do the trick.

```
- (void)setOn:(BOOL)on animated:(BOOL)animated

```

So to set the switch ON in your program, you would use:

**Objective-C**

```
[switchName setOn:YES animated:YES];

```

**Swift**

```
switchName.setOn(true, animated: true)

```
Use this code to solve on/off state problem in switch in iOS

```
- (IBAction)btnSwitched:(id)sender {
    UISwitch *switchObject = (UISwitch *)sender;
    if(switchObject.isOn){
        self.lblShow.text=@"Switch State is Disabled";
    }else{
        self.lblShow.text=@"Switch State is Enabled";
    }                

```