Skip to content

Commit 565453f

Browse files
author
chenliming
committed
support swift3
1 parent 3e44e0e commit 565453f

File tree

5 files changed

+81
-64
lines changed

5 files changed

+81
-64
lines changed

samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */; };
1011
84D8B48C1D757D4000752B56 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48B1D757D4000752B56 /* AppDelegate.swift */; };
1112
84D8B48E1D757D4000752B56 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48D1D757D4000752B56 /* ViewController.swift */; };
1213
84D8B4911D757D4000752B56 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B48F1D757D4000752B56 /* Main.storyboard */; };
@@ -21,12 +22,11 @@
2122
84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */; };
2223
84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */; };
2324
84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */; };
24-
9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */; };
2525
/* End PBXBuildFile section */
2626

2727
/* Begin PBXFileReference section */
28-
4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitSwiftDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2928
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 = "<group>"; };
29+
843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LFLiveKitSwiftDemo-Bridging-Header.h"; sourceTree = "<group>"; };
3030
84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
3131
84D8B48B1D757D4000752B56 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3232
84D8B48D1D757D4000752B56 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -43,6 +43,7 @@
4343
84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = "<group>"; };
4444
84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = "<group>"; };
4545
84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
46+
A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LFLiveKitSwiftDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4647
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 = "<group>"; };
4748
/* End PBXFileReference section */
4849

@@ -52,7 +53,7 @@
5253
buildActionMask = 2147483647;
5354
files = (
5455
84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */,
55-
9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */,
56+
5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */,
5657
);
5758
runOnlyForDeploymentPostprocessing = 0;
5859
};
@@ -62,7 +63,7 @@
6263
23FA2B0543E0C2A8E7C84D9E /* Frameworks */ = {
6364
isa = PBXGroup;
6465
children = (
65-
4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */,
66+
A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */,
6667
);
6768
name = Frameworks;
6869
sourceTree = "<group>";
@@ -91,6 +92,7 @@
9192
children = (
9293
84D8B48B1D757D4000752B56 /* AppDelegate.swift */,
9394
84D8B48D1D757D4000752B56 /* ViewController.swift */,
95+
843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */,
9496
84D8B48F1D757D4000752B56 /* Main.storyboard */,
9597
84D8B4A31D757DBB00752B56 /* images */,
9698
84D8B4921D757D4000752B56 /* Assets.xcassets */,
@@ -320,7 +322,7 @@
320322
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
321323
GCC_WARN_UNUSED_FUNCTION = YES;
322324
GCC_WARN_UNUSED_VARIABLE = YES;
323-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
325+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
324326
MTL_ENABLE_DEBUG_INFO = YES;
325327
ONLY_ACTIVE_ARCH = YES;
326328
SDKROOT = iphoneos;
@@ -359,7 +361,7 @@
359361
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
360362
GCC_WARN_UNUSED_FUNCTION = YES;
361363
GCC_WARN_UNUSED_VARIABLE = YES;
362-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
364+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
363365
MTL_ENABLE_DEBUG_INFO = NO;
364366
SDKROOT = iphoneos;
365367
VALIDATE_PRODUCT = YES;
@@ -375,13 +377,13 @@
375377
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
376378
HEADER_SEARCH_PATHS = "$(inherited)";
377379
INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist;
378-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
380+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
379381
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
380382
LIBRARY_SEARCH_PATHS = "$(inherited)";
381383
OTHER_LDFLAGS = "-all_load";
382384
PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng;
383385
PRODUCT_NAME = "$(TARGET_NAME)";
384-
SWIFT_OBJC_BRIDGING_HEADER = "";
386+
SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h";
385387
SWIFT_VERSION = 3.0;
386388
};
387389
name = Debug;
@@ -395,13 +397,13 @@
395397
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
396398
HEADER_SEARCH_PATHS = "$(inherited)";
397399
INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist;
398-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
400+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
399401
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
400402
LIBRARY_SEARCH_PATHS = "$(inherited)";
401403
OTHER_LDFLAGS = "-all_load";
402404
PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng;
403405
PRODUCT_NAME = "$(TARGET_NAME)";
404-
SWIFT_OBJC_BRIDGING_HEADER = "";
406+
SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h";
405407
SWIFT_VERSION = 3.0;
406408
};
407409
name = Release;

samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<string>LaunchScreen</string>
2727
<key>UIMainStoryboardFile</key>
2828
<string>Main</string>
29+
<key>NSCameraUsageDescription</key>
30+
<string>..</string>
31+
<key>NSMicrophoneUsageDescription</key>
32+
<string>..</string>
2933
<key>UIRequiredDeviceCapabilities</key>
3034
<array>
3135
<string>armv7</string>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// LFLiveKitSwiftDemo-Bridging-Header.h
3+
// LFLiveKitSwiftDemo
4+
//
5+
// Created by admin on 2016/11/9.
6+
// Copyright © 2016年 admin. All rights reserved.
7+
//
8+
9+
#ifndef LFLiveKitSwiftDemo_Bridging_Header_h
10+
#define LFLiveKitSwiftDemo_Bridging_Header_h
11+
12+
#import <LFLiveKit/LFLiveKit.h>
13+
14+
#endif /* LFLiveKitSwiftDemo_Bridging_Header_h */

samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift

+49-54
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
1414
override func viewDidLoad() {
1515
super.viewDidLoad()
1616
// Do any additional setup after loading the view, typically from a nib.
17+
18+
session.delegate = self
19+
session.preView = self.view
20+
1721
self.requestAccessForVideo()
1822
self.requestAccessForAudio()
1923
self.view.backgroundColor = UIColor.clear
@@ -23,6 +27,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
2327
containerView.addSubview(beautyButton)
2428
containerView.addSubview(cameraButton)
2529
containerView.addSubview(startLiveButton)
30+
31+
cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for:.touchUpInside)
32+
beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside)
33+
startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: .touchUpInside)
2634
}
2735

2836
override func didReceiveMemoryWarning() {
@@ -33,44 +41,45 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
3341
//MARK: AccessAuth
3442

3543
func requestAccessForVideo() -> Void {
36-
let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
44+
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo);
3745
switch status {
3846
// 许可对话没有出现,发起授权许可
39-
case AVAuthorizationStatus.NotDetermined:
40-
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) in
41-
if (granted) {
42-
dispatch_async(dispatch_get_main_queue(), {
43-
self.session.running = true;
44-
});
47+
case AVAuthorizationStatus.notDetermined:
48+
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted) in
49+
if(granted){
50+
DispatchQueue.main.async {
51+
self.session.running = true
52+
}
4553
}
4654
})
4755
break;
4856
// 已经开启授权,可继续
49-
case AVAuthorizationStatus.Authorized:
57+
case AVAuthorizationStatus.authorized:
5058
session.running = true;
5159
break;
5260
// 用户明确地拒绝授权,或者相机设备无法访问
53-
case AVAuthorizationStatus.Denied: break
54-
case AVAuthorizationStatus.Restricted:break;
61+
case AVAuthorizationStatus.denied: break
62+
case AVAuthorizationStatus.restricted:break;
5563
default:
5664
break;
5765
}
5866
}
5967

6068
func requestAccessForAudio() -> Void {
61-
let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeAudio)
69+
let status = AVCaptureDevice.authorizationStatus(forMediaType:AVMediaTypeAudio)
6270
switch status {
6371
// 许可对话没有出现,发起授权许可
64-
case AVAuthorizationStatus.NotDetermined:
65-
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeAudio, completionHandler: { (granted) in
72+
case AVAuthorizationStatus.notDetermined:
73+
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (granted) in
74+
6675
})
6776
break;
6877
// 已经开启授权,可继续
69-
case AVAuthorizationStatus.Authorized:
78+
case AVAuthorizationStatus.authorized:
7079
break;
7180
// 用户明确地拒绝授权,或者相机设备无法访问
72-
case AVAuthorizationStatus.Denied: break
73-
case AVAuthorizationStatus.Restricted:break;
81+
case AVAuthorizationStatus.denied: break
82+
case AVAuthorizationStatus.restricted:break;
7483
default:
7584
break;
7685
}
@@ -90,21 +99,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
9099
func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) {
91100
print("liveStateDidChange: \(state.rawValue)")
92101
switch state {
93-
case LFLiveState.Ready:
102+
case LFLiveState.ready:
94103
stateLabel.text = "未连接"
95104
break;
96-
case LFLiveState.Pending:
105+
case LFLiveState.pending:
97106
stateLabel.text = "连接中"
98107
break;
99-
case LFLiveState.Start:
108+
case LFLiveState.start:
100109
stateLabel.text = "已连接"
101110
break;
102-
case LFLiveState.Error:
111+
case LFLiveState.error:
103112
stateLabel.text = "连接错误"
104113
break;
105-
case LFLiveState.Stop:
114+
case LFLiveState.stop:
106115
stateLabel.text = "未连接"
107116
break;
117+
default:
118+
break;
108119
}
109120
}
110121

@@ -127,13 +138,13 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
127138
// 美颜
128139
func didTappedBeautyButton(_ button: UIButton) -> Void {
129140
session.beautyFace = !session.beautyFace;
130-
beautyButton.selected = !session.beautyFace;
141+
beautyButton.isSelected = !session.beautyFace
131142
}
132143

