added alertView

This commit is contained in:
Haik Aslanyan
2016-08-08 20:45:24 +04:00
parent a2c0f4e805
commit f2afd02f6b
4 changed files with 16 additions and 5 deletions
+11
View File
@@ -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)
}
+2 -2
View File
@@ -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()
}
+1 -1
View File
@@ -69,7 +69,7 @@ class Video {
suggestedVideos: suggestedVideos)
completiotion(video)
} catch _ {
print("error downloading video")
showNotification()
}
}
}.resume()
+2 -2
View File
@@ -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)
}