Alert Message

Hi


I am calling WebService in ViewdidLoad . I want if data is not returned in some seconds then some message should be displayed.


Thanks

Replies

Can you show some code ? Have you implemented a requestFinished and a requestFailed func ?


Why do you want to do this and not wait for the alert to complete of fail and then let user know what is going on ?

The requests are executed asynchornously in another thread, so with your design you will risk creating some mess, alerting and then request will complete just a few seconds later !

Hi


I have the below code and called on ViewDidLoad. I want if it takes some tike say 10-15 sec to load some message should appear.

func webserviceMethod1()
    {
        SVProgressHUD.show(withStatus: "Loading...")
        let strURL = "https://www.ser.com/affiliate/WebAPI/member-api.php?module=product-details&p_tab=2"
        Alamofire.request(strURL, method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response:DataResponse) in
           switch(response.result) {
            case .success(_):
                if let data = response.result.value{
                    self.arrImages1 = (data as! NSDictionary).value(forKey: "result") as! NSArray
                    self.tstArray = self.arrImages1
                    self.itemsPerRow = CGFloat(self.arrImages1.count);
                    self.clcView1.reloadData()
                }
                break
               
            case .failure(_):
                print(response.result.error)
                SVProgressHUD.dismiss()
                break
            }
        }
    }

Thanks

Is the completion closure you’re passing in to your networking layer running on the main thread? If not, you’re breaking UIKit’s threading rules (UIKit is, for the large part, main thread only) and weird long delays in updating the UI is a common symptom of that.

If you’re using Xcode 9 beta you can enable the super cool main thread checker (via the Main Thread Checker checkbox of the diagnostics tab of your Run scheme). If you’re on an older Xcode, add the following line to your completion closure.

assert(Thread.isMainThread)

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"