Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 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
- @IBAction func handlePostButton(_ sender: Any) {
- guard let image = desciptionImage.image else {return}
- var currentLocation: CLLocation!
- if (CLLocationManager.authorizationStatus() == .authorizedWhenInUse || CLLocationManager.authorizationStatus() == .authorizedAlways){
- currentLocation = locationManager.location
- }
- //Need to specify the area of ryerson.
- // if ((currentLocation.coordinate.longitude < 43.657821 && currentLocation.coordinate.longitude > 43.656258 ) && (currentLocation.coordinate.latitude < -79.380299 && currentLocation.coordinate.latitude > -79.37842 )) {
- self.uploadProfileImage(image, completion: { (url) in
- guard let url = url else {return}
- guard let userProfile = UserService.currentUserProfile else { return }
- var postID: String!
- //Lets make a reference to the database
- var postref: DatabaseReference!
- //Check which view its coming from
- if self.cityLocationInNewPost?.school == nil {
- postref = Database.database().reference().child("posts/school/((self.school)!)").childByAutoId()
- postID = "((postref)!)"
- print("The post ID (String(describing: postID))")
- postID = postID.replacingOccurrences(of: "https://jama3a-version2.firebaseio.com/posts/school/((self.school)!)/", with: "")
- print(postID!)
- }else {
- postref = Database.database().reference().child("posts/school/((self.cityLocationInNewPost?.school)!)").childByAutoId()
- }
- guard let uid = Auth.auth().currentUser?.uid else { return }
- self.ref = Database.database().reference().child("users/profile/(uid)/numberOfPosts")
- self.ref.observeSingleEvent(of: .value) { (snapshot) in
- if let number = snapshot.value as? Int {
- self.numberOfPosts = number
- }
- }
- //This will assign this post a specific identifier that we can reference it by.
- //This is referencing the place where you write a post
- let postObject = [
- "author":[
- "uid": userProfile.uid,
- "photoURL": userProfile.photoURL.absoluteString,
- "username": userProfile.username,
- "email": userProfile.email,
- "numberOfPosts": 0
- ],
- "text": self.textView.text,
- "postphotoURL": url,
- "Status": "(self.statusOfPost)",
- "timestamp": [".sv": "timestamp"],
- "location":[
- "latitude": currentLocation.coordinate.latitude,
- "logitude": currentLocation.coordinate.longitude
- ],
- "PostID": postID
- ] as [String:Any]
- postref.setValue(postObject, withCompletionBlock: {Error, ref in
- if Error == nil {
- //This will set the value
- DispatchQueue.main.asyncAfter(deadline: .now()){
- if self.cityLocationInNewPost?.school == nil {
- //This is coming from the subscription need to initialte that view
- let Storyboard = UIStoryboard(name: "Main", bundle: nil)
- let vc = Storyboard.instantiateViewController(withIdentifier: "LoggedIn2ViewController") as! LoggedIn2ViewController
- vc.school = self.school
- self.navigationController?.pushViewController(vc, animated: true)
- }else {
- self.dismiss(animated: true, completion: nil)
- }
- //lets set the numberofposts to the variable
- self.updateNumberOfPosts()
- }
- }else {
- print(Error?.localizedDescription as Any)
- self.creatAlert(title: "Error", message: "Error making a Post!")
- }
- })
- })
- //Giving an alert that the post was succesful
- let alert = UIAlertController(title: "Notification", message: "Your post is successful! Thank you for the contribution", preferredStyle: UIAlertController.Style.alert)
- alert.addAction(UIAlertAction(title: "Awesome!", style: UIAlertAction.Style.default, handler: nil))
- self.present(alert, animated: true, completion: nil)
- // }else {
- // self.creatAlert(title: "Cant Make Post!", message: "Cant make post since you are not on the School's campus!")
- // textView.text = ""
- // }
- }
- func updateNumberOfPosts() {
- //We will need to increment the number of posts
- guard let uid = Auth.auth().currentUser?.uid else { return }
- ref = Database.database().reference().child("users/profile/(uid)/numberOfPosts")
- ref.observeSingleEvent(of: .value) { (snapshot) in
- if var number = snapshot.value as? Int {
- print(number)
- number = number + 1
- self.ref.setValue(number)
- print(number)
- }
- }
Add Comment
Please, Sign In to add comment