diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj index 00f97fff..1c7fc0bd 100644 --- a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */; }; 84D8B48C1D757D4000752B56 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48B1D757D4000752B56 /* AppDelegate.swift */; }; 84D8B48E1D757D4000752B56 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48D1D757D4000752B56 /* ViewController.swift */; }; 84D8B4911D757D4000752B56 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B48F1D757D4000752B56 /* Main.storyboard */; }; @@ -21,12 +22,11 @@ 84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */; }; 84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */; }; 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */; }; - 9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitSwiftDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.debug.xcconfig"; sourceTree = ""; }; + 843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LFLiveKitSwiftDemo-Bridging-Header.h"; sourceTree = ""; }; 84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 84D8B48B1D757D4000752B56 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 84D8B48D1D757D4000752B56 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -43,6 +43,7 @@ 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; + A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LFLiveKitSwiftDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -52,7 +53,7 @@ buildActionMask = 2147483647; files = ( 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */, - 9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */, + 5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -62,7 +63,7 @@ 23FA2B0543E0C2A8E7C84D9E /* Frameworks */ = { isa = PBXGroup; children = ( - 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */, + A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */, ); name = Frameworks; sourceTree = ""; @@ -91,6 +92,7 @@ children = ( 84D8B48B1D757D4000752B56 /* AppDelegate.swift */, 84D8B48D1D757D4000752B56 /* ViewController.swift */, + 843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */, 84D8B48F1D757D4000752B56 /* Main.storyboard */, 84D8B4A31D757DBB00752B56 /* images */, 84D8B4921D757D4000752B56 /* Assets.xcassets */, @@ -320,7 +322,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -359,7 +361,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -375,13 +377,13 @@ FRAMEWORK_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h"; SWIFT_VERSION = 3.0; }; name = Debug; @@ -395,13 +397,13 @@ FRAMEWORK_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist index 6905cc67..22b854f4 100644 --- a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist @@ -26,6 +26,10 @@ LaunchScreen UIMainStoryboardFile Main + NSCameraUsageDescription + .. + NSMicrophoneUsageDescription + .. UIRequiredDeviceCapabilities armv7 diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h new file mode 100644 index 00000000..251e8a97 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h @@ -0,0 +1,14 @@ +// +// LFLiveKitSwiftDemo-Bridging-Header.h +// LFLiveKitSwiftDemo +// +// Created by admin on 2016/11/9. +// Copyright © 2016年 admin. All rights reserved. +// + +#ifndef LFLiveKitSwiftDemo_Bridging_Header_h +#define LFLiveKitSwiftDemo_Bridging_Header_h + +#import + +#endif /* LFLiveKitSwiftDemo_Bridging_Header_h */ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift index 5e871e4c..931ff818 100644 --- a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift @@ -14,6 +14,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. + + session.delegate = self + session.preView = self.view + self.requestAccessForVideo() self.requestAccessForAudio() self.view.backgroundColor = UIColor.clear @@ -23,6 +27,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate { containerView.addSubview(beautyButton) containerView.addSubview(cameraButton) containerView.addSubview(startLiveButton) + + cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for:.touchUpInside) + beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside) + startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: .touchUpInside) } override func didReceiveMemoryWarning() { @@ -33,44 +41,45 @@ class ViewController: UIViewController, LFLiveSessionDelegate { //MARK: AccessAuth func requestAccessForVideo() -> Void { - let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) + let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo); switch status { // 许可对话没有出现,发起授权许可 - case AVAuthorizationStatus.NotDetermined: - AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) in - if (granted) { - dispatch_async(dispatch_get_main_queue(), { - self.session.running = true; - }); + case AVAuthorizationStatus.notDetermined: + AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted) in + if(granted){ + DispatchQueue.main.async { + self.session.running = true + } } }) break; // 已经开启授权,可继续 - case AVAuthorizationStatus.Authorized: + case AVAuthorizationStatus.authorized: session.running = true; break; // 用户明确地拒绝授权,或者相机设备无法访问 - case AVAuthorizationStatus.Denied: break - case AVAuthorizationStatus.Restricted:break; + case AVAuthorizationStatus.denied: break + case AVAuthorizationStatus.restricted:break; default: break; } } func requestAccessForAudio() -> Void { - let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeAudio) + let status = AVCaptureDevice.authorizationStatus(forMediaType:AVMediaTypeAudio) switch status { // 许可对话没有出现,发起授权许可 - case AVAuthorizationStatus.NotDetermined: - AVCaptureDevice.requestAccessForMediaType(AVMediaTypeAudio, completionHandler: { (granted) in + case AVAuthorizationStatus.notDetermined: + AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (granted) in + }) break; // 已经开启授权,可继续 - case AVAuthorizationStatus.Authorized: + case AVAuthorizationStatus.authorized: break; // 用户明确地拒绝授权,或者相机设备无法访问 - case AVAuthorizationStatus.Denied: break - case AVAuthorizationStatus.Restricted:break; + case AVAuthorizationStatus.denied: break + case AVAuthorizationStatus.restricted:break; default: break; } @@ -90,21 +99,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate { func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) { print("liveStateDidChange: \(state.rawValue)") switch state { - case LFLiveState.Ready: + case LFLiveState.ready: stateLabel.text = "未连接" break; - case LFLiveState.Pending: + case LFLiveState.pending: stateLabel.text = "连接中" break; - case LFLiveState.Start: + case LFLiveState.start: stateLabel.text = "已连接" break; - case LFLiveState.Error: + case LFLiveState.error: stateLabel.text = "连接错误" break; - case LFLiveState.Stop: + case LFLiveState.stop: stateLabel.text = "未连接" break; + default: + break; } } @@ -127,13 +138,13 @@ class ViewController: UIViewController, LFLiveSessionDelegate { // 美颜 func didTappedBeautyButton(_ button: UIButton) -> Void { session.beautyFace = !session.beautyFace; - beautyButton.selected = !session.beautyFace; + beautyButton.isSelected = !session.beautyFace } // 摄像头 func didTappedCameraButton(_ button: UIButton) -> Void { let devicePositon = session.captureDevicePosition; - session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.Back) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; + session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.back) ? AVCaptureDevicePosition.front : AVCaptureDevicePosition.back; } // 关闭 @@ -144,26 +155,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate { //MARK: - Getters and Setters //  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏 - lazy var session: LFLiveSession = { - let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration() - let videoConfiguration = LFLiveVideoConfiguration.defaultConfigurationForQuality(LFLiveVideoQuality.Low3) + var session: LFLiveSession = { + let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high) + let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3) let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration) - - session?.delegate = self - session?.preView = self.view return session! }() // 视图 - lazy var containerView: UIView = { - let containerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height)) + var containerView: UIView = { + let containerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)) containerView.backgroundColor = UIColor.clear containerView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleHeight] return containerView }() // 状态Label - lazy var stateLabel: UILabel = { + var stateLabel: UILabel = { let stateLabel = UILabel(frame: CGRect(x: 20, y: 20, width: 80, height: 40)) stateLabel.text = "未连接" stateLabel.textColor = UIColor.white @@ -172,49 +180,36 @@ class ViewController: UIViewController, LFLiveSessionDelegate { }() // 关闭按钮 - lazy var closeButton: UIButton = { - let closeButton = UIButton(frame: CGRect(x: self.view.frame.width - 10 - 44, y: 20, width: 44, height: 44)) + var closeButton: UIButton = { + let closeButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 10 - 44, y: 20, width: 44, height: 44)) closeButton.setImage(UIImage(named: "close_preview"), for: UIControlState()) - closeButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: UIControlEvents.touchUpInside) return closeButton }() // 摄像头 - lazy var cameraButton: UIButton = { - let cameraButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 2, y: 20, width: 44, height: 44)) + var cameraButton: UIButton = { + let cameraButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 2, y: 20, width: 44, height: 44)) cameraButton.setImage(UIImage(named: "camra_preview"), for: UIControlState()) - cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for: UIControlEvents.touchUpInside) return cameraButton }() // 摄像头 - lazy var beautyButton: UIButton = { - let beautyButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 3, y: 20, width: 44, height: 44)) - beautyButton.setImage(UIImage(named: "camra_preview"), for: UIControlState.selected) + var beautyButton: UIButton = { + let beautyButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 3, y: 20, width: 44, height: 44)) + beautyButton.setImage(UIImage(named: "camra_beauty"), for: UIControlState.selected) beautyButton.setImage(UIImage(named: "camra_beauty_close"), for: UIControlState()) - beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: UIControlEvents.touchUpInside) return beautyButton }() // 开始直播按钮 - lazy var startLiveButton: UIButton = { - let startLiveButton = UIButton(frame: CGRect(x: 30, y: self.view.frame.height - 50, width: self.view.frame.width - 10 - 44, height: 44)) + var startLiveButton: UIButton = { + let startLiveButton = UIButton(frame: CGRect(x: 30, y: UIScreen.main.bounds.height - 50, width: UIScreen.main.bounds.width - 10 - 44, height: 44)) startLiveButton.layer.cornerRadius = 22 startLiveButton.setTitleColor(UIColor.black, for:UIControlState()) startLiveButton.setTitle("开始直播", for: UIControlState()) startLiveButton.titleLabel!.font = UIFont.systemFont(ofSize: 14) startLiveButton.backgroundColor = UIColor(colorLiteralRed: 50, green: 32, blue: 245, alpha: 1) - startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: UIControlEvents.touchUpInside) return startLiveButton }() - - // 转屏 - override var supportedInterfaceOrientations : UIInterfaceOrientationMask { - return UIInterfaceOrientationMask.portrait - } - - override var shouldAutorotate : Bool { - return true - } } diff --git a/samples/LFLiveKitSwiftDemo/Podfile b/samples/LFLiveKitSwiftDemo/Podfile index 22153b04..9883348e 100644 --- a/samples/LFLiveKitSwiftDemo/Podfile +++ b/samples/LFLiveKitSwiftDemo/Podfile @@ -1,6 +1,8 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios,'7.0' +use_frameworks! + target “LFLiveKitSwiftDemo” do pod 'LFLiveKit', :path => '../../.' end