I'm writing a method to consume data from the web-service. I wrote this method inside a class(common class), so I can use this class in any viewController
to consume data. Inside this method, I check for the internet connection. If some failure occurs, I want to display an alert with the error description. This is my code inside my method:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
mainSession = [NSURLSession sharedSession];
mainDataTask = [mainSession dataTaskWithRequest:MainRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
UIAlertController *alertOne = [UIAlertController alertControllerWithTitle:@"Something Wrong!" message:[error description] preferredStyle:UIAlertControllerStyleAlert];
// I want to show alert here
}
}];
});
This method is in my common class(NSObject). If something wrong with the connection, inside this block I want to show the error. How can I do that?