133144
// 摄像头
134145
func didTappedCameraButton(_ button: UIButton) -> Void {
135146
let devicePositon = session.captureDevicePosition;
136-
session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.Back) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
147+
session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.back) ? AVCaptureDevicePosition.front : AVCaptureDevicePosition.back;
137148
}
138149

139150
// 关闭
@@ -144,26 +155,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
144155
//MARK: - Getters and Setters
145156

146157
//  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏
147-
lazy var session: LFLiveSession = {
148-
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration()
149-
let videoConfiguration = LFLiveVideoConfiguration.defaultConfigurationForQuality(LFLiveVideoQuality.Low3)
158+
var session: LFLiveSession = {
159+
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
160+
let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
150161
let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
151-
152-
session?.delegate = self
153-
session?.preView = self.view
154162
return session!
155163
}()
156164

157165
// 视图
158-
lazy var containerView: UIView = {
159-
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height))
166+
var containerView: UIView = {
167+
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
160168
containerView.backgroundColor = UIColor.clear
161169
containerView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleHeight]
162170
return containerView
163171
}()
164172

165173
// 状态Label
166-
lazy var stateLabel: UILabel = {
174+
var stateLabel: UILabel = {
167175
let stateLabel = UILabel(frame: CGRect(x: 20, y: 20, width: 80, height: 40))
168176
stateLabel.text = "未连接"
169177
stateLabel.textColor = UIColor.white
@@ -172,49 +180,36 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
172180
}()
173181

174182
// 关闭按钮
175-
lazy var closeButton: UIButton = {
176-
let closeButton = UIButton(frame: CGRect(x: self.view.frame.width - 10 - 44, y: 20, width: 44, height: 44))
183+
var closeButton: UIButton = {
184+
let closeButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 10 - 44, y: 20, width: 44, height: 44))
177185
closeButton.setImage(UIImage(named: "close_preview"), for: UIControlState())
178-
closeButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: UIControlEvents.touchUpInside)
179186
return closeButton
180187
}()
181188

182189
// 摄像头
183-
lazy var cameraButton: UIButton = {
184-
let cameraButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 2, y: 20, width: 44, height: 44))
190+
var cameraButton: UIButton = {
191+
let cameraButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 2, y: 20, width: 44, height: 44))
185192
cameraButton.setImage(UIImage(named: "camra_preview"), for: UIControlState())
186-
cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for: UIControlEvents.touchUpInside)
187193
return cameraButton
188194
}()
189195

190196
// 摄像头
191-
lazy var beautyButton: UIButton = {
192-
let beautyButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 3, y: 20, width: 44, height: 44))
193-
beautyButton.setImage(UIImage(named: "camra_preview"), for: UIControlState.selected)
197+
var beautyButton: UIButton = {
198+
let beautyButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 3, y: 20, width: 44, height: 44))
199+
beautyButton.setImage(UIImage(named: "camra_beauty"), for: UIControlState.selected)
194200
beautyButton.setImage(UIImage(named: "camra_beauty_close"), for: UIControlState())
195-
beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: UIControlEvents.touchUpInside)
196201
return beautyButton
197202
}()
198203

199204
// 开始直播按钮
200-
lazy var startLiveButton: UIButton = {
201-
let startLiveButton = UIButton(frame: CGRect(x: 30, y: self.view.frame.height - 50, width: self.view.frame.width - 10 - 44, height: 44))
205+
var startLiveButton: UIButton = {
206+
let startLiveButton = UIButton(frame: CGRect(x: 30, y: UIScreen.main.bounds.height - 50, width: UIScreen.main.bounds.width - 10 - 44, height: 44))
202207
startLiveButton.layer.cornerRadius = 22
203208
startLiveButton.setTitleColor(UIColor.black, for:UIControlState())
204209
startLiveButton.setTitle("开始直播", for: UIControlState())
205210
startLiveButton.titleLabel!.font = UIFont.systemFont(ofSize: 14)
206211
startLiveButton.backgroundColor = UIColor(colorLiteralRed: 50, green: 32, blue: 245, alpha: 1)
207-
startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: UIControlEvents.touchUpInside)
208212
return startLiveButton
209213
}()
210-
211-
// 转屏
212-
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
213-
return UIInterfaceOrientationMask.portrait
214-
}
215-
216-
override var shouldAutorotate : Bool {
217-
return true
218-
}
219214
}
220215

samples/LFLiveKitSwiftDemo/Podfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22
platform :ios,'7.0'
33

4+
use_frameworks!
5+
46
target “LFLiveKitSwiftDemo” do
57
pod 'LFLiveKit', :path => '../../.'
68
end

0 commit comments

Comments
 (0)