Guest User

Untitled

a guest
Jan 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. 2019-01-18 14:02:32.251806-0500 Jama3aV2[35603:8067503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C17.1:2][0x10254c2e0] get output frames failed, state 8196
  2. 2019-01-18 14:02:32.252321-0500 Jama3aV2[35603:8067503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C17.1:2][0x10254c2e0] get output frames failed, state 8196
  3.  
  4. @IBAction func handlePostButton(_ sender: Any) {
  5.  
  6. guard let image = desciptionImage.image else {return}
  7.  
  8. var currentLocation: CLLocation!
  9. if (CLLocationManager.authorizationStatus() == .authorizedWhenInUse || CLLocationManager.authorizationStatus() == .authorizedAlways){
  10. currentLocation = locationManager.location
  11. }
  12.  
  13. //Need to specify the area of ryerson.
  14. // if ((currentLocation.coordinate.longitude < 43.657821 && currentLocation.coordinate.longitude > 43.656258 ) && (currentLocation.coordinate.latitude < -79.380299 && currentLocation.coordinate.latitude > -79.37842 )) {
  15.  
  16. self.uploadProfileImage(image, completion: { (url) in
  17. guard let url = url else {return}
  18. guard let userProfile = UserService.currentUserProfile else { return }
  19. var postID: String!
  20. //Lets make a reference to the database
  21. var postref: DatabaseReference!
  22.  
  23. //Check which view its coming from
  24. if self.cityLocationInNewPost?.school == nil {
  25. postref = Database.database().reference().child("posts/school/((self.school)!)").childByAutoId()
  26. postID = "((postref)!)"
  27. print("The post ID (String(describing: postID))")
  28. postID = postID.replacingOccurrences(of: "https://jama3a-version2.firebaseio.com/posts/school/((self.school)!)/", with: "")
  29. print(postID!)
  30. }else {
  31. postref = Database.database().reference().child("posts/school/((self.cityLocationInNewPost?.school)!)").childByAutoId()
  32.  
  33. }
  34. guard let uid = Auth.auth().currentUser?.uid else { return }
  35. self.ref = Database.database().reference().child("users/profile/(uid)/numberOfPosts")
  36. self.ref.observeSingleEvent(of: .value) { (snapshot) in
  37. if let number = snapshot.value as? Int {
  38. self.numberOfPosts = number
  39. }
  40. }
  41.  
  42. //This will assign this post a specific identifier that we can reference it by.
  43. //This is referencing the place where you write a post
  44. let postObject = [
  45. "author":[
  46. "uid": userProfile.uid,
  47. "photoURL": userProfile.photoURL.absoluteString,
  48. "username": userProfile.username,
  49. "email": userProfile.email,
  50. "numberOfPosts": 0
  51. ],
  52. "text": self.textView.text,
  53. "postphotoURL": url,
  54. "Status": "(self.statusOfPost)",
  55. "timestamp": [".sv": "timestamp"],
  56. "location":[
  57. "latitude": currentLocation.coordinate.latitude,
  58. "logitude": currentLocation.coordinate.longitude
  59. ],
  60. "PostID": postID
  61. ] as [String:Any]
  62.  
  63. postref.setValue(postObject, withCompletionBlock: {Error, ref in
  64. if Error == nil {
  65.  
  66. //This will set the value
  67. DispatchQueue.main.asyncAfter(deadline: .now()){
  68. if self.cityLocationInNewPost?.school == nil {
  69. //This is coming from the subscription need to initialte that view
  70. let Storyboard = UIStoryboard(name: "Main", bundle: nil)
  71. let vc = Storyboard.instantiateViewController(withIdentifier: "LoggedIn2ViewController") as! LoggedIn2ViewController
  72. vc.school = self.school
  73. self.navigationController?.pushViewController(vc, animated: true)
  74.  
  75. }else {
  76. self.dismiss(animated: true, completion: nil)
  77. }
  78. //lets set the numberofposts to the variable
  79. self.updateNumberOfPosts()
  80. }
  81. }else {
  82. print(Error?.localizedDescription as Any)
  83. self.creatAlert(title: "Error", message: "Error making a Post!")
  84. }
  85. })
  86. })
  87. //Giving an alert that the post was succesful
  88. let alert = UIAlertController(title: "Notification", message: "Your post is successful! Thank you for the contribution", preferredStyle: UIAlertController.Style.alert)
  89. alert.addAction(UIAlertAction(title: "Awesome!", style: UIAlertAction.Style.default, handler: nil))
  90. self.present(alert, animated: true, completion: nil)
  91. // }else {
  92. // self.creatAlert(title: "Cant Make Post!", message: "Cant make post since you are not on the School's campus!")
  93. // textView.text = ""
  94. // }
  95. }
  96.  
  97. func updateNumberOfPosts() {
  98. //We will need to increment the number of posts
  99. guard let uid = Auth.auth().currentUser?.uid else { return }
  100. ref = Database.database().reference().child("users/profile/(uid)/numberOfPosts")
  101. ref.observeSingleEvent(of: .value) { (snapshot) in
  102. if var number = snapshot.value as? Int {
  103. print(number)
  104. number = number + 1
  105. self.ref.setValue(number)
  106. print(number)
  107. }
  108. }
Add Comment
Please, Sign In to add comment