diff --git a/Podfile b/Podfile index 52e67b6..956f6b8 100644 --- a/Podfile +++ b/Podfile @@ -25,6 +25,7 @@ pod 'Qiniu' pod 'TZImagePickerController' pod 'LookinServer', :configurations => ['Debug'] + pod 'StreamingKit' # Pods for yinmeng-ios diff --git a/yinmeng-ios.xcodeproj/project.pbxproj b/yinmeng-ios.xcodeproj/project.pbxproj index 0ef34a3..bd28425 100644 --- a/yinmeng-ios.xcodeproj/project.pbxproj +++ b/yinmeng-ios.xcodeproj/project.pbxproj @@ -1009,6 +1009,7 @@ INFOPLIST_FILE = "yinmeng-ios/Info.plist"; INFOPLIST_KEY_CFBundleDisplayName = "音萌"; INFOPLIST_KEY_NSCameraUsageDescription = "“音萌”需要您的同意,才可以访问进行拍照,才可以在聊天中分享图片给他人查看,或上传图片以更新头像"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "“音萌”需要您的同意,才能进行定位服务,推荐附近好友"; INFOPLIST_KEY_NSMicrophoneUsageDescription = "\"音萌\"需要您的同意,才可以进行语音聊天"; INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "“音萌”需要您的同意,才可以存储相片到相册"; INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "“音萌”需要您的同意,才可以访问相册并选择图片,然后在聊天中分享图片给他人查看,或上传图片以更新头像"; @@ -1052,6 +1053,7 @@ INFOPLIST_FILE = "yinmeng-ios/Info.plist"; INFOPLIST_KEY_CFBundleDisplayName = "音萌"; INFOPLIST_KEY_NSCameraUsageDescription = "“音萌”需要您的同意,才可以访问进行拍照,才可以在聊天中分享图片给他人查看,或上传图片以更新头像"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "“音萌”需要您的同意,才能进行定位服务,推荐附近好友"; INFOPLIST_KEY_NSMicrophoneUsageDescription = "\"音萌\"需要您的同意,才可以进行语音聊天"; INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "“音萌”需要您的同意,才可以存储相片到相册"; INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "“音萌”需要您的同意,才可以访问相册并选择图片,然后在聊天中分享图片给他人查看,或上传图片以更新头像"; diff --git a/yinmeng-ios/Base/Request/YMNetworkHelper.swift b/yinmeng-ios/Base/Request/YMNetworkHelper.swift index 1410a73..85e1308 100644 --- a/yinmeng-ios/Base/Request/YMNetworkHelper.swift +++ b/yinmeng-ios/Base/Request/YMNetworkHelper.swift @@ -92,6 +92,7 @@ class YMNetworkHelper: NSObject { if codeNum == 401 && UrlSss.contains("auth-center/sso/logout") == false { NotificationCenter.default.post(name: NSNotification.Name(rawValue: "SessionTickValid"), object: nil) sessionNetMana.cancelAllRequests() + keyWindow.rootViewController = BaseNavigationViewController(rootViewController:AuthLaunchVC()) } var messageIn = response1.error.debugDescription if ResultMo.keys.contains("message") { messageIn = ResultMo["message"] as? String ?? "" } diff --git a/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h b/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h index 1d90eef..14e4934 100644 --- a/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h +++ b/yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h @@ -6,3 +6,5 @@ #import #import "RecordVoiceManager.h" #import +#import + diff --git a/yinmeng-ios/Info.plist b/yinmeng-ios/Info.plist index 7865451..0a91a49 100644 --- a/yinmeng-ios/Info.plist +++ b/yinmeng-ios/Info.plist @@ -2,8 +2,6 @@ - NSLocationWhenInUseUsageDescription - “音萌”需要您的同意,才能进行定位服务,推荐附近好友 NSAppTransportSecurity NSAllowsArbitraryLoads @@ -14,5 +12,9 @@ UIApplicationSupportsMultipleScenes + UIBackgroundModes + + audio + diff --git a/yinmeng-ios/Modules/Home/HomeVoiceUserInfoView.swift b/yinmeng-ios/Modules/Home/HomeVoiceUserInfoView.swift index 2c5e7b7..043d111 100644 --- a/yinmeng-ios/Modules/Home/HomeVoiceUserInfoView.swift +++ b/yinmeng-ios/Modules/Home/HomeVoiceUserInfoView.swift @@ -17,7 +17,7 @@ class HomeVoiceUserInfoView: UIView { override init(frame: CGRect) { super.init(frame: frame) setUILayout() - + self.dissView.addTarget(self, action: #selector(dissViewAction), for: .touchUpInside) } func setUILayout(){ backgroundColor = UIColor(white: 0, alpha: 0.8) @@ -210,10 +210,11 @@ class HomeVoiceUserInfoView: UIView { } @objc func dissViewAction(){ self.removeFromSuperview() + PlayVoiceManager.shared.stopPlayVoice() } var dissView:UIButton = { let _dissView = UIButton() - _dissView.addTarget(self, action: #selector(dissViewAction), for: .touchUpInside) + return _dissView }() var backgroundView:UIView = { diff --git a/yinmeng-ios/Modules/Home/PlayVoiceManager.swift b/yinmeng-ios/Modules/Home/PlayVoiceManager.swift index b6dd664..3b2d73f 100644 --- a/yinmeng-ios/Modules/Home/PlayVoiceManager.swift +++ b/yinmeng-ios/Modules/Home/PlayVoiceManager.swift @@ -7,11 +7,13 @@ import UIKit import Alamofire -class PlayVoiceManager: NSObject,AVAudioPlayerDelegate { - static let shared = PlayVoiceManager() - var player:AVAudioPlayer? - + +class PlayVoiceManager: NSObject,AVAudioPlayerDelegate { + + static let shared = PlayVoiceManager() + var player:AVAudioPlayer? + var isPlay = false func stopPlayVoice(){ guard let player = player else{return} @@ -26,7 +28,7 @@ class PlayVoiceManager: NSObject,AVAudioPlayerDelegate { guard let _url = URL.init(string: url) else { return } - self.player = try? AVAudioPlayer.init(contentsOf: _url) + self.player = try? AVAudioPlayer(contentsOf: _url) self.player?.volume = 1 self.player?.numberOfLoops = -1 self.player?.delegate = self @@ -35,75 +37,68 @@ class PlayVoiceManager: NSObject,AVAudioPlayerDelegate { isPlay = true } func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { - print(flag) + } func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) { - print(error) + } - func downloadVoice(url:String){ + func downloadVoice(url:String){ + let list = url.components(separatedBy: "/") var name = "voiceList" if list.isEmpty == false,let getName = list.last{ name = getName } let path = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)[0] as String - - let allPath = path + "/kUserVoice/" + name - try? FileManager.default.removeItem(atPath: allPath) if FileManager.default.fileExists(atPath: allPath){ beginPlayVoice(url: allPath) }else{ -// try? FileManager.default.createDirectory(atPath: allPath, withIntermediateDirectories: true, attributes: nil) + try? FileManager.default.createDirectory(atPath: allPath, withIntermediateDirectories: true, attributes: nil) downloadDataWithUrl(url: url, path: allPath) } } func downloadDataWithUrl(url:String,path:String){ - - //请求 - let request = URLRequest(url: URL(string: url)!) - - let session = URLSession.shared - //下载任务 - let downloadTask = session.downloadTask(with: request, - completionHandler: { (location:URL?, response:URLResponse?, error:Error?) + //请求 + let request = URLRequest(url: URL(string: url)!) + let session = URLSession.shared + //下载任务 + let downloadTask = session.downloadTask(with: request, + completionHandler: { (location:URL?, response:URLResponse?, error:Error?) -> Void in - let locationPath = location!.path - let getUlr = URL.init(string: path) - let locationUrl = URL.init(string: locationPath) - - - let data = try? NSData.dataWithContentsOfMappedFile(locationPath) - if let _data = data as? Data{ - do{ - FileManager.default.createFile(atPath: path, contents: _data) - self.beginPlayVoice(url:path) + let locationPath = location!.path + if FileManager.default.fileExists(atPath: path){ + try? FileManager.default.removeItem(atPath: path) } - catch{ - + do { + // 文件移动至document + try FileManager.default.copyItem(atPath: locationPath, toPath: path) + // main + DispatchQueue.main.async { + self.beginPlayVoice(url:path) + } + } catch let error { + debugPrint(error) + HUDTool.show(with: "\(error.localizedDescription)") } - - } - - - - - + // let data = NSData.init(contentsOfFile: locationPath) + // if let _data = data { + // let isHave = _data.write(toFile: path, atomically: true) + // print(isHave) + // self.beginPlayVoice(url:path) + // } + }) - - - }) - - //使用resume方法启动任务 downloadTask.resume() } - - - + + + } +