diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 27fa8d1a..4c0fe2a8 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 0A8F54B81AB67D11004AD60E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0A8F54B71AB67D11004AD60E /* Images.xcassets */; }; 0A8F54BB1AB67D11004AD60E /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0A8F54B91AB67D11004AD60E /* LaunchScreen.xib */; }; 0A8F54C71AB67D11004AD60E /* YepTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8F54C61AB67D11004AD60E /* YepTests.swift */; }; + 0A944C251AC8BB2F00037A06 /* YepStorageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A944C241AC8BB2F00037A06 /* YepStorageService.swift */; }; 0AD7EA5E1AC3ED1200617758 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AD7EA5D1AC3ED1200617758 /* CFNetwork.framework */; }; 0AD7EA601AC3ED1900617758 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AD7EA5F1AC3ED1900617758 /* CoreFoundation.framework */; }; 0AD7EA621AC3ED2100617758 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AD7EA611AC3ED2100617758 /* CoreTelephony.framework */; }; @@ -99,6 +100,7 @@ 0A8F54C01AB67D11004AD60E /* YepTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YepTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0A8F54C51AB67D11004AD60E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0A8F54C61AB67D11004AD60E /* YepTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YepTests.swift; sourceTree = ""; }; + 0A944C241AC8BB2F00037A06 /* YepStorageService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepStorageService.swift; path = Services/YepStorageService.swift; sourceTree = ""; }; 0AD7EA511AC3EA6F00617758 /* JPushSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JPushSDK.framework; path = "Pods/../build/Debug-iphoneos/Pods/JPushSDK.framework"; sourceTree = ""; }; 0AD7EA581AC3EAF300617758 /* Yep-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Yep-Bridging-Header.h"; sourceTree = ""; }; 0AD7EA5B1AC3ECD700617758 /* libPushSDK-1.8.3.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPushSDK-1.8.3.a"; path = "Yep/lib/libPushSDK-1.8.3.a"; sourceTree = ""; }; @@ -431,6 +433,7 @@ 502AE5281AB81076005BD199 /* YepService.swift */, 50E114F81ABC137A00F13000 /* YepServiceSync.swift */, 5076C5691AC46B9F00B22952 /* FayeService.swift */, + 0A944C241AC8BB2F00037A06 /* YepStorageService.swift */, ); name = Services; sourceTree = ""; @@ -832,6 +835,7 @@ 503315A01AC126100008A209 /* MessageToolbar.swift in Sources */, 502AE5531AB93215005BD199 /* ProfileFooterCell.swift in Sources */, 0A5D83991AC5D91E000045BF /* ContactsSearchTableViewController.swift in Sources */, + 0A944C251AC8BB2F00037A06 /* YepStorageService.swift in Sources */, 5023DE521AB6C51300B3EE96 /* CGRect+Yep.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Yep/Services/YepStorageService.swift b/Yep/Services/YepStorageService.swift new file mode 100644 index 00000000..886c6423 --- /dev/null +++ b/Yep/Services/YepStorageService.swift @@ -0,0 +1,28 @@ +// +// YepStorageService.swift +// Yep +// +// Created by kevinzhow on 15/3/30. +// Copyright (c) 2015年 Catch Inc. All rights reserved. +// + +import Foundation + +func uploadFileToAWSS3(fileUrl: NSURL) -> String { + return "" +} + +func requestAWSS3UploadForm(#failureHandler: ((Reason, String?) -> ())?, #completion: JSONDictionary -> Void) { + + let parse: JSONDictionary -> JSONDictionary? = { data in + return data + } + + let resource = authJsonResource(path: "/api/v1/attachments/s3_upload_public_form_fields", method: .GET, requestParameters:[:], parse: parse) + + if let failureHandler = failureHandler { + apiRequest({_ in}, baseURL, resource, failureHandler, completion) + } else { + apiRequest({_ in}, baseURL, resource, defaultFailureHandler, completion) + } +} diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 40813584..2d76e359 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -137,6 +137,14 @@ class ConversationViewController: UIViewController { }) } } + + messageToolbar.voiceSendAction = { messageToolbar in + requestAWSS3UploadForm(failureHandler: { (reason, error) in + println("\(error)") + }, completion: { token in + println("Got S3 token is \(token)") + }) + } } override func viewDidLayoutSubviews() { diff --git a/Yep/Views/MessageToolbar/MessageToolbar.swift b/Yep/Views/MessageToolbar/MessageToolbar.swift index 2678c148..6abe3328 100644 --- a/Yep/Views/MessageToolbar/MessageToolbar.swift +++ b/Yep/Views/MessageToolbar/MessageToolbar.swift @@ -31,6 +31,8 @@ class MessageToolbar: UIToolbar { } var textSendAction: ((messageToolBar: MessageToolbar) -> ())? + + var voiceSendAction: ((messageToolBar: MessageToolbar) -> ())? lazy var cameraButton: UIButton = { let button = UIButton() @@ -51,6 +53,7 @@ class MessageToolbar: UIToolbar { let button = UIButton() button.setImage(UIImage(named: "item_mic"), forState: .Normal) button.tintColor = UIColor.yepTintColor() + button.addTarget(self, action: "trySendVoiceMessage", forControlEvents: UIControlEvents.TouchUpInside) return button }() @@ -127,6 +130,12 @@ class MessageToolbar: UIToolbar { textSendAction(messageToolBar: self) } } + + func trySendVoiceMessage() { + if let textSendAction = voiceSendAction { + textSendAction(messageToolBar: self) + } + } } // MARK: UITextFieldDelegate