forked from superzzp/Visual-Eyes-BizHacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload more userdata to firebase database and firebase storage, based…
… on the current users and the time uploaded
- Loading branch information
Showing
8 changed files
with
250 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+12.8 KB
(120%)
VisualEyes.xcworkspace/xcuserdata/alexzhang.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// StorageReference.swift | ||
// VisualEyes | ||
// | ||
// Created by Alex Zhang on 2019-02-10. | ||
// Copyright © 2019 Alex Zhang. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FirebaseStorage | ||
|
||
// generate a new location for each new post image that is created by the current ISO timestamp. | ||
extension StorageReference { | ||
static let dateFormatter = ISO8601DateFormatter() | ||
|
||
static func newPostImageReference() -> StorageReference { | ||
let uid = User.current.uid | ||
let timestamp = dateFormatter.string(from: Date()) | ||
|
||
return Storage.storage().reference().child("images/posts/\(uid)/\(timestamp).jpg") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// UIImage+Size.swift | ||
// VisualEyes | ||
// | ||
// Created by Alex Zhang on 2019-02-10. | ||
// Copyright © 2019 Alex Zhang. All rights reserved. | ||
// | ||
import UIKit | ||
|
||
extension UIImage { | ||
|
||
//aspect height calculated base on the width and height of the device | ||
//currently ipad pro 11 | ||
var aspectHeight: CGFloat { | ||
let heightRatio = size.height / 1112 | ||
let widthRatio = size.width / 834 | ||
let aspectRatio = fmax(heightRatio, widthRatio) | ||
return size.height / aspectRatio | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// AzureCognitiveService.swift | ||
// VisualEyes | ||
// | ||
// Created by Alex Zhang on 2019-02-10. | ||
// Copyright © 2019 Alex Zhang. All rights reserved. | ||
// | ||
// class for sending or receving data from / to Microsoft Azure Cognitive Service API | ||
|
||
import Foundation | ||
import Alamofire | ||
import SwiftyJSON | ||
|
||
class AzureCognitiveService { | ||
|
||
//let azureURL: String = Constants.Azure.AZUREURL | ||
//let azureSubscriptionKey: String = Constants.Azure.SUBSCRIPTIONKEY | ||
|
||
|
||
static func azureFaceAnalysis (facePicsUrl: URL?, completion: @escaping (JSON?) -> Void) { | ||
let headers: HTTPHeaders = [ | ||
"Content-Type" : "application/json", | ||
"Ocp-Apim-Subscription-Key": Constants.Azure.SUBSCRIPTIONKEY, | ||
] | ||
print(facePicsUrl?.absoluteString) | ||
//some parameters included in Constants.Azure.AZUREURL | ||
let parameters: Parameters = [ | ||
// "returnFaceId":true, | ||
// "returnFaceLandmarks": false, | ||
// "returnFaceAttributes": "age, gender, emotion, hair, makeup, occlusion, accessories, blur", | ||
"url" : facePicsUrl?.absoluteString | ||
] | ||
|
||
Alamofire.request(Constants.Azure.AZUREURL, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { response in | ||
if response.result.isSuccess { | ||
print("successfully get JSON data!") | ||
let jso: JSON = JSON(response.result.value!) | ||
//json from azure is returned! | ||
return completion(jso) | ||
|
||
//self.updateUserData(json: jso) | ||
}else{ | ||
print("fail to get JSON response!") | ||
return completion(nil) | ||
//DispatchQueue.main.async { | ||
// self.navigationItem.title = "Fail to get image infomation" | ||
//} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters