From bb3577ade14507f2191b03f510eef5d7c4c41889 Mon Sep 17 00:00:00 2001 From: kevinzhow Date: Mon, 13 Jul 2015 13:35:46 +0800 Subject: [PATCH] Resume background music --- Yep.xcodeproj/project.pbxproj | 1 + .../xcshareddata/Yep.xcscmblueprint | 30 ++++++++ Yep/AppDelegate.swift | 9 +-- Yep/Info.plist | 2 +- Yep/Services/YepAudioService.swift | 71 ++++++++++++------- .../ConversationViewController.swift | 4 ++ 6 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 Yep.xcworkspace/xcshareddata/Yep.xcscmblueprint diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 1227f4b9..5d9a1cae 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -1533,6 +1533,7 @@ 0A8F54A31AB67D11004AD60E /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 0700; LastUpgradeCheck = 0630; ORGANIZATIONNAME = "Catch Inc"; TargetAttributes = { diff --git a/Yep.xcworkspace/xcshareddata/Yep.xcscmblueprint b/Yep.xcworkspace/xcshareddata/Yep.xcscmblueprint new file mode 100644 index 00000000..293496d5 --- /dev/null +++ b/Yep.xcworkspace/xcshareddata/Yep.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "F957B893D3C5E641248DF05092C80954FE9803E8", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "AD419F7F93A7DCDB6BCEF67C9BDF3271E84453B3" : 0, + "F957B893D3C5E641248DF05092C80954FE9803E8" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "C7AB340A-CC24-4E1A-9720-213C5CAC149C", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "AD419F7F93A7DCDB6BCEF67C9BDF3271E84453B3" : "CatchLib-iOS", + "F957B893D3C5E641248DF05092C80954FE9803E8" : "Yep" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "Yep", + "DVTSourceControlWorkspaceBlueprintVersion" : 203, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Yep.xcworkspace", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/CatchChat\/CatchLib-iOS.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "AD419F7F93A7DCDB6BCEF67C9BDF3271E84453B3" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/CatchChat\/Yep.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "F957B893D3C5E641248DF05092C80954FE9803E8" + } + ] +} \ No newline at end of file diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index ec607bcc..0979cbeb 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -22,8 +22,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var isColdLaunch = true func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - - println("App is On \(DEBUG)") setSchemaVersion(13, Realm.defaultPath, { migration, oldSchemaVersion in // We haven’t migrated anything yet, so oldSchemaVersion == 0 @@ -70,10 +68,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { }) Crashlytics.startWithAPIKey("3030ba006e21bcf8eb4a2127b6a7931ea6667486") - - AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker, error: nil) -// AVAudioSession.sharedInstance().setActive(true, error: nil) - + + AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker,error: nil) + application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum) // 推送初始化 APService.setupWithOption(launchOptions) diff --git a/Yep/Info.plist b/Yep/Info.plist index 0837eaa1..c5d83757 100644 --- a/Yep/Info.plist +++ b/Yep/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 48 + 49 Fabric APIKey diff --git a/Yep/Services/YepAudioService.swift b/Yep/Services/YepAudioService.swift index ff8179fa..478b053a 100644 --- a/Yep/Services/YepAudioService.swift +++ b/Yep/Services/YepAudioService.swift @@ -14,6 +14,8 @@ import Proposer class YepAudioService: NSObject { static let sharedManager = YepAudioService() + + let queue = dispatch_queue_create("YepAudioService", DISPATCH_QUEUE_SERIAL) var audioFileURL: NSURL? var audioRecorder: AVAudioRecorder? @@ -73,41 +75,56 @@ class YepAudioService: NSObject { } func beginRecordWithFileURL(fileURL: NSURL, audioRecorderDelegate: AVAudioRecorderDelegate) { - - proposeToAccess(.Microphone, agreed: { - - self.prepareAudioRecorderWithFileURL(fileURL, audioRecorderDelegate: audioRecorderDelegate) - - if let audioRecorder = self.audioRecorder { - - if (audioRecorder.recording){ - audioRecorder.stop() - - } else { - audioRecorder.record() - println("Audio Record did begin") + +// dispatch_async(queue, { () -> Void in +// AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker,error: nil) +// AVAudioSession.sharedInstance().setActive(true, error: nil) + + proposeToAccess(.Microphone, agreed: { + + self.prepareAudioRecorderWithFileURL(fileURL, audioRecorderDelegate: audioRecorderDelegate) + + if let audioRecorder = self.audioRecorder { + + if (audioRecorder.recording){ + audioRecorder.stop() + + } else { + audioRecorder.record() + println("Audio Record did begin") + } } - } + + }, rejected: { + if let + appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate, + viewController = appDelegate.window?.rootViewController { + viewController.alertCanNotAccessMicrophone() + } + }) +// }) + - }, rejected: { - if let - appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate, - viewController = appDelegate.window?.rootViewController { - viewController.alertCanNotAccessMicrophone() - } - }) } func endRecord() { - if let audioRecorder = audioRecorder { - if (audioRecorder.recording){ - audioRecorder.stop() + + + if let audioRecorder = self.audioRecorder { + if (audioRecorder.recording){ + audioRecorder.stop() + } } - } + dispatch_async(queue, { () -> Void in + // AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker,error: nil) + AVAudioSession.sharedInstance().setActive(false, withOptions: AVAudioSessionSetActiveOptions.OptionNotifyOthersOnDeactivation, error: nil) + }) + self.checkRecordTimeoutTimer?.invalidate() + + self.checkRecordTimeoutTimer = nil - checkRecordTimeoutTimer?.invalidate() + - checkRecordTimeoutTimer = nil } // MARK: Audio Player diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 710672ac..c50f6adc 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -200,6 +200,7 @@ class ConversationViewController: BaseViewController { navigationController?.delegate = delegate } } + override func viewDidLoad() { super.viewDidLoad() @@ -481,6 +482,7 @@ class ConversationViewController: BaseViewController { } messageToolbar.voiceSendCancelAction = { [weak self] messageToolbar in + self?.swipeUpView.hidden = true self?.waverView.removeFromSuperview() @@ -489,6 +491,7 @@ class ConversationViewController: BaseViewController { YepAudioService.sharedManager.recordTimeoutAction = nil } + messageToolbar.voiceSendEndAction = { [weak self] messageToolbar in hideWaver() @@ -1957,6 +1960,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi }) }, cancelAction: { + }) return