Podfile | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai.xcodeproj/project.pbxproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/AppDelegate.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Config/Enums.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Network/Services.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Network/SocketManager.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Root/Course/VC/CourseOnlineListVC.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Root/Home/VC/HomeVC.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
WanPai/Root/Yard/VC/YardBookingDetailVC.swift | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Podfile
@@ -19,6 +19,7 @@ pod 'AlipaySDK-iOS' pod 'AMap2DMap-NO-IDFA' pod 'CryptoSwift' pod 'RHSocketKit/Extend' post_install do |installer| WanPai.xcodeproj/project.pbxproj
@@ -125,6 +125,7 @@ 1387B6722A4AC9C000BF2F2E /* CourseBookingTCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1387B6702A4AC9C000BF2F2E /* CourseBookingTCell.xib */; }; 1387B6752A4ACA1000BF2F2E /* CourseBooking_1_TCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1387B6732A4ACA1000BF2F2E /* CourseBooking_1_TCell.swift */; }; 1387B6762A4ACA1000BF2F2E /* CourseBooking_1_TCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1387B6742A4ACA1000BF2F2E /* CourseBooking_1_TCell.xib */; }; 138BE81C2AF0E41400FECE44 /* SocketManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 138BE81B2AF0E41400FECE44 /* SocketManager.swift */; }; 138D4CFB2A47ECAC005233E7 /* CourseInfoScheduleVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 138D4CF92A47ECAC005233E7 /* CourseInfoScheduleVC.swift */; }; 138D4CFC2A47ECAC005233E7 /* CourseInfoScheduleVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 138D4CFA2A47ECAC005233E7 /* CourseInfoScheduleVC.xib */; }; 138D4CFF2A47EF4C005233E7 /* CourseDatetimeCCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 138D4CFD2A47EF4C005233E7 /* CourseDatetimeCCell.swift */; }; @@ -419,6 +420,7 @@ 1387B6702A4AC9C000BF2F2E /* CourseBookingTCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CourseBookingTCell.xib; sourceTree = "<group>"; }; 1387B6732A4ACA1000BF2F2E /* CourseBooking_1_TCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseBooking_1_TCell.swift; sourceTree = "<group>"; }; 1387B6742A4ACA1000BF2F2E /* CourseBooking_1_TCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CourseBooking_1_TCell.xib; sourceTree = "<group>"; }; 138BE81B2AF0E41400FECE44 /* SocketManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketManager.swift; sourceTree = "<group>"; }; 138D4CF92A47ECAC005233E7 /* CourseInfoScheduleVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseInfoScheduleVC.swift; sourceTree = "<group>"; }; 138D4CFA2A47ECAC005233E7 /* CourseInfoScheduleVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CourseInfoScheduleVC.xib; sourceTree = "<group>"; }; 138D4CFD2A47EF4C005233E7 /* CourseDatetimeCCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDatetimeCCell.swift; sourceTree = "<group>"; }; @@ -685,6 +687,7 @@ 134BD5092A5FF72800786819 /* OBSUploader.swift */, 1353D5732A56CA0A00539FCA /* Services.swift */, 1353D5742A56CA0A00539FCA /* NetworkRequest.swift */, 138BE81B2AF0E41400FECE44 /* SocketManager.swift */, ); path = Network; sourceTree = "<group>"; @@ -1622,6 +1625,7 @@ 13D7BA9B2A4BDF0A0007E4B7 /* WelfareCouponsTCell.swift in Sources */, 8D4905AD2A31AE7100E38513 /* JoinMemberIntroduceVC.swift in Sources */, 130EC1802AD3F6AF003CA9BA /* CommonAlertSheetView.swift in Sources */, 138BE81C2AF0E41400FECE44 /* SocketManager.swift in Sources */, 13D7D6232A4EBBCF000136BD /* SearchStoreTCell.swift in Sources */, 8DC3BE112A3803B500C91B7F /* ActivityListVC.swift in Sources */, 1378018A2A3B08A600414959 /* CourseOnlineListVC.swift in Sources */, WanPai/AppDelegate.swift
@@ -111,6 +111,8 @@ } completion: { _ in snapView?.removeFromSuperview() } // YYSocketManager.instance.startSocket(host: Socket_Url, port: 8888) } func needLogin(){ WanPai/Config/Enums.swift
@@ -289,7 +289,7 @@ switch self { case .goods:return "实体" case .coupon:return "优惠券" case .course:return "课包" case .course:return "运动营" case .ticket:return "门票" } } WanPai/Network/Services.swift
@@ -13,12 +13,14 @@ #if DEBUG //let All_Url = "http://192.168.110.27:56666" //罗易胜 let All_Url = "http://192.168.110.22:56666" //刘杰 //let All_Url = "http://8.137.22.229:56666" //正式地址 //let All_Url = "http://192.168.110.22:56666" //刘杰 //let Socket_Url = "192.168.110.22" let All_Url = "http://8.137.22.229:56666" //正式地址 //let All_Url = "http://8.137.22.229:56666" //正式地址 let Game_Url = "https://try.daowepark.com" #else let All_Url = "http://8.137.22.229:56666" //正式地址 //let Socket_Url = "192.168.110.22" //let Game_Url = "https://port.daowepark.com"//正式地址 let Game_Url = "https://try.daowepark.com" //测试地址 #endif WanPai/Network/SocketManager.swift
New file @@ -0,0 +1,142 @@ // // SocketManager.swift // WanPai // // Created by 无故事王国 on 2023/10/31. // import Foundation import RHSocketKit import RxSwift import RxCocoa import HandyJSON /// Sockt管理类 class YYSocketManager: NSObject { //仿OC写法 static let instance: YYSocketManager = YYSocketManager() /// DisposeBag private var timeDisposeBag = DisposeBag() private var host = "" private var point:Int32! class func shared(host:String,port:Int32) -> YYSocketManager { instance.host = host instance.point = port return instance } override init() { super.init() initNotificationCenter() } func initNotificationCenter() { NotificationCenter.default.addObserver(self, selector: #selector(detectSocketServiceState(notif:)), name: NSNotification.Name(rawValue: kNotificationSocketServiceState), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(detectSocketPacketResponse(notif:)), name: NSNotification.Name(rawValue: kNotificationSocketPacketResponse), object: nil) } /// 开始 func startSocket(host:String,port:Int32) { if !RHSocketService.sharedInstance().isRunning{ //方便多次观察,先停止之前的连接 YYSocketManager.shared(host: host, port: port).stopSocket() let encoder = RHSocketVariableLengthEncoder() let decoder = RHSocketVariableLengthDecoder() encoder.countOfLengthByte = 4 decoder.countOfLengthByte = 4 RHSocketService.sharedInstance().encoder = encoder RHSocketService.sharedInstance().decoder = decoder let param = RHSocketConnectParam() param.host = host param.port = Int32(point) //心跳间隔 param.heartbeatInterval = 5 //设置短线后是否自动重连 param.autoReconnect = true RHSocketService.sharedInstance().start(with: param) } } /// Socket是否在运行 /// - Returns: BOOL func isRunning() -> Bool { return RHSocketService.sharedInstance().isRunning } /// 停止 private func stopSocket() { RHSocketService.sharedInstance().stop() } //MARK: - socket状态 @objc func detectSocketServiceState(notif:NSNotification) { if let state = notif.object { if state as? Bool == true{ //链接成功 Observable<Int>.interval(RxTimeInterval.seconds(5), scheduler: MainScheduler.instance) .subscribe(onNext: { [unowned self](_) in print("--->心跳") }).disposed(by: timeDisposeBag) }else{ //链接失败 self.timeDisposeBag = DisposeBag() } }else{ //链接失败 self.timeDisposeBag = DisposeBag() } } //MARK: - 解析接收长连接信息 func decodeResponse(notification:NSNotification) -> NSDictionary { if notification.object != nil { return (notification.object as! NSDictionary) } if let userInfo:Dictionary = notification.userInfo { let rsp:RHSocketPacketResponse = userInfo["RHSocketPacket"] as! RHSocketPacketResponse // let strEncode = CFStringConvertEncodingToNSStringEncoding(UInt32(CFStringEncodings.GB_18030_2000.rawValue)) if let data:Data = rsp.object as? Data{ let result = String.init(data: data, encoding: .utf8) let newData = result?.data(using: String.Encoding.utf8) guard let data = newData else{ return [:] } let dic = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) if let dict:NSDictionary = dic as? NSDictionary{ return dict }else{ return [:] } }else{ return [:] } }else{ return [:] } } //MARK: - socket接收信息 @objc func detectSocketPacketResponse(notif:NSNotification) { let dic = decodeResponse(notification: notif) let info = SocketModel<SimpleModel>.deserialize(from: dic) guard let model = info else {return} } } struct SocketModel<T:HandyJSON>:HandyJSON{ var code = 0 var msg = "" var data:T? var method = "" //SCAN_YARD_PUSH:场地预约扫码 } WanPai/Root/Course/VC/CourseOnlineListVC.swift
@@ -47,8 +47,8 @@ override func viewDidLoad() { super.viewDidLoad() Services.bannerList(position: .onlineCourse).subscribe(onNext: {[weak self] data in let type = BannerPositionType(rawValue: viewModel.position.value)! Services.bannerList(position: type).subscribe(onNext: {[weak self] data in if let models = data.data{ self?.searchView.bannerView.setImages(images: models.map({$0.img}),type: .URL, imageClickBlock: { index in WanPai/Root/Home/VC/HomeVC.swift
@@ -250,11 +250,11 @@ let vc = ActivityListVC() push(vc: vc) case .video: let vc = CourseOnlineListVC(position: 2) let vc = CourseOnlineListVC(position: 3) vc.title = "看视频得奖励" push(vc: vc) case .coin: let vc = CourseOnlineListVC(position: 1) let vc = CourseOnlineListVC(position: 2) vc.title = "线上课得积分" push(vc: vc) case .ticket: WanPai/Root/Yard/VC/YardBookingDetailVC.swift
@@ -133,15 +133,22 @@ private func startTimer(timeZone:String){ guard let startTime = yardBookingDetailDataModel?.startTime else {return} let d = Date(timeIntervalSince1970: TimeInterval(startTime / 1000)) if Date.jq_CalBySet(startDate: Date(), endDate: d).hour < 0{return} if Date().timeIntervalSince1970 > d.timeIntervalSince1970{return} label_dealtime.isHidden = false timer = Timer(timeInterval: 1.0, repeats: true, block: {[weak self] t in let datatime = Date.jq_CalBySet(startDate: Date(), endDate:d, set: [.day,.second,.hour,.minute]) if datatime.day > 0{ self?.label_dealtime.text = String(format: "距离入场时间:%02ld天%02ld小时%02ld分%02ld秒", datatime.day,datatime.hour,datatime.minute,datatime.second) } else if datatime.day == 0{ self?.label_dealtime.text = String(format: "距离入场时间:%02ld小时%02ld分%02ld秒", datatime.hour,datatime.minute,datatime.second) if datatime.day > 0 || datatime.hour > 0 || datatime.minute > 0 || datatime.second > 0{ if datatime.day > 0{ self?.label_dealtime.text = String(format: "距可入场时间:%02ld天%02ld小时%02ld分%02ld秒", datatime.day,datatime.hour,datatime.minute,datatime.second) }else if datatime.hour == 0 && datatime.day == 0{ self?.label_dealtime.text = String(format: "距可入场时间:%02ld分%02ld秒",datatime.minute,datatime.second) }else if datatime.day == 0{ self?.label_dealtime.text = String(format: "距可入场时间:%02ld小时%02ld分%02ld秒", datatime.hour,datatime.minute,datatime.second) } }else{ t.invalidate() self?.label_dealtime.isHidden = true } })