added alertView
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Video {
|
||||
suggestedVideos: suggestedVideos)
|
||||
completiotion(video)
|
||||
} catch _ {
|
||||
print("error downloading video")
|
||||
showNotification()
|
||||
}
|
||||
}
|
||||
}.resume()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user