getting all necessary things in place for recording and storing locally, now just cloud upload and then firestore update
This commit is contained in:
@@ -711,6 +711,7 @@
|
|||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = "nirvana-ios/Info.plist";
|
INFOPLIST_FILE = "nirvana-ios/Info.plist";
|
||||||
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
|
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
|
||||||
|
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Please provide access to send messages 🌱";
|
||||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||||
@@ -745,6 +746,7 @@
|
|||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = "nirvana-ios/Info.plist";
|
INFOPLIST_FILE = "nirvana-ios/Info.plist";
|
||||||
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
|
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
|
||||||
|
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Please provide access to send messages 🌱";
|
||||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import NavigationStack
|
|||||||
import AVKit
|
import AVKit
|
||||||
|
|
||||||
struct CircleGridView: View {
|
struct CircleGridView: View {
|
||||||
|
@EnvironmentObject var innerCircleVM: InnerCircleViewModel
|
||||||
@EnvironmentObject var authSessionStore: AuthSessionStore
|
@EnvironmentObject var authSessionStore: AuthSessionStore
|
||||||
@EnvironmentObject var navigationStack: NavigationStack
|
@EnvironmentObject var navigationStack: NavigationStack
|
||||||
|
|
||||||
@@ -184,6 +185,7 @@ struct CircleGridView: View {
|
|||||||
struct CircleGridView_Previews: PreviewProvider {
|
struct CircleGridView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CircleGridView(selectedFriendIndex: Binding.constant(nil)).environmentObject(AuthSessionStore())
|
CircleGridView(selectedFriendIndex: Binding.constant(nil)).environmentObject(AuthSessionStore())
|
||||||
|
.environmentObject(InnerCircleViewModel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,14 +362,18 @@ extension CircleGridView {
|
|||||||
impactHeavy.impactOccurred()
|
impactHeavy.impactOccurred()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func record() {
|
||||||
|
// call parent view model/environment object vm functions
|
||||||
|
|
||||||
|
self.innerCircleVM.startRecording()
|
||||||
|
}
|
||||||
|
|
||||||
private func recordingGestureDeactived() {
|
private func recordingGestureDeactived() {
|
||||||
// stop recording
|
// stop recording
|
||||||
print("stopped recording")
|
print("stopped recording")
|
||||||
|
|
||||||
self.selectedFriendIndex = nil
|
self.selectedFriendIndex = nil
|
||||||
}
|
|
||||||
|
|
||||||
private func record() {
|
self.innerCircleVM.stopRecording()
|
||||||
// call parent view model/environment object vm functions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ enum SheetView : Identifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct InnerCircleView: View {
|
struct InnerCircleView: View {
|
||||||
|
@StateObject var innerCircleVM: InnerCircleViewModel = InnerCircleViewModel()
|
||||||
@EnvironmentObject var authSessionStore: AuthSessionStore
|
@EnvironmentObject var authSessionStore: AuthSessionStore
|
||||||
@EnvironmentObject var navigationStack: NavigationStack
|
@EnvironmentObject var navigationStack: NavigationStack
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ struct InnerCircleView: View {
|
|||||||
|
|
||||||
// content
|
// content
|
||||||
CircleGridView(selectedFriendIndex: self.$selectedFriendIndex)
|
CircleGridView(selectedFriendIndex: self.$selectedFriendIndex)
|
||||||
|
.environmentObject(innerCircleVM)
|
||||||
|
|
||||||
// header
|
// header
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
|
|
||||||
@Published var isRecording : Bool = false
|
@Published var isRecording : Bool = false
|
||||||
|
|
||||||
|
private var audioLocalUrl: URL?
|
||||||
|
|
||||||
func startRecording() {
|
func startRecording() {
|
||||||
let recordingSession = AVAudioSession.sharedInstance()
|
let recordingSession = AVAudioSession.sharedInstance()
|
||||||
do {
|
do {
|
||||||
@@ -23,8 +25,9 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
print("Can not setup the Recording")
|
print("Can not setup the Recording")
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
let filePath = getTemporaryDirectory().appendingPathComponent("\(UUID().uuidString).m4a")
|
||||||
let fileName = path.appendingPathComponent("\(UUID().uuidString).m4a")
|
|
||||||
|
print("file name of recording will be : \(filePath)")
|
||||||
|
|
||||||
let settings = [
|
let settings = [
|
||||||
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
|
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
|
||||||
@@ -33,13 +36,14 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
|
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
audioRecorder = try AVAudioRecorder(url: fileName, settings: settings)
|
audioRecorder = try AVAudioRecorder(url: filePath, settings: settings)
|
||||||
audioRecorder.prepareToRecord()
|
audioRecorder.prepareToRecord()
|
||||||
audioRecorder.record()
|
audioRecorder.record()
|
||||||
isRecording = true
|
isRecording = true
|
||||||
|
|
||||||
|
self.audioLocalUrl = filePath // setting this for later use when recording is stopped
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
print("Failed to Setup the Recording")
|
print("Failed to Setup the Recording")
|
||||||
}
|
}
|
||||||
@@ -49,14 +53,20 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
audioRecorder.stop()
|
audioRecorder.stop()
|
||||||
isRecording = false
|
isRecording = false
|
||||||
|
|
||||||
// upload to the cloud storage
|
if self.audioLocalUrl != nil {
|
||||||
|
// upload to the cloud storage
|
||||||
|
|
||||||
// store in firestore for receiving user to automatically get notified
|
// store in firestore for receiving user to automatically get notified
|
||||||
|
|
||||||
|
// delete local audio file from user's phone so that it doesn't get crazy
|
||||||
|
print("stopped recording: file about to get deleted from \(getTemporaryDirectory()) with filename: \(self.audioLocalUrl)")
|
||||||
|
|
||||||
|
try? FileManager.default.removeItem(at: self.audioLocalUrl!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDocumentsDirectory() -> URL {
|
func getTemporaryDirectory() -> URL {
|
||||||
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
return FileManager.default.temporaryDirectory
|
||||||
return paths[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user