diff --git a/YouTube/Helpers/GlobalVariables.swift b/YouTube/Helpers/GlobalVariables.swift index f739f4d..fc0aa06 100644 --- a/YouTube/Helpers/GlobalVariables.swift +++ b/YouTube/Helpers/GlobalVariables.swift @@ -67,3 +67,14 @@ func requestSuggestionsURL(text: String) -> URL { let url = URL.init(string: "https://api.bing.com/osjson.aspx?query=\(netText)")! return url } + +func showNotification() { + let alert = UIAlertController(title: "Oops!", message:"Please check your internet connection", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in }) + let navigationController = UIApplication.shared().windows[0].rootViewController as! UINavigationController + let activeViewCont = navigationController.visibleViewController! + activeViewCont.present(alert, animated: true, completion: nil) +} + + + diff --git a/YouTube/Model/User.swift b/YouTube/Model/User.swift index 9777240..dd758cd 100644 --- a/YouTube/Model/User.swift +++ b/YouTube/Model/User.swift @@ -41,10 +41,10 @@ class User { let user = User.init(name: name, profilePic: profilePic, backgroundImage: backgroundImage, playlists: playlists) completition(user) } catch _ { - print("failed to fetch data") + showNotification() } } else { - print("Please check your internet connection") + showNotification() } }.resume() } diff --git a/YouTube/Model/Video.swift b/YouTube/Model/Video.swift index 01097ea..26bff1e 100644 --- a/YouTube/Model/Video.swift +++ b/YouTube/Model/Video.swift @@ -69,7 +69,7 @@ class Video { suggestedVideos: suggestedVideos) completiotion(video) } catch _ { - print("error downloading video") + showNotification() } } }.resume() diff --git a/YouTube/Model/VideoItem.swift b/YouTube/Model/VideoItem.swift index 6d01699..110a347 100644 --- a/YouTube/Model/VideoItem.swift +++ b/YouTube/Model/VideoItem.swift @@ -25,13 +25,13 @@ class VideoItem { var items = [[String : AnyObject]]() URLSession.shared().dataTask(with: fromURL) { (data, response, error) in if error != nil { - print("Please check your internet connection") + showNotification() } else{ do{ let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) items = json as! [[String : AnyObject]] } catch _ { - print("error fetching the feed") + showNotification() } completition(items) }