移除iOS原生端旧的对讲
This commit is contained in:
parent
82f04ba16d
commit
2ceee5c317
@ -11,47 +11,6 @@
|
||||
3364C3F42B0C902100AA5ABC /* lcokStarMain.png in Resources */ = {isa = PBXBuildFile; fileRef = 3364C3F32B0C902100AA5ABC /* lcokStarMain.png */; };
|
||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||
8297E4102AE75AC500E886FA /* XSFlutterManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E40E2AE75AC500E886FA /* XSFlutterManager.m */; };
|
||||
8297E43A2AE75BEE00E886FA /* Msg.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4132AE75BEE00E886FA /* Msg.m */; };
|
||||
8297E43B2AE75BEE00E886FA /* udp_data_class.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4172AE75BEE00E886FA /* udp_data_class.m */; };
|
||||
8297E43C2AE75BEE00E886FA /* UdpHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4182AE75BEE00E886FA /* UdpHelper.m */; };
|
||||
8297E43D2AE75BEE00E886FA /* Sformat.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E41B2AE75BEE00E886FA /* Sformat.m */; };
|
||||
8297E43E2AE75BEE00E886FA /* HttpManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4202AE75BEE00E886FA /* HttpManager.m */; };
|
||||
8297E43F2AE75BEE00E886FA /* UI.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4212AE75BEE00E886FA /* UI.m */; };
|
||||
8297E4402AE75BEE00E886FA /* sysInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4222AE75BEE00E886FA /* sysInfo.m */; };
|
||||
8297E4412AE75BEE00E886FA /* Pub.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4232AE75BEE00E886FA /* Pub.m */; };
|
||||
8297E4422AE75BEE00E886FA /* recordAudio.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4252AE75BEE00E886FA /* recordAudio.m */; };
|
||||
8297E4432AE75BEE00E886FA /* playAudio.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4282AE75BEE00E886FA /* playAudio.m */; };
|
||||
8297E4442AE75BEE00E886FA /* talk_Class.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E42A2AE75BEE00E886FA /* talk_Class.m */; };
|
||||
8297E4452AE75BEE00E886FA /* IframeInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E42C2AE75BEE00E886FA /* IframeInfo.m */; };
|
||||
8297E4462AE75BEE00E886FA /* Piano.caf in Resources */ = {isa = PBXBuildFile; fileRef = 8297E42E2AE75BEE00E886FA /* Piano.caf */; };
|
||||
8297E4472AE75BEE00E886FA /* ring1.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 8297E42F2AE75BEE00E886FA /* ring1.mp3 */; };
|
||||
8297E4482AE75BEE00E886FA /* ok.wav in Resources */ = {isa = PBXBuildFile; fileRef = 8297E4302AE75BEE00E886FA /* ok.wav */; };
|
||||
8297E4492AE75BEE00E886FA /* notice.wav in Resources */ = {isa = PBXBuildFile; fileRef = 8297E4312AE75BEE00E886FA /* notice.wav */; };
|
||||
8297E44A2AE75BEE00E886FA /* err.wav in Resources */ = {isa = PBXBuildFile; fileRef = 8297E4322AE75BEE00E886FA /* err.wav */; };
|
||||
8297E44B2AE75BEE00E886FA /* alarm.wav in Resources */ = {isa = PBXBuildFile; fileRef = 8297E4332AE75BEE00E886FA /* alarm.wav */; };
|
||||
8297E44C2AE75BEE00E886FA /* RingCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4362AE75BEE00E886FA /* RingCall.m */; };
|
||||
8297E44D2AE75BEE00E886FA /* VideoTalkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4382AE75BEE00E886FA /* VideoTalkManager.m */; };
|
||||
8297E44E2AE75BEE00E886FA /* voip_call.caf in Resources */ = {isa = PBXBuildFile; fileRef = 8297E4392AE75BEE00E886FA /* voip_call.caf */; };
|
||||
8297E4662AE75D4E00E886FA /* FaceSubPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4542AE75D4E00E886FA /* FaceSubPage.m */; };
|
||||
8297E4672AE75D4E00E886FA /* EquConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4552AE75D4E00E886FA /* EquConfig.m */; };
|
||||
8297E4682AE75D4E00E886FA /* OpenPwd.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4562AE75D4E00E886FA /* OpenPwd.m */; };
|
||||
8297E4692AE75D4E00E886FA /* Web.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4582AE75D4E00E886FA /* Web.m */; };
|
||||
8297E46A2AE75D4E00E886FA /* Setting.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E45A2AE75D4E00E886FA /* Setting.m */; };
|
||||
8297E46B2AE75D4E00E886FA /* FaceUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E45B2AE75D4E00E886FA /* FaceUpload.m */; };
|
||||
8297E46C2AE75D4E00E886FA /* EquAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E45C2AE75D4E00E886FA /* EquAdd.m */; };
|
||||
8297E46D2AE75D4E00E886FA /* EquList.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E45D2AE75D4E00E886FA /* EquList.m */; };
|
||||
8297E46E2AE75D4E00E886FA /* WifiList.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E45F2AE75D4E00E886FA /* WifiList.m */; };
|
||||
8297E46F2AE75D4E00E886FA /* P2pTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4612AE75D4E00E886FA /* P2pTest.m */; };
|
||||
8297E4702AE75D4E00E886FA /* Call.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4642AE75D4E00E886FA /* Call.m */; };
|
||||
8297E4742AE761EB00E886FA /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4722AE761EB00E886FA /* BaseViewController.m */; };
|
||||
8297E4782AE7635400E886FA /* Opendoor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4772AE7635400E886FA /* Opendoor.m */; };
|
||||
8297E4802AE7643100E886FA /* AsyncUdpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E47A2AE7643100E886FA /* AsyncUdpSocket.m */; };
|
||||
8297E4812AE7643100E886FA /* UIView+AutoLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E47C2AE7643100E886FA /* UIView+AutoLayout.m */; };
|
||||
8297E4822AE7643100E886FA /* AsyncSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E47E2AE7643100E886FA /* AsyncSocket.m */; };
|
||||
8297E4882AE768DE00E886FA /* BaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4872AE768DE00E886FA /* BaseNavigationController.m */; };
|
||||
8297E48E2AE76D0500E886FA /* BaseTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E48D2AE76D0500E886FA /* BaseTableViewController.m */; };
|
||||
8297E4912AE76DD500E886FA /* BasePageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4902AE76DD500E886FA /* BasePageViewController.m */; };
|
||||
8297E4952AE76EC700E886FA /* HKHTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E4942AE76EC700E886FA /* HKHTextField.m */; };
|
||||
8297E49B2AE7974700E886FA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8297E49A2AE7974700E886FA /* AppDelegate.m */; };
|
||||
82C026542AE8AC6D0011FE6A /* AliyunEmasServices-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 82C026532AE8AC6D0011FE6A /* AliyunEmasServices-Info.plist */; };
|
||||
82C026982AEB6C050011FE6A /* add.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026562AEB6C050011FE6A /* add.png */; };
|
||||
@ -151,81 +110,6 @@
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
8297E40E2AE75AC500E886FA /* XSFlutterManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XSFlutterManager.m; sourceTree = "<group>"; };
|
||||
8297E40F2AE75AC500E886FA /* XSFlutterManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSFlutterManager.h; sourceTree = "<group>"; };
|
||||
8297E4132AE75BEE00E886FA /* Msg.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Msg.m; sourceTree = "<group>"; };
|
||||
8297E4142AE75BEE00E886FA /* UI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UI.h; sourceTree = "<group>"; };
|
||||
8297E4152AE75BEE00E886FA /* HttpManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HttpManager.h; sourceTree = "<group>"; };
|
||||
8297E4172AE75BEE00E886FA /* udp_data_class.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = udp_data_class.m; sourceTree = "<group>"; };
|
||||
8297E4182AE75BEE00E886FA /* UdpHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UdpHelper.m; sourceTree = "<group>"; };
|
||||
8297E4192AE75BEE00E886FA /* udp_data_class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = udp_data_class.h; sourceTree = "<group>"; };
|
||||
8297E41A2AE75BEE00E886FA /* UdpHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UdpHelper.h; sourceTree = "<group>"; };
|
||||
8297E41B2AE75BEE00E886FA /* Sformat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sformat.m; sourceTree = "<group>"; };
|
||||
8297E41C2AE75BEE00E886FA /* Pub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pub.h; sourceTree = "<group>"; };
|
||||
8297E41D2AE75BEE00E886FA /* sysInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sysInfo.h; sourceTree = "<group>"; };
|
||||
8297E41E2AE75BEE00E886FA /* Msg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Msg.h; sourceTree = "<group>"; };
|
||||
8297E41F2AE75BEE00E886FA /* Sformat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sformat.h; sourceTree = "<group>"; };
|
||||
8297E4202AE75BEE00E886FA /* HttpManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HttpManager.m; sourceTree = "<group>"; };
|
||||
8297E4212AE75BEE00E886FA /* UI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UI.m; sourceTree = "<group>"; };
|
||||
8297E4222AE75BEE00E886FA /* sysInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = sysInfo.m; sourceTree = "<group>"; };
|
||||
8297E4232AE75BEE00E886FA /* Pub.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Pub.m; sourceTree = "<group>"; };
|
||||
8297E4252AE75BEE00E886FA /* recordAudio.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = recordAudio.m; sourceTree = "<group>"; };
|
||||
8297E4262AE75BEE00E886FA /* talk_Class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = talk_Class.h; sourceTree = "<group>"; };
|
||||
8297E4272AE75BEE00E886FA /* IframeInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IframeInfo.h; sourceTree = "<group>"; };
|
||||
8297E4282AE75BEE00E886FA /* playAudio.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = playAudio.m; sourceTree = "<group>"; };
|
||||
8297E4292AE75BEE00E886FA /* recordAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recordAudio.h; sourceTree = "<group>"; };
|
||||
8297E42A2AE75BEE00E886FA /* talk_Class.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = talk_Class.m; sourceTree = "<group>"; };
|
||||
8297E42B2AE75BEE00E886FA /* playAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = playAudio.h; sourceTree = "<group>"; };
|
||||
8297E42C2AE75BEE00E886FA /* IframeInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IframeInfo.m; sourceTree = "<group>"; };
|
||||
8297E42E2AE75BEE00E886FA /* Piano.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Piano.caf; sourceTree = "<group>"; };
|
||||
8297E42F2AE75BEE00E886FA /* ring1.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = ring1.mp3; sourceTree = "<group>"; };
|
||||
8297E4302AE75BEE00E886FA /* ok.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = ok.wav; sourceTree = "<group>"; };
|
||||
8297E4312AE75BEE00E886FA /* notice.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = notice.wav; sourceTree = "<group>"; };
|
||||
8297E4322AE75BEE00E886FA /* err.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = err.wav; sourceTree = "<group>"; };
|
||||
8297E4332AE75BEE00E886FA /* alarm.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = alarm.wav; sourceTree = "<group>"; };
|
||||
8297E4352AE75BEE00E886FA /* VideoTalkManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoTalkManager.h; sourceTree = "<group>"; };
|
||||
8297E4362AE75BEE00E886FA /* RingCall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RingCall.m; sourceTree = "<group>"; };
|
||||
8297E4372AE75BEE00E886FA /* RingCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RingCall.h; sourceTree = "<group>"; };
|
||||
8297E4382AE75BEE00E886FA /* VideoTalkManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoTalkManager.m; sourceTree = "<group>"; };
|
||||
8297E4392AE75BEE00E886FA /* voip_call.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = voip_call.caf; sourceTree = "<group>"; };
|
||||
8297E4502AE75D4E00E886FA /* EquList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquList.h; sourceTree = "<group>"; };
|
||||
8297E4512AE75D4E00E886FA /* EquAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquAdd.h; sourceTree = "<group>"; };
|
||||
8297E4522AE75D4E00E886FA /* FaceUpload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FaceUpload.h; sourceTree = "<group>"; };
|
||||
8297E4532AE75D4E00E886FA /* WifiList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WifiList.h; sourceTree = "<group>"; };
|
||||
8297E4542AE75D4E00E886FA /* FaceSubPage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FaceSubPage.m; sourceTree = "<group>"; };
|
||||
8297E4552AE75D4E00E886FA /* EquConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquConfig.m; sourceTree = "<group>"; };
|
||||
8297E4562AE75D4E00E886FA /* OpenPwd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenPwd.m; sourceTree = "<group>"; };
|
||||
8297E4572AE75D4E00E886FA /* P2pTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = P2pTest.h; sourceTree = "<group>"; };
|
||||
8297E4582AE75D4E00E886FA /* Web.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Web.m; sourceTree = "<group>"; };
|
||||
8297E4592AE75D4E00E886FA /* Call.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Call.h; sourceTree = "<group>"; };
|
||||
8297E45A2AE75D4E00E886FA /* Setting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Setting.m; sourceTree = "<group>"; };
|
||||
8297E45B2AE75D4E00E886FA /* FaceUpload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FaceUpload.m; sourceTree = "<group>"; };
|
||||
8297E45C2AE75D4E00E886FA /* EquAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquAdd.m; sourceTree = "<group>"; };
|
||||
8297E45D2AE75D4E00E886FA /* EquList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquList.m; sourceTree = "<group>"; };
|
||||
8297E45E2AE75D4E00E886FA /* FaceSubPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FaceSubPage.h; sourceTree = "<group>"; };
|
||||
8297E45F2AE75D4E00E886FA /* WifiList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WifiList.m; sourceTree = "<group>"; };
|
||||
8297E4602AE75D4E00E886FA /* OpenPwd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenPwd.h; sourceTree = "<group>"; };
|
||||
8297E4612AE75D4E00E886FA /* P2pTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = P2pTest.m; sourceTree = "<group>"; };
|
||||
8297E4622AE75D4E00E886FA /* EquConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquConfig.h; sourceTree = "<group>"; };
|
||||
8297E4632AE75D4E00E886FA /* Setting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Setting.h; sourceTree = "<group>"; };
|
||||
8297E4642AE75D4E00E886FA /* Call.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Call.m; sourceTree = "<group>"; };
|
||||
8297E4652AE75D4E00E886FA /* Web.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Web.h; sourceTree = "<group>"; };
|
||||
8297E4722AE761EB00E886FA /* BaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseViewController.m; sourceTree = "<group>"; };
|
||||
8297E4732AE761EB00E886FA /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = "<group>"; };
|
||||
8297E4762AE7635400E886FA /* Opendoor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Opendoor.h; sourceTree = "<group>"; };
|
||||
8297E4772AE7635400E886FA /* Opendoor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Opendoor.m; sourceTree = "<group>"; };
|
||||
8297E47A2AE7643100E886FA /* AsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncUdpSocket.m; sourceTree = "<group>"; };
|
||||
8297E47B2AE7643100E886FA /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncSocket.h; sourceTree = "<group>"; };
|
||||
8297E47C2AE7643100E886FA /* UIView+AutoLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AutoLayout.m"; sourceTree = "<group>"; };
|
||||
8297E47D2AE7643100E886FA /* UIView+AutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AutoLayout.h"; sourceTree = "<group>"; };
|
||||
8297E47E2AE7643100E886FA /* AsyncSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncSocket.m; sourceTree = "<group>"; };
|
||||
8297E47F2AE7643100E886FA /* AsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncUdpSocket.h; sourceTree = "<group>"; };
|
||||
8297E4862AE768DE00E886FA /* BaseNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = "<group>"; };
|
||||
8297E4872AE768DE00E886FA /* BaseNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
|
||||
8297E48C2AE76D0500E886FA /* BaseTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseTableViewController.h; sourceTree = "<group>"; };
|
||||
8297E48D2AE76D0500E886FA /* BaseTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseTableViewController.m; sourceTree = "<group>"; };
|
||||
8297E48F2AE76DD500E886FA /* BasePageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasePageViewController.h; sourceTree = "<group>"; };
|
||||
8297E4902AE76DD500E886FA /* BasePageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BasePageViewController.m; sourceTree = "<group>"; };
|
||||
8297E4932AE76EC700E886FA /* HKHTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HKHTextField.h; sourceTree = "<group>"; };
|
||||
8297E4942AE76EC700E886FA /* HKHTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HKHTextField.m; sourceTree = "<group>"; };
|
||||
8297E4992AE7974700E886FA /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
8297E49A2AE7974700E886FA /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
82BD91212ADA72360018E523 /* CommonDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonDefine.h; sourceTree = "<group>"; };
|
||||
@ -330,168 +214,6 @@
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4112AE75BEE00E886FA /* XSTalkManager */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4792AE7643100E886FA /* External */,
|
||||
8297E4752AE7635400E886FA /* mainPage */,
|
||||
8297E4712AE761EB00E886FA /* views */,
|
||||
8297E44F2AE75D4E00E886FA /* NextPage */,
|
||||
8297E4122AE75BEE00E886FA /* Utils */,
|
||||
8297E42D2AE75BEE00E886FA /* sound */,
|
||||
8297E4342AE75BEE00E886FA /* pushkit */,
|
||||
);
|
||||
path = XSTalkManager;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4122AE75BEE00E886FA /* Utils */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4132AE75BEE00E886FA /* Msg.m */,
|
||||
8297E41E2AE75BEE00E886FA /* Msg.h */,
|
||||
8297E4142AE75BEE00E886FA /* UI.h */,
|
||||
8297E4212AE75BEE00E886FA /* UI.m */,
|
||||
8297E41C2AE75BEE00E886FA /* Pub.h */,
|
||||
8297E4232AE75BEE00E886FA /* Pub.m */,
|
||||
8297E41F2AE75BEE00E886FA /* Sformat.h */,
|
||||
8297E41B2AE75BEE00E886FA /* Sformat.m */,
|
||||
8297E4152AE75BEE00E886FA /* HttpManager.h */,
|
||||
8297E4202AE75BEE00E886FA /* HttpManager.m */,
|
||||
8297E41D2AE75BEE00E886FA /* sysInfo.h */,
|
||||
8297E4222AE75BEE00E886FA /* sysInfo.m */,
|
||||
8297E4162AE75BEE00E886FA /* UDP */,
|
||||
8297E4242AE75BEE00E886FA /* Talk */,
|
||||
);
|
||||
path = Utils;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4162AE75BEE00E886FA /* UDP */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4192AE75BEE00E886FA /* udp_data_class.h */,
|
||||
8297E4172AE75BEE00E886FA /* udp_data_class.m */,
|
||||
8297E41A2AE75BEE00E886FA /* UdpHelper.h */,
|
||||
8297E4182AE75BEE00E886FA /* UdpHelper.m */,
|
||||
);
|
||||
path = UDP;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4242AE75BEE00E886FA /* Talk */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4272AE75BEE00E886FA /* IframeInfo.h */,
|
||||
8297E42C2AE75BEE00E886FA /* IframeInfo.m */,
|
||||
8297E4292AE75BEE00E886FA /* recordAudio.h */,
|
||||
8297E4252AE75BEE00E886FA /* recordAudio.m */,
|
||||
8297E4262AE75BEE00E886FA /* talk_Class.h */,
|
||||
8297E42A2AE75BEE00E886FA /* talk_Class.m */,
|
||||
8297E42B2AE75BEE00E886FA /* playAudio.h */,
|
||||
8297E4282AE75BEE00E886FA /* playAudio.m */,
|
||||
);
|
||||
path = Talk;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E42D2AE75BEE00E886FA /* sound */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E42E2AE75BEE00E886FA /* Piano.caf */,
|
||||
8297E42F2AE75BEE00E886FA /* ring1.mp3 */,
|
||||
8297E4302AE75BEE00E886FA /* ok.wav */,
|
||||
8297E4312AE75BEE00E886FA /* notice.wav */,
|
||||
8297E4322AE75BEE00E886FA /* err.wav */,
|
||||
8297E4332AE75BEE00E886FA /* alarm.wav */,
|
||||
);
|
||||
path = sound;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4342AE75BEE00E886FA /* pushkit */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4352AE75BEE00E886FA /* VideoTalkManager.h */,
|
||||
8297E4362AE75BEE00E886FA /* RingCall.m */,
|
||||
8297E4372AE75BEE00E886FA /* RingCall.h */,
|
||||
8297E4382AE75BEE00E886FA /* VideoTalkManager.m */,
|
||||
8297E4392AE75BEE00E886FA /* voip_call.caf */,
|
||||
);
|
||||
path = pushkit;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E44F2AE75D4E00E886FA /* NextPage */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4502AE75D4E00E886FA /* EquList.h */,
|
||||
8297E4512AE75D4E00E886FA /* EquAdd.h */,
|
||||
8297E4522AE75D4E00E886FA /* FaceUpload.h */,
|
||||
8297E4532AE75D4E00E886FA /* WifiList.h */,
|
||||
8297E4542AE75D4E00E886FA /* FaceSubPage.m */,
|
||||
8297E4552AE75D4E00E886FA /* EquConfig.m */,
|
||||
8297E4562AE75D4E00E886FA /* OpenPwd.m */,
|
||||
8297E4572AE75D4E00E886FA /* P2pTest.h */,
|
||||
8297E4582AE75D4E00E886FA /* Web.m */,
|
||||
8297E45A2AE75D4E00E886FA /* Setting.m */,
|
||||
8297E45B2AE75D4E00E886FA /* FaceUpload.m */,
|
||||
8297E45C2AE75D4E00E886FA /* EquAdd.m */,
|
||||
8297E45D2AE75D4E00E886FA /* EquList.m */,
|
||||
8297E45E2AE75D4E00E886FA /* FaceSubPage.h */,
|
||||
8297E45F2AE75D4E00E886FA /* WifiList.m */,
|
||||
8297E4602AE75D4E00E886FA /* OpenPwd.h */,
|
||||
8297E4612AE75D4E00E886FA /* P2pTest.m */,
|
||||
8297E4622AE75D4E00E886FA /* EquConfig.h */,
|
||||
8297E4632AE75D4E00E886FA /* Setting.h */,
|
||||
8297E4652AE75D4E00E886FA /* Web.h */,
|
||||
8297E4592AE75D4E00E886FA /* Call.h */,
|
||||
8297E4642AE75D4E00E886FA /* Call.m */,
|
||||
);
|
||||
path = NextPage;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4712AE761EB00E886FA /* views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4922AE76EC700E886FA /* TextField */,
|
||||
8297E48F2AE76DD500E886FA /* BasePageViewController.h */,
|
||||
8297E4902AE76DD500E886FA /* BasePageViewController.m */,
|
||||
8297E48C2AE76D0500E886FA /* BaseTableViewController.h */,
|
||||
8297E48D2AE76D0500E886FA /* BaseTableViewController.m */,
|
||||
8297E4862AE768DE00E886FA /* BaseNavigationController.h */,
|
||||
8297E4872AE768DE00E886FA /* BaseNavigationController.m */,
|
||||
8297E4722AE761EB00E886FA /* BaseViewController.m */,
|
||||
8297E4732AE761EB00E886FA /* BaseViewController.h */,
|
||||
);
|
||||
path = views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4752AE7635400E886FA /* mainPage */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4762AE7635400E886FA /* Opendoor.h */,
|
||||
8297E4772AE7635400E886FA /* Opendoor.m */,
|
||||
);
|
||||
path = mainPage;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4792AE7643100E886FA /* External */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E47A2AE7643100E886FA /* AsyncUdpSocket.m */,
|
||||
8297E47B2AE7643100E886FA /* AsyncSocket.h */,
|
||||
8297E47C2AE7643100E886FA /* UIView+AutoLayout.m */,
|
||||
8297E47D2AE7643100E886FA /* UIView+AutoLayout.h */,
|
||||
8297E47E2AE7643100E886FA /* AsyncSocket.m */,
|
||||
8297E47F2AE7643100E886FA /* AsyncUdpSocket.h */,
|
||||
);
|
||||
path = External;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8297E4922AE76EC700E886FA /* TextField */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8297E4932AE76EC700E886FA /* HKHTextField.h */,
|
||||
8297E4942AE76EC700E886FA /* HKHTextField.m */,
|
||||
);
|
||||
path = TextField;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
82C026552AEB6C050011FE6A /* img */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -605,7 +327,6 @@
|
||||
8297E49A2AE7974700E886FA /* AppDelegate.m */,
|
||||
8297E40F2AE75AC500E886FA /* XSFlutterManager.h */,
|
||||
8297E40E2AE75AC500E886FA /* XSFlutterManager.m */,
|
||||
8297E4112AE75BEE00E886FA /* XSTalkManager */,
|
||||
33BF41252A96174D009D92E2 /* Runner.entitlements */,
|
||||
97C146FA1CF9000F007C117D /* Main.storyboard */,
|
||||
97C146FD1CF9000F007C117D /* Assets.xcassets */,
|
||||
@ -666,7 +387,7 @@
|
||||
97C146E61CF9000F007C117D /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 1300;
|
||||
LastUpgradeCheck = 1430;
|
||||
ORGANIZATIONNAME = "";
|
||||
TargetAttributes = {
|
||||
97C146ED1CF9000F007C117D = {
|
||||
@ -705,17 +426,12 @@
|
||||
82C026542AE8AC6D0011FE6A /* AliyunEmasServices-Info.plist in Resources */,
|
||||
82C026AD2AEB6C050011FE6A /* blank.png in Resources */,
|
||||
82C0269F2AEB6C050011FE6A /* show_head_toast_bg.9.PNG in Resources */,
|
||||
8297E44B2AE75BEE00E886FA /* alarm.wav in Resources */,
|
||||
82C026BA2AEB6C050011FE6A /* logo3.png in Resources */,
|
||||
82C026B22AEB6C050011FE6A /* swicth_minus_on.png in Resources */,
|
||||
82C026C22AEB6C050011FE6A /* shop_loading.png in Resources */,
|
||||
82C026AF2AEB6C050011FE6A /* rotate.png in Resources */,
|
||||
82C026BD2AEB6C050011FE6A /* logo2.png in Resources */,
|
||||
8297E44A2AE75BEE00E886FA /* err.wav in Resources */,
|
||||
8297E4492AE75BEE00E886FA /* notice.wav in Resources */,
|
||||
82C026C62AEB6C050011FE6A /* ic_launcher.png in Resources */,
|
||||
8297E4472AE75BEE00E886FA /* ring1.mp3 in Resources */,
|
||||
8297E44E2AE75BEE00E886FA /* voip_call.caf in Resources */,
|
||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
|
||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
|
||||
82C026D62AEB6C050011FE6A /* vcontacts_on.png in Resources */,
|
||||
@ -724,9 +440,7 @@
|
||||
82C026A12AEB6C050011FE6A /* icon_close.png in Resources */,
|
||||
82C026AB2AEB6C050011FE6A /* vcall.png in Resources */,
|
||||
82C026CE2AEB6C050011FE6A /* split.JPG in Resources */,
|
||||
8297E4462AE75BEE00E886FA /* Piano.caf in Resources */,
|
||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
|
||||
8297E4482AE75BEE00E886FA /* ok.wav in Resources */,
|
||||
82C026A72AEB6C050011FE6A /* zoom.png in Resources */,
|
||||
82C026D42AEB6C050011FE6A /* split4.png in Resources */,
|
||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
|
||||
@ -861,43 +575,9 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8297E49B2AE7974700E886FA /* AppDelegate.m in Sources */,
|
||||
8297E4692AE75D4E00E886FA /* Web.m in Sources */,
|
||||
8297E4742AE761EB00E886FA /* BaseViewController.m in Sources */,
|
||||
8297E43E2AE75BEE00E886FA /* HttpManager.m in Sources */,
|
||||
8297E43F2AE75BEE00E886FA /* UI.m in Sources */,
|
||||
8297E46B2AE75D4E00E886FA /* FaceUpload.m in Sources */,
|
||||
8297E43D2AE75BEE00E886FA /* Sformat.m in Sources */,
|
||||
8297E4672AE75D4E00E886FA /* EquConfig.m in Sources */,
|
||||
8297E4912AE76DD500E886FA /* BasePageViewController.m in Sources */,
|
||||
8297E46C2AE75D4E00E886FA /* EquAdd.m in Sources */,
|
||||
8297E46D2AE75D4E00E886FA /* EquList.m in Sources */,
|
||||
8297E4412AE75BEE00E886FA /* Pub.m in Sources */,
|
||||
8297E4662AE75D4E00E886FA /* FaceSubPage.m in Sources */,
|
||||
8297E4702AE75D4E00E886FA /* Call.m in Sources */,
|
||||
8297E43A2AE75BEE00E886FA /* Msg.m in Sources */,
|
||||
8297E4822AE7643100E886FA /* AsyncSocket.m in Sources */,
|
||||
8297E4952AE76EC700E886FA /* HKHTextField.m in Sources */,
|
||||
8297E43C2AE75BEE00E886FA /* UdpHelper.m in Sources */,
|
||||
8297E4452AE75BEE00E886FA /* IframeInfo.m in Sources */,
|
||||
8297E4102AE75AC500E886FA /* XSFlutterManager.m in Sources */,
|
||||
8297E46A2AE75D4E00E886FA /* Setting.m in Sources */,
|
||||
97C146F31CF9000F007C117D /* main.m in Sources */,
|
||||
8297E4812AE7643100E886FA /* UIView+AutoLayout.m in Sources */,
|
||||
8297E4422AE75BEE00E886FA /* recordAudio.m in Sources */,
|
||||
8297E4432AE75BEE00E886FA /* playAudio.m in Sources */,
|
||||
8297E48E2AE76D0500E886FA /* BaseTableViewController.m in Sources */,
|
||||
8297E4442AE75BEE00E886FA /* talk_Class.m in Sources */,
|
||||
8297E4402AE75BEE00E886FA /* sysInfo.m in Sources */,
|
||||
8297E44C2AE75BEE00E886FA /* RingCall.m in Sources */,
|
||||
8297E4682AE75D4E00E886FA /* OpenPwd.m in Sources */,
|
||||
8297E44D2AE75BEE00E886FA /* VideoTalkManager.m in Sources */,
|
||||
8297E43B2AE75BEE00E886FA /* udp_data_class.m in Sources */,
|
||||
8297E4882AE768DE00E886FA /* BaseNavigationController.m in Sources */,
|
||||
8297E4802AE7643100E886FA /* AsyncUdpSocket.m in Sources */,
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||
8297E4782AE7635400E886FA /* Opendoor.m in Sources */,
|
||||
8297E46F2AE75D4E00E886FA /* P2pTest.m in Sources */,
|
||||
8297E46E2AE75D4E00E886FA /* WifiList.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1430"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@ -8,43 +8,12 @@
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
#import "sysInfo.h"
|
||||
#import "UdpHelper.h"
|
||||
#import "talk_Class.h"
|
||||
#import "Call.h"
|
||||
#import "P2pTest.h"
|
||||
#import "Opendoor.h"
|
||||
#import "HKHTextField.h"
|
||||
#import <CloudPushSDK/CloudPushSDK.h>
|
||||
|
||||
#define SoundOK 0
|
||||
#define SoundNotice 1
|
||||
#define SoundError 2
|
||||
#define SoundAlarm 3
|
||||
#define SoundRing 4
|
||||
|
||||
@interface AppDelegate : FlutterAppDelegate <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
@property (strong, nonatomic) Opendoor *main;
|
||||
@property (strong, nonatomic) Call *callOut;
|
||||
@property (strong, nonatomic) P2pTest *p2ptest;
|
||||
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
|
||||
@property (nonatomic) BOOL isBack;
|
||||
@property (nonatomic) BOOL TalkSendAudio;
|
||||
|
||||
@property sqlite3 *db;
|
||||
@property (strong, nonatomic) sysInfo *sysinfo;
|
||||
@property (strong, nonatomic) UdpHelper *udp;
|
||||
@property (strong, nonatomic) talk_Class *talk;
|
||||
@property (strong, nonatomic) HKHTextField *activeTextField;
|
||||
|
||||
|
||||
- (void)playSoundWith:(NSInteger)mode;
|
||||
- (void)OpenDoorSucc:(NSString *)equid;
|
||||
- (void)OpenDoorFail:(NSString *)equid;
|
||||
- (void)ring;
|
||||
- (void)ring_stop;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -4,12 +4,7 @@
|
||||
#import "CommonDefine.h"
|
||||
#import "XSFlutterManager.h"
|
||||
|
||||
#import "Sformat.h"
|
||||
#import "Pub.h"
|
||||
#import "Msg.h"
|
||||
#import "VideoTalkManager.h"
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
|
||||
@interface AppDelegate()
|
||||
@ -17,15 +12,8 @@
|
||||
@end
|
||||
|
||||
@implementation AppDelegate {
|
||||
SystemSoundID okSound;
|
||||
SystemSoundID noticeSound;
|
||||
SystemSoundID errorSound;
|
||||
SystemSoundID alarmSound;
|
||||
SystemSoundID ringSound;
|
||||
}
|
||||
|
||||
@synthesize sysinfo;
|
||||
@synthesize db;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
@ -36,15 +24,6 @@
|
||||
self.window.rootViewController = VC;
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
//关闭可视对讲功能 需打开时再解注释
|
||||
//[self initSound];
|
||||
//_udp = [[UdpHelper alloc] init];
|
||||
//[_udp Open];
|
||||
//_talk = [[talk_Class alloc] init];
|
||||
|
||||
//sysinfo.launchtime = [Sformat timestamp];
|
||||
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -148,145 +127,6 @@
|
||||
[CloudPushSDK sendNotificationAck:userInfo];
|
||||
}
|
||||
|
||||
- (void)initSound
|
||||
{
|
||||
|
||||
CFURLRef okURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ok" ofType:@"wav"]]);
|
||||
CFURLRef noticeURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
|
||||
CFURLRef errURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"err" ofType:@"wav"]]);
|
||||
CFURLRef alarmURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"]]);
|
||||
CFURLRef ringURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
|
||||
|
||||
AudioServicesCreateSystemSoundID(okURL, &okSound);
|
||||
AudioServicesCreateSystemSoundID(noticeURL, ¬iceSound);
|
||||
AudioServicesCreateSystemSoundID(errURL, &errorSound);
|
||||
AudioServicesCreateSystemSoundID(alarmURL, &alarmSound);
|
||||
AudioServicesCreateSystemSoundID(ringURL, &ringSound);
|
||||
AudioServicesPropertyID flag = 0; //0 means always play
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &okSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), ¬iceSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &errorSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &alarmSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &ringSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
|
||||
CFBridgingRelease(okURL);
|
||||
CFBridgingRelease(noticeURL);
|
||||
CFBridgingRelease(errURL);
|
||||
CFBridgingRelease(alarmURL);
|
||||
CFBridgingRelease(ringURL);
|
||||
}
|
||||
|
||||
|
||||
- (void)playSoundWith:(NSInteger)mode
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
if ([MPMusicPlayerController systemMusicPlayer].playbackState == MPMusicPlaybackStatePlaying) {
|
||||
NSLog(@"play ServicesPlayAlertSound ...");
|
||||
switch (mode) {
|
||||
case SoundOK:
|
||||
AudioServicesPlayAlertSound(self->okSound);
|
||||
break;
|
||||
case SoundNotice:
|
||||
AudioServicesPlayAlertSound(self->noticeSound);
|
||||
break;
|
||||
case SoundError:
|
||||
AudioServicesPlayAlertSound(self->errorSound);
|
||||
break;
|
||||
case SoundAlarm:
|
||||
AudioServicesPlayAlertSound(self->alarmSound);
|
||||
break;
|
||||
case SoundRing:
|
||||
AudioServicesPlayAlertSound(self->ringSound);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"play ServicesPlaySystemSound ...");
|
||||
switch (mode) {
|
||||
case SoundOK:
|
||||
AudioServicesPlaySystemSound(self->okSound);
|
||||
break;
|
||||
case SoundNotice:
|
||||
AudioServicesPlaySystemSound(self->noticeSound);
|
||||
break;
|
||||
case SoundError:
|
||||
AudioServicesPlaySystemSound(self->errorSound);
|
||||
break;
|
||||
case SoundAlarm:
|
||||
AudioServicesPlayAlertSound(self->alarmSound);
|
||||
break;
|
||||
case SoundRing:
|
||||
AudioServicesPlayAlertSound(self->ringSound);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
- (void)ring
|
||||
{
|
||||
if (!self.isBack)[self playaudio];
|
||||
//if (!self.isBack)[self playSoundWith:SoundRing];
|
||||
|
||||
}
|
||||
|
||||
- (void)ring_stop
|
||||
{
|
||||
|
||||
if(self.audioPlayer != nil) {
|
||||
[self.audioPlayer stop];
|
||||
self.audioPlayer = nil;
|
||||
}
|
||||
AVAudioSession *session = [AVAudioSession sharedInstance];
|
||||
[session setActive:YES error:nil];
|
||||
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
|
||||
|
||||
}
|
||||
|
||||
- (void)playaudio
|
||||
{
|
||||
AVAudioSession *session = [AVAudioSession sharedInstance];
|
||||
[session setActive:YES error:nil];
|
||||
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
|
||||
//播放背景音乐
|
||||
NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"ring1" ofType:@"mp3"];
|
||||
|
||||
NSURL *url = [[NSURL alloc] initFileURLWithPath:musicPath];
|
||||
|
||||
// 创建播放器
|
||||
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
|
||||
//[url release];
|
||||
[self.audioPlayer prepareToPlay];
|
||||
|
||||
[self.audioPlayer setVolume:.5];
|
||||
self.audioPlayer.numberOfLoops = -1; //设置音乐播放次数 -1为一直循环
|
||||
[self.audioPlayer play]; //播放
|
||||
NSLog(@"playaudio");
|
||||
}
|
||||
|
||||
- (void)OpenDoorSucc:(NSString *)equid{
|
||||
if(self.callOut){
|
||||
[self.callOut alert:@"开门成功"];
|
||||
}
|
||||
|
||||
[self playSoundWith:SoundOK];
|
||||
[self.sysinfo SaveRecord:[Sformat timestamp] Type:@"开门" Equ:equid Img:@"" Note:@"成功"];
|
||||
}
|
||||
- (void)OpenDoorFail:(NSString *)equid{
|
||||
if(self.callOut){
|
||||
[self.callOut alert:@"开门失败"];
|
||||
NSLog(@"通话中开门失败");
|
||||
}
|
||||
|
||||
[self playSoundWith:SoundError];
|
||||
[self.sysinfo SaveRecord:[Sformat timestamp] Type:@"开门" Equ:equid Img:@"" Note:@"失败"];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -7,34 +7,13 @@
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
#import "sysInfo.h"
|
||||
#import "UdpHelper.h"
|
||||
#import "talk_Class.h"
|
||||
#import "Call.h"
|
||||
#import "P2pTest.h"
|
||||
#import "Opendoor.h"
|
||||
#import "HKHTextField.h"
|
||||
#import "Pub.h"
|
||||
#import "Sformat.h"
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
#define SoundOK 0
|
||||
#define SoundNotice 1
|
||||
#define SoundError 2
|
||||
#define SoundAlarm 3
|
||||
#define SoundRing 4
|
||||
|
||||
|
||||
@interface XSFlutterManager : FlutterViewController
|
||||
|
||||
@property (strong, nonatomic) sysInfo *sysinfo;
|
||||
@property (strong, nonatomic) UdpHelper *udp;
|
||||
@property (strong, nonatomic) talk_Class *talk;
|
||||
@property (strong, nonatomic) HKHTextField *activeTextField;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -18,15 +18,8 @@
|
||||
@end
|
||||
|
||||
@implementation XSFlutterManager{
|
||||
SystemSoundID okSound;
|
||||
SystemSoundID noticeSound;
|
||||
SystemSoundID errorSound;
|
||||
SystemSoundID alarmSound;
|
||||
SystemSoundID ringSound;
|
||||
}
|
||||
|
||||
@synthesize sysinfo;
|
||||
//@synthesize db;
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
@ -62,8 +55,7 @@
|
||||
|
||||
//不出现在活动项目
|
||||
activityVC.excludedActivityTypes = @[UIActivityTypePrint];
|
||||
// [self presentViewController:activityVC animated:YES completion:nil];
|
||||
[[Pub getApp].window.rootViewController presentViewController:activityVC animated:YES completion:nil];
|
||||
[self presentViewController:activityVC animated:YES completion:nil];
|
||||
|
||||
// 分享之后的回调
|
||||
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
||||
@ -76,61 +68,12 @@
|
||||
}
|
||||
};
|
||||
result(@"push返回到flutter");
|
||||
} else if ([method isEqualToString:XSflutterMethodVideoTalk]) {
|
||||
id params = methodCall.arguments;
|
||||
if ([params isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *paramDic = (NSDictionary *)params;
|
||||
NSLog(@"得到了参数%@", paramDic[@"videoTalk"]);
|
||||
}
|
||||
|
||||
sysinfo = [[sysInfo alloc] init];
|
||||
[sysinfo initDB];
|
||||
[sysinfo readSystemInfo];
|
||||
|
||||
// BaseViewController * VC = [[BaseViewController alloc]init];
|
||||
// [Pub getApp].window.rootViewController = VC;
|
||||
// [[Pub getApp].window makeKeyAndVisible];
|
||||
|
||||
[self initSound];
|
||||
_udp = [[UdpHelper alloc] init];
|
||||
[_udp Open];
|
||||
_talk = [[talk_Class alloc] init];
|
||||
|
||||
sysinfo.launchtime = [Sformat timestamp];
|
||||
}
|
||||
|
||||
}];
|
||||
[GeneratedPluginRegistrant registerWithRegistry:self];
|
||||
}
|
||||
|
||||
|
||||
- (void)initSound
|
||||
{
|
||||
|
||||
CFURLRef okURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ok" ofType:@"wav"]]);
|
||||
CFURLRef noticeURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
|
||||
CFURLRef errURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"err" ofType:@"wav"]]);
|
||||
CFURLRef alarmURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"]]);
|
||||
CFURLRef ringURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
|
||||
|
||||
AudioServicesCreateSystemSoundID(okURL, &okSound);
|
||||
AudioServicesCreateSystemSoundID(noticeURL, ¬iceSound);
|
||||
AudioServicesCreateSystemSoundID(errURL, &errorSound);
|
||||
AudioServicesCreateSystemSoundID(alarmURL, &alarmSound);
|
||||
AudioServicesCreateSystemSoundID(ringURL, &ringSound);
|
||||
AudioServicesPropertyID flag = 0; //0 means always play
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &okSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), ¬iceSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &errorSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &alarmSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &ringSound, sizeof(AudioServicesPropertyID), &flag);
|
||||
|
||||
CFBridgingRelease(okURL);
|
||||
CFBridgingRelease(noticeURL);
|
||||
CFBridgingRelease(errURL);
|
||||
CFBridgingRelease(alarmURL);
|
||||
CFBridgingRelease(ringURL);
|
||||
}
|
||||
|
||||
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
|
||||
@ -1,657 +0,0 @@
|
||||
//
|
||||
// AsyncSocket.h
|
||||
//
|
||||
// This class is in the public domain.
|
||||
// Originally created by Dustin Voss on Wed Jan 29 2003.
|
||||
// Updated and maintained by Deusty Designs and the Mac development community.
|
||||
//
|
||||
// http://code.google.com/p/cocoaasyncsocket/
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class AsyncSocket;
|
||||
@class AsyncReadPacket;
|
||||
@class AsyncWritePacket;
|
||||
|
||||
extern NSString *const AsyncSocketException;
|
||||
extern NSString *const AsyncSocketErrorDomain;
|
||||
|
||||
typedef NS_ENUM(NSInteger, AsyncSocketError) {
|
||||
AsyncSocketCFSocketError = kCFSocketError, // From CFSocketError enum.
|
||||
AsyncSocketNoError = 0, // Never used.
|
||||
AsyncSocketCanceledError, // onSocketWillConnect: returned NO.
|
||||
AsyncSocketConnectTimeoutError,
|
||||
AsyncSocketReadMaxedOutError, // Reached set maxLength without completing
|
||||
AsyncSocketReadTimeoutError,
|
||||
AsyncSocketWriteTimeoutError
|
||||
};
|
||||
|
||||
@protocol AsyncSocketDelegate
|
||||
@optional
|
||||
|
||||
/**
|
||||
* In the event of an error, the socket is closed.
|
||||
* You may call "unreadData" during this call-back to get the last bit of data off the socket.
|
||||
* When connecting, this delegate method may be called
|
||||
* before"onSocket:didAcceptNewSocket:" or "onSocket:didConnectToHost:".
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
|
||||
|
||||
/**
|
||||
* Called when a socket disconnects with or without error. If you want to release a socket after it disconnects,
|
||||
* do so here. It is not safe to do that during "onSocket:willDisconnectWithError:".
|
||||
*
|
||||
* If you call the disconnect method, and the socket wasn't already disconnected,
|
||||
* this delegate method will be called before the disconnect method returns.
|
||||
**/
|
||||
- (void)onSocketDidDisconnect:(AsyncSocket *)sock;
|
||||
|
||||
/**
|
||||
* Called when a socket accepts a connection. Another socket is spawned to handle it. The new socket will have
|
||||
* the same delegate and will call "onSocket:didConnectToHost:port:".
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
||||
|
||||
/**
|
||||
* Called when a new socket is spawned to handle a connection. This method should return the run-loop of the
|
||||
* thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used.
|
||||
**/
|
||||
- (NSRunLoop *)onSocket:(AsyncSocket *)sock wantsRunLoopForNewSocket:(AsyncSocket *)newSocket;
|
||||
|
||||
/**
|
||||
* Called when a socket is about to connect. This method should return YES to continue, or NO to abort.
|
||||
* If aborted, will result in AsyncSocketCanceledError.
|
||||
*
|
||||
* If the connectToHost:onPort:error: method was called, the delegate will be able to access and configure the
|
||||
* CFReadStream and CFWriteStream as desired prior to connection.
|
||||
*
|
||||
* If the connectToAddress:error: method was called, the delegate will be able to access and configure the
|
||||
* CFSocket and CFSocketNativeHandle (BSD socket) as desired prior to connection. You will be able to access and
|
||||
* configure the CFReadStream and CFWriteStream in the onSocket:didConnectToHost:port: method.
|
||||
**/
|
||||
- (BOOL)onSocketWillConnect:(AsyncSocket *)sock;
|
||||
|
||||
/**
|
||||
* Called when a socket connects and is ready for reading and writing.
|
||||
* The host parameter will be an IP address, not a DNS name.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port;
|
||||
|
||||
/**
|
||||
* Called when a socket has completed reading the requested data into memory.
|
||||
* Not called if there is an error.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called when a socket has read in data, but has not yet completed the read.
|
||||
* This would occur if using readToData: or readToLength: methods.
|
||||
* It may be used to for things such as updating progress bars.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called when a socket has completed writing the requested data. Not called if there is an error.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called when a socket has written some data, but has not yet completed the entire write.
|
||||
* It may be used to for things such as updating progress bars.
|
||||
**/
|
||||
- (void)onSocket:(AsyncSocket *)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called if a read operation has reached its timeout without completing.
|
||||
* This method allows you to optionally extend the timeout.
|
||||
* If you return a positive time interval (> 0) the read's timeout will be extended by the given amount.
|
||||
* If you don't implement this method, or return a non-positive time interval (<= 0) the read will timeout as usual.
|
||||
*
|
||||
* The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
|
||||
* The length parameter is the number of bytes that have been read so far for the read operation.
|
||||
*
|
||||
* Note that this method may be called multiple times for a single read if you return positive numbers.
|
||||
**/
|
||||
- (NSTimeInterval)onSocket:(AsyncSocket *)sock
|
||||
shouldTimeoutReadWithTag:(long)tag
|
||||
elapsed:(NSTimeInterval)elapsed
|
||||
bytesDone:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* Called if a write operation has reached its timeout without completing.
|
||||
* This method allows you to optionally extend the timeout.
|
||||
* If you return a positive time interval (> 0) the write's timeout will be extended by the given amount.
|
||||
* If you don't implement this method, or return a non-positive time interval (<= 0) the write will timeout as usual.
|
||||
*
|
||||
* The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
|
||||
* The length parameter is the number of bytes that have been written so far for the write operation.
|
||||
*
|
||||
* Note that this method may be called multiple times for a single write if you return positive numbers.
|
||||
**/
|
||||
- (NSTimeInterval)onSocket:(AsyncSocket *)sock
|
||||
shouldTimeoutWriteWithTag:(long)tag
|
||||
elapsed:(NSTimeInterval)elapsed
|
||||
bytesDone:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* Called after the socket has successfully completed SSL/TLS negotiation.
|
||||
* This method is not called unless you use the provided startTLS method.
|
||||
*
|
||||
* If a SSL/TLS negotiation fails (invalid certificate, etc) then the socket will immediately close,
|
||||
* and the onSocket:willDisconnectWithError: delegate method will be called with the specific SSL error code.
|
||||
**/
|
||||
- (void)onSocketDidSecure:(AsyncSocket *)sock;
|
||||
|
||||
@end
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark -
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@interface AsyncSocket : NSObject
|
||||
{
|
||||
CFSocketNativeHandle theNativeSocket4;
|
||||
CFSocketNativeHandle theNativeSocket6;
|
||||
|
||||
CFSocketRef theSocket4; // IPv4 accept or connect socket
|
||||
CFSocketRef theSocket6; // IPv6 accept or connect socket
|
||||
|
||||
CFReadStreamRef theReadStream;
|
||||
CFWriteStreamRef theWriteStream;
|
||||
|
||||
CFRunLoopSourceRef theSource4; // For theSocket4
|
||||
CFRunLoopSourceRef theSource6; // For theSocket6
|
||||
CFRunLoopRef theRunLoop;
|
||||
CFSocketContext theContext;
|
||||
NSArray *theRunLoopModes;
|
||||
|
||||
NSTimer *theConnectTimer;
|
||||
|
||||
NSMutableArray *theReadQueue;
|
||||
AsyncReadPacket *theCurrentRead;
|
||||
NSTimer *theReadTimer;
|
||||
NSMutableData *partialReadBuffer;
|
||||
|
||||
NSMutableArray *theWriteQueue;
|
||||
AsyncWritePacket *theCurrentWrite;
|
||||
NSTimer *theWriteTimer;
|
||||
|
||||
id theDelegate;
|
||||
UInt16 theFlags;
|
||||
|
||||
long theUserData;
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
- (id)initWithDelegate:(id)delegate;
|
||||
- (id)initWithDelegate:(id)delegate userData:(long)userData;
|
||||
|
||||
/* String representation is long but has no "\n". */
|
||||
- (NSString *)description;
|
||||
|
||||
/**
|
||||
* Use "canSafelySetDelegate" to see if there is any pending business (reads and writes) with the current delegate
|
||||
* before changing it. It is, of course, safe to change the delegate before connecting or accepting connections.
|
||||
**/
|
||||
- (id)delegate;
|
||||
- (BOOL)canSafelySetDelegate;
|
||||
- (void)setDelegate:(id)delegate;
|
||||
|
||||
/* User data can be a long, or an id or void * cast to a long. */
|
||||
- (long)userData;
|
||||
- (void)setUserData:(long)userData;
|
||||
|
||||
/* Don't use these to read or write. And don't close them either! */
|
||||
- (CFSocketRef)getCFSocket;
|
||||
- (CFReadStreamRef)getCFReadStream;
|
||||
- (CFWriteStreamRef)getCFWriteStream;
|
||||
|
||||
// Once one of the accept or connect methods are called, the AsyncSocket instance is locked in
|
||||
// and the other accept/connect methods can't be called without disconnecting the socket first.
|
||||
// If the attempt fails or times out, these methods either return NO or
|
||||
// call "onSocket:willDisconnectWithError:" and "onSockedDidDisconnect:".
|
||||
|
||||
// When an incoming connection is accepted, AsyncSocket invokes several delegate methods.
|
||||
// These methods are (in chronological order):
|
||||
// 1. onSocket:didAcceptNewSocket:
|
||||
// 2. onSocket:wantsRunLoopForNewSocket:
|
||||
// 3. onSocketWillConnect:
|
||||
//
|
||||
// Your server code will need to retain the accepted socket (if you want to accept it).
|
||||
// The best place to do this is probably in the onSocket:didAcceptNewSocket: method.
|
||||
//
|
||||
// After the read and write streams have been setup for the newly accepted socket,
|
||||
// the onSocket:didConnectToHost:port: method will be called on the proper run loop.
|
||||
//
|
||||
// Multithreading Note: If you're going to be moving the newly accepted socket to another run
|
||||
// loop by implementing onSocket:wantsRunLoopForNewSocket:, then you should wait until the
|
||||
// onSocket:didConnectToHost:port: method before calling read, write, or startTLS methods.
|
||||
// Otherwise read/write events are scheduled on the incorrect runloop, and chaos may ensue.
|
||||
|
||||
/**
|
||||
* Tells the socket to begin listening and accepting connections on the given port.
|
||||
* When a connection comes in, the AsyncSocket instance will call the various delegate methods (see above).
|
||||
* The socket will listen on all available interfaces (e.g. wifi, ethernet, etc)
|
||||
**/
|
||||
- (BOOL)acceptOnPort:(UInt16)port error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* This method is the same as acceptOnPort:error: with the additional option
|
||||
* of specifying which interface to listen on. So, for example, if you were writing code for a server that
|
||||
* has multiple IP addresses, you could specify which address you wanted to listen on. Or you could use it
|
||||
* to specify that the socket should only accept connections over ethernet, and not other interfaces such as wifi.
|
||||
* You may also use the special strings "localhost" or "loopback" to specify that
|
||||
* the socket only accept connections from the local machine.
|
||||
*
|
||||
* To accept connections on any interface pass nil, or simply use the acceptOnPort:error: method.
|
||||
**/
|
||||
- (BOOL)acceptOnInterface:(NSString *)interface port:(UInt16)port error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Connects to the given host and port.
|
||||
* The host may be a domain name (e.g. "deusty.com") or an IP address string (e.g. "192.168.0.2")
|
||||
**/
|
||||
- (BOOL)connectToHost:(NSString *)hostname onPort:(UInt16)port error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* This method is the same as connectToHost:onPort:error: with an additional timeout option.
|
||||
* To not time out use a negative time interval, or simply use the connectToHost:onPort:error: method.
|
||||
**/
|
||||
- (BOOL)connectToHost:(NSString *)hostname
|
||||
onPort:(UInt16)port
|
||||
withTimeout:(NSTimeInterval)timeout
|
||||
error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Connects to the given address, specified as a sockaddr structure wrapped in a NSData object.
|
||||
* For example, a NSData object returned from NSNetService's addresses method.
|
||||
*
|
||||
* If you have an existing struct sockaddr you can convert it to a NSData object like so:
|
||||
* struct sockaddr sa -> NSData *dsa = [NSData dataWithBytes:&remoteAddr length:remoteAddr.sa_len];
|
||||
* struct sockaddr *sa -> NSData *dsa = [NSData dataWithBytes:remoteAddr length:remoteAddr->sa_len];
|
||||
**/
|
||||
- (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* This method is the same as connectToAddress:error: with an additional timeout option.
|
||||
* To not time out use a negative time interval, or simply use the connectToAddress:error: method.
|
||||
**/
|
||||
- (BOOL)connectToAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr;
|
||||
|
||||
- (BOOL)connectToAddress:(NSData *)remoteAddr
|
||||
viaInterfaceAddress:(NSData *)interfaceAddr
|
||||
withTimeout:(NSTimeInterval)timeout
|
||||
error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Disconnects immediately. Any pending reads or writes are dropped.
|
||||
* If the socket is not already disconnected, the onSocketDidDisconnect delegate method
|
||||
* will be called immediately, before this method returns.
|
||||
*
|
||||
* Please note the recommended way of releasing an AsyncSocket instance (e.g. in a dealloc method)
|
||||
* [asyncSocket setDelegate:nil];
|
||||
* [asyncSocket disconnect];
|
||||
* [asyncSocket release];
|
||||
**/
|
||||
- (void)disconnect;
|
||||
|
||||
/**
|
||||
* Disconnects after all pending reads have completed.
|
||||
* After calling this, the read and write methods will do nothing.
|
||||
* The socket will disconnect even if there are still pending writes.
|
||||
**/
|
||||
- (void)disconnectAfterReading;
|
||||
|
||||
/**
|
||||
* Disconnects after all pending writes have completed.
|
||||
* After calling this, the read and write methods will do nothing.
|
||||
* The socket will disconnect even if there are still pending reads.
|
||||
**/
|
||||
- (void)disconnectAfterWriting;
|
||||
|
||||
/**
|
||||
* Disconnects after all pending reads and writes have completed.
|
||||
* After calling this, the read and write methods will do nothing.
|
||||
**/
|
||||
- (void)disconnectAfterReadingAndWriting;
|
||||
|
||||
/* Returns YES if the socket and streams are open, connected, and ready for reading and writing. */
|
||||
- (BOOL)isConnected;
|
||||
|
||||
/**
|
||||
* Returns the local or remote host and port to which this socket is connected, or nil and 0 if not connected.
|
||||
* The host will be an IP address.
|
||||
**/
|
||||
- (NSString *)connectedHost;
|
||||
- (UInt16)connectedPort;
|
||||
|
||||
- (NSString *)localHost;
|
||||
- (UInt16)localPort;
|
||||
|
||||
/**
|
||||
* Returns the local or remote address to which this socket is connected,
|
||||
* specified as a sockaddr structure wrapped in a NSData object.
|
||||
*
|
||||
* See also the connectedHost, connectedPort, localHost and localPort methods.
|
||||
**/
|
||||
- (NSData *)connectedAddress;
|
||||
- (NSData *)localAddress;
|
||||
|
||||
/**
|
||||
* Returns whether the socket is IPv4 or IPv6.
|
||||
* An accepting socket may be both.
|
||||
**/
|
||||
- (BOOL)isIPv4;
|
||||
- (BOOL)isIPv6;
|
||||
|
||||
// The readData and writeData methods won't block (they are asynchronous).
|
||||
//
|
||||
// When a read is complete the onSocket:didReadData:withTag: delegate method is called.
|
||||
// When a write is complete the onSocket:didWriteDataWithTag: delegate method is called.
|
||||
//
|
||||
// You may optionally set a timeout for any read/write operation. (To not timeout, use a negative time interval.)
|
||||
// If a read/write opertion times out, the corresponding "onSocket:shouldTimeout..." delegate method
|
||||
// is called to optionally allow you to extend the timeout.
|
||||
// Upon a timeout, the "onSocket:willDisconnectWithError:" method is called, followed by "onSocketDidDisconnect".
|
||||
//
|
||||
// The tag is for your convenience.
|
||||
// You can use it as an array index, step number, state id, pointer, etc.
|
||||
|
||||
/**
|
||||
* Reads the first available bytes that become available on the socket.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
**/
|
||||
- (void)readDataWithTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads the first available bytes that become available on the socket.
|
||||
* The bytes will be appended to the given byte buffer starting at the given offset.
|
||||
* The given buffer will automatically be increased in size if needed.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
* If the buffer if nil, the socket will create a buffer for you.
|
||||
*
|
||||
* If the bufferOffset is greater than the length of the given buffer,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
|
||||
* After completion, the data returned in onSocket:didReadData:withTag: will be a subset of the given buffer.
|
||||
* That is, it will reference the bytes that were appended to the given buffer.
|
||||
**/
|
||||
- (void)readDataWithTimeout:(NSTimeInterval)timeout
|
||||
buffer:(NSMutableData *)buffer
|
||||
bufferOffset:(NSUInteger)offset
|
||||
tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads the first available bytes that become available on the socket.
|
||||
* The bytes will be appended to the given byte buffer starting at the given offset.
|
||||
* The given buffer will automatically be increased in size if needed.
|
||||
* A maximum of length bytes will be read.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
* If the buffer if nil, a buffer will automatically be created for you.
|
||||
* If maxLength is zero, no length restriction is enforced.
|
||||
*
|
||||
* If the bufferOffset is greater than the length of the given buffer,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
|
||||
* After completion, the data returned in onSocket:didReadData:withTag: will be a subset of the given buffer.
|
||||
* That is, it will reference the bytes that were appended to the given buffer.
|
||||
**/
|
||||
- (void)readDataWithTimeout:(NSTimeInterval)timeout
|
||||
buffer:(NSMutableData *)buffer
|
||||
bufferOffset:(NSUInteger)offset
|
||||
maxLength:(NSUInteger)length
|
||||
tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads the given number of bytes.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
*
|
||||
* If the length is 0, this method does nothing and the delegate is not called.
|
||||
**/
|
||||
- (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads the given number of bytes.
|
||||
* The bytes will be appended to the given byte buffer starting at the given offset.
|
||||
* The given buffer will automatically be increased in size if needed.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
* If the buffer if nil, a buffer will automatically be created for you.
|
||||
*
|
||||
* If the length is 0, this method does nothing and the delegate is not called.
|
||||
* If the bufferOffset is greater than the length of the given buffer,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
|
||||
* After completion, the data returned in onSocket:didReadData:withTag: will be a subset of the given buffer.
|
||||
* That is, it will reference the bytes that were appended to the given buffer.
|
||||
**/
|
||||
- (void)readDataToLength:(NSUInteger)length
|
||||
withTimeout:(NSTimeInterval)timeout
|
||||
buffer:(NSMutableData *)buffer
|
||||
bufferOffset:(NSUInteger)offset
|
||||
tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
*
|
||||
* If you pass nil or zero-length data as the "data" parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
|
||||
* Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
|
||||
* a character, the read will prematurely end.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
|
||||
* The bytes will be appended to the given byte buffer starting at the given offset.
|
||||
* The given buffer will automatically be increased in size if needed.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
* If the buffer if nil, a buffer will automatically be created for you.
|
||||
*
|
||||
* If the bufferOffset is greater than the length of the given buffer,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
|
||||
* After completion, the data returned in onSocket:didReadData:withTag: will be a subset of the given buffer.
|
||||
* That is, it will reference the bytes that were appended to the given buffer.
|
||||
*
|
||||
* To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
|
||||
* Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
|
||||
* a character, the read will prematurely end.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data
|
||||
withTimeout:(NSTimeInterval)timeout
|
||||
buffer:(NSMutableData *)buffer
|
||||
bufferOffset:(NSUInteger)offset
|
||||
tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
*
|
||||
* If maxLength is zero, no length restriction is enforced.
|
||||
* Otherwise if maxLength bytes are read without completing the read,
|
||||
* it is treated similarly to a timeout - the socket is closed with a AsyncSocketReadMaxedOutError.
|
||||
* The read will complete successfully if exactly maxLength bytes are read and the given data is found at the end.
|
||||
*
|
||||
* If you pass nil or zero-length data as the "data" parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
* If you pass a maxLength parameter that is less than the length of the data parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
|
||||
* Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
|
||||
* a character, the read will prematurely end.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout maxLength:(NSUInteger)length tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
|
||||
* The bytes will be appended to the given byte buffer starting at the given offset.
|
||||
* The given buffer will automatically be increased in size if needed.
|
||||
* A maximum of length bytes will be read.
|
||||
*
|
||||
* If the timeout value is negative, the read operation will not use a timeout.
|
||||
* If the buffer if nil, a buffer will automatically be created for you.
|
||||
*
|
||||
* If maxLength is zero, no length restriction is enforced.
|
||||
* Otherwise if maxLength bytes are read without completing the read,
|
||||
* it is treated similarly to a timeout - the socket is closed with a AsyncSocketReadMaxedOutError.
|
||||
* The read will complete successfully if exactly maxLength bytes are read and the given data is found at the end.
|
||||
*
|
||||
* If you pass a maxLength parameter that is less than the length of the data parameter,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
* If the bufferOffset is greater than the length of the given buffer,
|
||||
* the method will do nothing, and the delegate will not be called.
|
||||
*
|
||||
* If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
|
||||
* After completion, the data returned in onSocket:didReadData:withTag: will be a subset of the given buffer.
|
||||
* That is, it will reference the bytes that were appended to the given buffer.
|
||||
*
|
||||
* To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
|
||||
* Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
|
||||
* a character, the read will prematurely end.
|
||||
**/
|
||||
- (void)readDataToData:(NSData *)data
|
||||
withTimeout:(NSTimeInterval)timeout
|
||||
buffer:(NSMutableData *)buffer
|
||||
bufferOffset:(NSUInteger)offset
|
||||
maxLength:(NSUInteger)length
|
||||
tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Writes data to the socket, and calls the delegate when finished.
|
||||
*
|
||||
* If you pass in nil or zero-length data, this method does nothing and the delegate will not be called.
|
||||
* If the timeout value is negative, the write operation will not use a timeout.
|
||||
**/
|
||||
- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Returns progress of current read or write, from 0.0 to 1.0, or NaN if no read/write (use isnan() to check).
|
||||
* "tag", "done" and "total" will be filled in if they aren't NULL.
|
||||
**/
|
||||
- (float)progressOfReadReturningTag:(long *)tag bytesDone:(NSUInteger *)done total:(NSUInteger *)total;
|
||||
- (float)progressOfWriteReturningTag:(long *)tag bytesDone:(NSUInteger *)done total:(NSUInteger *)total;
|
||||
|
||||
/**
|
||||
* Secures the connection using SSL/TLS.
|
||||
*
|
||||
* This method may be called at any time, and the TLS handshake will occur after all pending reads and writes
|
||||
* are finished. This allows one the option of sending a protocol dependent StartTLS message, and queuing
|
||||
* the upgrade to TLS at the same time, without having to wait for the write to finish.
|
||||
* Any reads or writes scheduled after this method is called will occur over the secured connection.
|
||||
*
|
||||
* The possible keys and values for the TLS settings are well documented.
|
||||
* Some possible keys are:
|
||||
* - kCFStreamSSLLevel
|
||||
* - kCFStreamSSLAllowsExpiredCertificates
|
||||
* - kCFStreamSSLAllowsExpiredRoots
|
||||
* - kCFStreamSSLAllowsAnyRoot
|
||||
* - kCFStreamSSLValidatesCertificateChain
|
||||
* - kCFStreamSSLPeerName
|
||||
* - kCFStreamSSLCertificates
|
||||
* - kCFStreamSSLIsServer
|
||||
*
|
||||
* Please refer to Apple's documentation for associated values, as well as other possible keys.
|
||||
*
|
||||
* If you pass in nil or an empty dictionary, the default settings will be used.
|
||||
*
|
||||
* The default settings will check to make sure the remote party's certificate is signed by a
|
||||
* trusted 3rd party certificate agency (e.g. verisign) and that the certificate is not expired.
|
||||
* However it will not verify the name on the certificate unless you
|
||||
* give it a name to verify against via the kCFStreamSSLPeerName key.
|
||||
* The security implications of this are important to understand.
|
||||
* Imagine you are attempting to create a secure connection to MySecureServer.com,
|
||||
* but your socket gets directed to MaliciousServer.com because of a hacked DNS server.
|
||||
* If you simply use the default settings, and MaliciousServer.com has a valid certificate,
|
||||
* the default settings will not detect any problems since the certificate is valid.
|
||||
* To properly secure your connection in this particular scenario you
|
||||
* should set the kCFStreamSSLPeerName property to "MySecureServer.com".
|
||||
* If you do not know the peer name of the remote host in advance (for example, you're not sure
|
||||
* if it will be "domain.com" or "www.domain.com"), then you can use the default settings to validate the
|
||||
* certificate, and then use the X509Certificate class to verify the issuer after the socket has been secured.
|
||||
* The X509Certificate class is part of the CocoaAsyncSocket open source project.
|
||||
**/
|
||||
- (void)startTLS:(NSDictionary *)tlsSettings;
|
||||
|
||||
/**
|
||||
* For handling readDataToData requests, data is necessarily read from the socket in small increments.
|
||||
* The performance can be much improved by allowing AsyncSocket to read larger chunks at a time and
|
||||
* store any overflow in a small internal buffer.
|
||||
* This is termed pre-buffering, as some data may be read for you before you ask for it.
|
||||
* If you use readDataToData a lot, enabling pre-buffering will result in better performance, especially on the iPhone.
|
||||
*
|
||||
* The default pre-buffering state is controlled by the DEFAULT_PREBUFFERING definition.
|
||||
* It is highly recommended one leave this set to YES.
|
||||
*
|
||||
* This method exists in case pre-buffering needs to be disabled by default for some unforeseen reason.
|
||||
* In that case, this method exists to allow one to easily enable pre-buffering when ready.
|
||||
**/
|
||||
- (void)enablePreBuffering;
|
||||
|
||||
/**
|
||||
* When you create an AsyncSocket, it is added to the runloop of the current thread.
|
||||
* So for manually created sockets, it is easiest to simply create the socket on the thread you intend to use it.
|
||||
*
|
||||
* If a new socket is accepted, the delegate method onSocket:wantsRunLoopForNewSocket: is called to
|
||||
* allow you to place the socket on a separate thread. This works best in conjunction with a thread pool design.
|
||||
*
|
||||
* If, however, you need to move the socket to a separate thread at a later time, this
|
||||
* method may be used to accomplish the task.
|
||||
*
|
||||
* This method must be called from the thread/runloop the socket is currently running on.
|
||||
*
|
||||
* Note: After calling this method, all further method calls to this object should be done from the given runloop.
|
||||
* Also, all delegate calls will be sent on the given runloop.
|
||||
**/
|
||||
- (BOOL)moveToRunLoop:(NSRunLoop *)runLoop;
|
||||
|
||||
/**
|
||||
* Allows you to configure which run loop modes the socket uses.
|
||||
* The default set of run loop modes is NSDefaultRunLoopMode.
|
||||
*
|
||||
* If you'd like your socket to continue operation during other modes, you may want to add modes such as
|
||||
* NSModalPanelRunLoopMode or NSEventTrackingRunLoopMode. Or you may simply want to use NSRunLoopCommonModes.
|
||||
*
|
||||
* Accepted sockets will automatically inherit the same run loop modes as the listening socket.
|
||||
*
|
||||
* Note: NSRunLoopCommonModes is defined in 10.5. For previous versions one can use kCFRunLoopCommonModes.
|
||||
**/
|
||||
- (BOOL)setRunLoopModes:(NSArray *)runLoopModes;
|
||||
- (BOOL)addRunLoopMode:(NSString *)runLoopMode;
|
||||
- (BOOL)removeRunLoopMode:(NSString *)runLoopMode;
|
||||
|
||||
/**
|
||||
* Returns the current run loop modes the AsyncSocket instance is operating in.
|
||||
* The default set of run loop modes is NSDefaultRunLoopMode.
|
||||
**/
|
||||
- (NSArray *)runLoopModes;
|
||||
|
||||
/**
|
||||
* In the event of an error, this method may be called during onSocket:willDisconnectWithError: to read
|
||||
* any data that's left on the socket.
|
||||
**/
|
||||
- (NSData *)unreadData;
|
||||
|
||||
/* A few common line separators, for use with the readDataToData:... methods. */
|
||||
+ (NSData *)CRLFData; // 0x0D0A
|
||||
+ (NSData *)CRData; // 0x0D
|
||||
+ (NSData *)LFData; // 0x0A
|
||||
+ (NSData *)ZeroData; // 0x00
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,368 +0,0 @@
|
||||
//
|
||||
// AsyncUdpSocket.h
|
||||
//
|
||||
// This class is in the public domain.
|
||||
// Originally created by Robbie Hanson on Wed Oct 01 2008.
|
||||
// Updated and maintained by Deusty Designs and the Mac development community.
|
||||
//
|
||||
// http://code.google.com/p/cocoaasyncsocket/
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class AsyncSendPacket;
|
||||
@class AsyncReceivePacket;
|
||||
|
||||
extern NSString *const AsyncUdpSocketException;
|
||||
extern NSString *const AsyncUdpSocketErrorDomain;
|
||||
|
||||
typedef NS_ENUM(NSInteger, AsyncUdpSocketError) {
|
||||
AsyncUdpSocketCFSocketError = kCFSocketError, // From CFSocketError enum
|
||||
AsyncUdpSocketNoError = 0, // Never used
|
||||
AsyncUdpSocketBadParameter, // Used if given a bad parameter (such as an improper address)
|
||||
AsyncUdpSocketIPv4Unavailable, // Used if you bind/connect using IPv6 only
|
||||
AsyncUdpSocketIPv6Unavailable, // Used if you bind/connect using IPv4 only (or iPhone)
|
||||
AsyncUdpSocketSendTimeoutError,
|
||||
AsyncUdpSocketReceiveTimeoutError
|
||||
};
|
||||
|
||||
@interface AsyncUdpSocket : NSObject
|
||||
{
|
||||
CFSocketRef theSocket4; // IPv4 socket
|
||||
CFSocketRef theSocket6; // IPv6 socket
|
||||
|
||||
CFRunLoopSourceRef theSource4; // For theSocket4
|
||||
CFRunLoopSourceRef theSource6; // For theSocket6
|
||||
CFRunLoopRef theRunLoop;
|
||||
CFSocketContext theContext;
|
||||
NSArray *theRunLoopModes;
|
||||
|
||||
NSMutableArray *theSendQueue;
|
||||
AsyncSendPacket *theCurrentSend;
|
||||
NSTimer *theSendTimer;
|
||||
|
||||
NSMutableArray *theReceiveQueue;
|
||||
AsyncReceivePacket *theCurrentReceive;
|
||||
NSTimer *theReceiveTimer;
|
||||
|
||||
id theDelegate;
|
||||
UInt16 theFlags;
|
||||
|
||||
long theUserData;
|
||||
|
||||
NSString *cachedLocalHost;
|
||||
UInt16 cachedLocalPort;
|
||||
|
||||
NSString *cachedConnectedHost;
|
||||
UInt16 cachedConnectedPort;
|
||||
|
||||
UInt32 maxReceiveBufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new instances of AsyncUdpSocket.
|
||||
**/
|
||||
- (id)init;
|
||||
- (id)initWithDelegate:(id)delegate;
|
||||
- (id)initWithDelegate:(id)delegate userData:(long)userData;
|
||||
|
||||
/**
|
||||
* Creates new instances of AsyncUdpSocket that support only IPv4 or IPv6.
|
||||
* The other init methods will support both, unless specifically binded or connected to one protocol.
|
||||
* If you know you'll only be using one protocol, these init methods may be a bit more efficient.
|
||||
**/
|
||||
- (id)initIPv4;
|
||||
- (id)initIPv6;
|
||||
|
||||
- (id)delegate;
|
||||
- (void)setDelegate:(id)delegate;
|
||||
|
||||
- (long)userData;
|
||||
- (void)setUserData:(long)userData;
|
||||
|
||||
/**
|
||||
* Returns the local address info for the socket.
|
||||
*
|
||||
* Note: Address info may not be available until after the socket has been bind'ed,
|
||||
* or until after data has been sent.
|
||||
**/
|
||||
- (NSString *)localHost;
|
||||
- (UInt16)localPort;
|
||||
|
||||
/**
|
||||
* Returns the remote address info for the socket.
|
||||
*
|
||||
* Note: Since UDP is connectionless by design, connected address info
|
||||
* will not be available unless the socket is explicitly connected to a remote host/port
|
||||
**/
|
||||
- (NSString *)connectedHost;
|
||||
- (UInt16)connectedPort;
|
||||
|
||||
/**
|
||||
* Returns whether or not this socket has been connected to a single host.
|
||||
* By design, UDP is a connectionless protocol, and connecting is not needed.
|
||||
* If connected, the socket will only be able to send/receive data to/from the connected host.
|
||||
**/
|
||||
- (BOOL)isConnected;
|
||||
|
||||
/**
|
||||
* Returns whether or not this socket has been closed.
|
||||
* The only way a socket can be closed is if you explicitly call one of the close methods.
|
||||
**/
|
||||
- (BOOL)isClosed;
|
||||
|
||||
/**
|
||||
* Returns whether or not this socket supports IPv4.
|
||||
* By default this will be true, unless the socket is specifically initialized as IPv6 only,
|
||||
* or is binded or connected to an IPv6 address.
|
||||
**/
|
||||
- (BOOL)isIPv4;
|
||||
|
||||
/**
|
||||
* Returns whether or not this socket supports IPv6.
|
||||
* By default this will be true, unless the socket is specifically initialized as IPv4 only,
|
||||
* or is binded or connected to an IPv4 address.
|
||||
*
|
||||
* This method will also return false on platforms that do not support IPv6.
|
||||
* Note: The iPhone does not currently support IPv6.
|
||||
**/
|
||||
- (BOOL)isIPv6;
|
||||
|
||||
/**
|
||||
* Returns the mtu of the socket.
|
||||
* If unknown, returns zero.
|
||||
*
|
||||
* Sending data larger than this may result in an error.
|
||||
* This is an advanced topic, and one should understand the wide range of mtu's on networks and the internet.
|
||||
* Therefore this method is only for reference and may be of little use in many situations.
|
||||
**/
|
||||
- (unsigned int)maximumTransmissionUnit;
|
||||
|
||||
/**
|
||||
* Binds the UDP socket to the given port and optional address.
|
||||
* Binding should be done for server sockets that receive data prior to sending it.
|
||||
* Client sockets can skip binding,
|
||||
* as the OS will automatically assign the socket an available port when it starts sending data.
|
||||
*
|
||||
* You cannot bind a socket after its been connected.
|
||||
* You can only bind a socket once.
|
||||
* You can still connect a socket (if desired) after binding.
|
||||
*
|
||||
* On success, returns YES.
|
||||
* Otherwise returns NO, and sets errPtr. If you don't care about the error, you can pass nil for errPtr.
|
||||
**/
|
||||
- (BOOL)bindToPort:(UInt16)port error:(NSError **)errPtr;
|
||||
- (BOOL)bindToAddress:(NSString *)localAddr port:(UInt16)port error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Connects the UDP socket to the given host and port.
|
||||
* By design, UDP is a connectionless protocol, and connecting is not needed.
|
||||
*
|
||||
* Choosing to connect to a specific host/port has the following effect:
|
||||
* - You will only be able to send data to the connected host/port.
|
||||
* - You will only be able to receive data from the connected host/port.
|
||||
* - You will receive ICMP messages that come from the connected host/port, such as "connection refused".
|
||||
*
|
||||
* Connecting a UDP socket does not result in any communication on the socket.
|
||||
* It simply changes the internal state of the socket.
|
||||
*
|
||||
* You cannot bind a socket after its been connected.
|
||||
* You can only connect a socket once.
|
||||
*
|
||||
* On success, returns YES.
|
||||
* Otherwise returns NO, and sets errPtr. If you don't care about the error, you can pass nil for errPtr.
|
||||
**/
|
||||
- (BOOL)connectToHost:(NSString *)host onPort:(UInt16)port error:(NSError **)errPtr;
|
||||
- (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Join multicast group
|
||||
*
|
||||
* Group should be an IP address (eg @"225.228.0.1")
|
||||
**/
|
||||
- (BOOL)joinMulticastGroup:(NSString *)group error:(NSError **)errPtr;
|
||||
- (BOOL)joinMulticastGroup:(NSString *)group withAddress:(NSString *)interface error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* By default, the underlying socket in the OS will not allow you to send broadcast messages.
|
||||
* In order to send broadcast messages, you need to enable this functionality in the socket.
|
||||
*
|
||||
* A broadcast is a UDP message to addresses like "192.168.255.255" or "255.255.255.255" that is
|
||||
* delivered to every host on the network.
|
||||
* The reason this is generally disabled by default is to prevent
|
||||
* accidental broadcast messages from flooding the network.
|
||||
**/
|
||||
- (BOOL)enableBroadcast:(BOOL)flag error:(NSError **)errPtr;
|
||||
|
||||
/**
|
||||
* Asynchronously sends the given data, with the given timeout and tag.
|
||||
*
|
||||
* This method may only be used with a connected socket.
|
||||
*
|
||||
* If data is nil or zero-length, this method does nothing and immediately returns NO.
|
||||
* If the socket is not connected, this method does nothing and immediately returns NO.
|
||||
**/
|
||||
- (BOOL)sendData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Asynchronously sends the given data, with the given timeout and tag, to the given host and port.
|
||||
*
|
||||
* This method cannot be used with a connected socket.
|
||||
*
|
||||
* If data is nil or zero-length, this method does nothing and immediately returns NO.
|
||||
* If the socket is connected, this method does nothing and immediately returns NO.
|
||||
* If unable to resolve host to a valid IPv4 or IPv6 address, this method returns NO.
|
||||
**/
|
||||
- (BOOL)sendData:(NSData *)data toHost:(NSString *)host port:(UInt16)port withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Asynchronously sends the given data, with the given timeout and tag, to the given address.
|
||||
*
|
||||
* This method cannot be used with a connected socket.
|
||||
*
|
||||
* If data is nil or zero-length, this method does nothing and immediately returns NO.
|
||||
* If the socket is connected, this method does nothing and immediately returns NO.
|
||||
**/
|
||||
- (BOOL)sendData:(NSData *)data toAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Asynchronously receives a single datagram packet.
|
||||
*
|
||||
* If the receive succeeds, the onUdpSocket:didReceiveData:fromHost:port:tag delegate method will be called.
|
||||
* Otherwise, a timeout will occur, and the onUdpSocket:didNotReceiveDataWithTag: delegate method will be called.
|
||||
**/
|
||||
- (void)receiveWithTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||
|
||||
/**
|
||||
* Closes the socket immediately. Any pending send or receive operations are dropped.
|
||||
**/
|
||||
- (void)close;
|
||||
|
||||
/**
|
||||
* Closes after all pending send operations have completed.
|
||||
* After calling this, the sendData: and receive: methods will do nothing.
|
||||
* In other words, you won't be able to add any more send or receive operations to the queue.
|
||||
* The socket will close even if there are still pending receive operations.
|
||||
**/
|
||||
- (void)closeAfterSending;
|
||||
|
||||
/**
|
||||
* Closes after all pending receive operations have completed.
|
||||
* After calling this, the sendData: and receive: methods will do nothing.
|
||||
* In other words, you won't be able to add any more send or receive operations to the queue.
|
||||
* The socket will close even if there are still pending send operations.
|
||||
**/
|
||||
- (void)closeAfterReceiving;
|
||||
|
||||
/**
|
||||
* Closes after all pending send and receive operations have completed.
|
||||
* After calling this, the sendData: and receive: methods will do nothing.
|
||||
* In other words, you won't be able to add any more send or receive operations to the queue.
|
||||
**/
|
||||
- (void)closeAfterSendingAndReceiving;
|
||||
|
||||
/**
|
||||
* Gets/Sets the maximum size of the buffer that will be allocated for receive operations.
|
||||
* The default size is 9216 bytes.
|
||||
*
|
||||
* The theoretical maximum size of any IPv4 UDP packet is UINT16_MAX = 65535.
|
||||
* The theoretical maximum size of any IPv6 UDP packet is UINT32_MAX = 4294967295.
|
||||
*
|
||||
* In practice, however, the size of UDP packets will be much smaller.
|
||||
* Indeed most protocols will send and receive packets of only a few bytes,
|
||||
* or will set a limit on the size of packets to prevent fragmentation in the IP layer.
|
||||
*
|
||||
* If you set the buffer size too small, the sockets API in the OS will silently discard
|
||||
* any extra data, and you will not be notified of the error.
|
||||
**/
|
||||
- (UInt32)maxReceiveBufferSize;
|
||||
- (void)setMaxReceiveBufferSize:(UInt32)max;
|
||||
|
||||
/**
|
||||
* When you create an AsyncUdpSocket, it is added to the runloop of the current thread.
|
||||
* So it is easiest to simply create the socket on the thread you intend to use it.
|
||||
*
|
||||
* If, however, you need to move the socket to a separate thread at a later time, this
|
||||
* method may be used to accomplish the task.
|
||||
*
|
||||
* This method must be called from the thread/runloop the socket is currently running on.
|
||||
*
|
||||
* Note: After calling this method, all further method calls to this object should be done from the given runloop.
|
||||
* Also, all delegate calls will be sent on the given runloop.
|
||||
**/
|
||||
- (BOOL)moveToRunLoop:(NSRunLoop *)runLoop;
|
||||
|
||||
/**
|
||||
* Allows you to configure which run loop modes the socket uses.
|
||||
* The default set of run loop modes is NSDefaultRunLoopMode.
|
||||
*
|
||||
* If you'd like your socket to continue operation during other modes, you may want to add modes such as
|
||||
* NSModalPanelRunLoopMode or NSEventTrackingRunLoopMode. Or you may simply want to use NSRunLoopCommonModes.
|
||||
*
|
||||
* Note: NSRunLoopCommonModes is defined in 10.5. For previous versions one can use kCFRunLoopCommonModes.
|
||||
**/
|
||||
- (BOOL)setRunLoopModes:(NSArray *)runLoopModes;
|
||||
|
||||
/**
|
||||
* Returns the current run loop modes the AsyncSocket instance is operating in.
|
||||
* The default set of run loop modes is NSDefaultRunLoopMode.
|
||||
**/
|
||||
- (NSArray *)runLoopModes;
|
||||
|
||||
@end
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark -
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@protocol AsyncUdpSocketDelegate
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Called when the datagram with the given tag has been sent.
|
||||
**/
|
||||
- (void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag;
|
||||
|
||||
/**
|
||||
* Called if an error occurs while trying to send a datagram.
|
||||
* This could be due to a timeout, or something more serious such as the data being too large to fit in a sigle packet.
|
||||
**/
|
||||
- (void)onUdpSocket:(AsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error;
|
||||
|
||||
/**
|
||||
* Called when the socket has received the requested datagram.
|
||||
*
|
||||
* Due to the nature of UDP, you may occasionally receive undesired packets.
|
||||
* These may be rogue UDP packets from unknown hosts,
|
||||
* or they may be delayed packets arriving after retransmissions have already occurred.
|
||||
* It's important these packets are properly ignored, while not interfering with the flow of your implementation.
|
||||
* As an aid, this delegate method has a boolean return value.
|
||||
* If you ever need to ignore a received packet, simply return NO,
|
||||
* and AsyncUdpSocket will continue as if the packet never arrived.
|
||||
* That is, the original receive request will still be queued, and will still timeout as usual if a timeout was set.
|
||||
* For example, say you requested to receive data, and you set a timeout of 500 milliseconds, using a tag of 15.
|
||||
* If rogue data arrives after 250 milliseconds, this delegate method would be invoked, and you could simply return NO.
|
||||
* If the expected data then arrives within the next 250 milliseconds,
|
||||
* this delegate method will be invoked, with a tag of 15, just as if the rogue data never appeared.
|
||||
*
|
||||
* Under normal circumstances, you simply return YES from this method.
|
||||
**/
|
||||
- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock
|
||||
didReceiveData:(NSData *)data
|
||||
withTag:(long)tag
|
||||
fromHost:(NSString *)host
|
||||
port:(UInt16)port;
|
||||
|
||||
/**
|
||||
* Called if an error occurs while trying to receive a requested datagram.
|
||||
* This is generally due to a timeout, but could potentially be something else if some kind of OS error occurred.
|
||||
**/
|
||||
- (void)onUdpSocket:(AsyncUdpSocket *)sock didNotReceiveDataWithTag:(long)tag dueToError:(NSError *)error;
|
||||
|
||||
/**
|
||||
* Called when the socket is closed.
|
||||
* A socket is only closed if you explicitly call one of the close methods.
|
||||
**/
|
||||
- (void)onUdpSocketDidClose:(AsyncUdpSocket *)sock;
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,278 +0,0 @@
|
||||
//
|
||||
// UIView+AutoLayout.h
|
||||
// v2.0.0
|
||||
// https://github.com/smileyborg/UIView-AutoLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#pragma mark ALAttributes
|
||||
|
||||
typedef NS_ENUM(NSInteger, ALEdge) {
|
||||
ALEdgeLeft = NSLayoutAttributeLeft, // the left edge of the view
|
||||
ALEdgeRight = NSLayoutAttributeRight, // the right edge of the view
|
||||
ALEdgeTop = NSLayoutAttributeTop, // the top edge of the view
|
||||
ALEdgeBottom = NSLayoutAttributeBottom, // the bottom edge of the view
|
||||
ALEdgeLeading = NSLayoutAttributeLeading, // the leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic)
|
||||
ALEdgeTrailing = NSLayoutAttributeTrailing // the trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic)
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, ALDimension) {
|
||||
ALDimensionWidth = NSLayoutAttributeWidth, // the width of the view
|
||||
ALDimensionHeight = NSLayoutAttributeHeight // the height of the view
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, ALAxis) {
|
||||
ALAxisVertical = NSLayoutAttributeCenterX, // a vertical line through the center of the view
|
||||
ALAxisHorizontal = NSLayoutAttributeCenterY, // a horizontal line through the center of the view
|
||||
ALAxisBaseline = NSLayoutAttributeBaseline // a horizontal line at the text baseline (not applicable to all views)
|
||||
};
|
||||
|
||||
typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UIView+AutoLayout category API
|
||||
|
||||
|
||||
#pragma mark - UIView+AutoLayout
|
||||
|
||||
/**
|
||||
A category on UIView that provides a simple yet powerful interface for creating Auto Layout constraints.
|
||||
*/
|
||||
@interface UIView (AutoLayout)
|
||||
|
||||
|
||||
#pragma mark Factory & Initializer Methods
|
||||
|
||||
/** Creates and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
+ (instancetype)newAutoLayoutView;
|
||||
|
||||
/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
- (instancetype)initForAutoLayout;
|
||||
|
||||
|
||||
#pragma mark Set Constraint Priority
|
||||
|
||||
/** Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout category API within the given constraints block.
|
||||
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! */
|
||||
+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Remove Constraints
|
||||
|
||||
/** Removes the given constraint from the view it has been added to. */
|
||||
+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint;
|
||||
|
||||
/** Removes the given constraints from the views they have been added to. */
|
||||
+ (void)autoRemoveConstraints:(NSArray *)constraints;
|
||||
|
||||
/** Removes all explicit constraints that affect the view.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
|
||||
- (void)autoRemoveConstraintsAffectingView;
|
||||
|
||||
/** Removes all constraints that affect the view, optionally including implicit constraints.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
|
||||
- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints;
|
||||
|
||||
/** Recursively removes all explicit constraints that affect the view and its subviews.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
|
||||
- (void)autoRemoveConstraintsAffectingViewAndSubviews;
|
||||
|
||||
/** Recursively removes all constraints from the view and its subviews, optionally including implicit constraints.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
|
||||
- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints;
|
||||
|
||||
|
||||
#pragma mark Center in Superview
|
||||
|
||||
/** Centers the view in its superview. */
|
||||
- (NSArray *)autoCenterInSuperview;
|
||||
|
||||
/** Aligns the view to the same axis of its superview. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
|
||||
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
/** Pins the given edge of the view to the same edge of the superview with an inset. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview with the given edge insets. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView;
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset;
|
||||
|
||||
|
||||
#pragma mark Match Dimensions
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/** Sets the view to a specific size. */
|
||||
- (NSArray *)autoSetDimensionsToSize:(CGSize)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Content Compression Resistance & Hugging
|
||||
|
||||
/** Sets the priority of content compression resistance for an axis.
|
||||
NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis;
|
||||
|
||||
/** Sets the priority of content hugging for an axis.
|
||||
NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis;
|
||||
|
||||
|
||||
#pragma mark Constrain Any Attributes
|
||||
|
||||
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView;
|
||||
|
||||
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Pin to Layout Guides
|
||||
|
||||
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. */
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. */
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - NSArray+AutoLayout
|
||||
|
||||
/**
|
||||
A category on NSArray that provides a simple yet powerful interface for applying constraints to groups of views.
|
||||
*/
|
||||
@interface NSArray (AutoLayout)
|
||||
|
||||
|
||||
#pragma mark Constrain Multiple Views
|
||||
|
||||
/** Aligns views in this array to one another along a given edge. */
|
||||
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge;
|
||||
|
||||
/** Aligns views in this array to one another along a given axis. */
|
||||
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
|
||||
/** Matches a given dimension of all the views in this array. */
|
||||
- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension;
|
||||
|
||||
/** Sets the given dimension of all the views in this array to a given size. */
|
||||
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
|
||||
#pragma mark Distribute Multiple Views
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - NSLayoutConstraint+AutoLayout
|
||||
|
||||
/**
|
||||
A category on NSLayoutConstraint that allows constraints to be easily removed.
|
||||
*/
|
||||
@interface NSLayoutConstraint (AutoLayout)
|
||||
|
||||
/** Adds the constraint to the appropriate view. */
|
||||
- (void)autoInstall;
|
||||
|
||||
/** Removes the constraint from the view it has been added to. */
|
||||
- (void)autoRemove;
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,20 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface Call : BaseViewController<UIScrollViewDelegate>
|
||||
@property(nonatomic) NSString *CallTag;
|
||||
- (void)RefImg:(NSData *)data;
|
||||
- (void)setTime:(long)time0;
|
||||
- (void)UIClose;
|
||||
- (void)AnswerSucc;
|
||||
- (void)OpenDoorGo:(NSString *)pwd;
|
||||
@end
|
||||
|
||||
@ -1,442 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Call.h"
|
||||
#import "UI.h"
|
||||
#import "Pub.h"
|
||||
#import "Opendoor.h"
|
||||
#import "Sformat.h"
|
||||
#import "Msg.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface Call ()
|
||||
@property (nonatomic, strong)UIView *rview,*spkView,*cutView,*hangupView,*openView;
|
||||
@property (nonatomic, strong)UIImageView *playerImage,*spkImage,*cutImage,*hangupImage,*answerImage,*openImage;
|
||||
@property (nonatomic, strong)UIScrollView *scrollView;
|
||||
@property (nonatomic, strong)UIButton *answerView;
|
||||
@property (nonatomic, strong)UILabel *statuLabel;
|
||||
@property (nonatomic, strong)UIAlertController *openAlert;
|
||||
@property (nonatomic, strong)NSTimer *timer;
|
||||
@end
|
||||
|
||||
@implementation Call
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
[self.navigationController.navigationBar setHidden:YES];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
self.edgesForExtendedLayout = UIRectEdgeNone;
|
||||
self.extendedLayoutIncludesOpaqueBars = NO;
|
||||
self.modalPresentationCapturesStatusBarAppearance = NO;
|
||||
self.automaticallyAdjustsScrollViewInsets = NO;
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self.scrollView];
|
||||
[self.scrollView addSubview:self.playerImage];
|
||||
[self.rview addSubview:self.statuLabel];
|
||||
|
||||
|
||||
if([_CallTag isEqualToString:@"BECALL"]){
|
||||
[_statuLabel setText:[[NSString alloc] initWithFormat:@"%@呼叫",@"小小茜子的搬砖"]];
|
||||
|
||||
// [_statuLabel setText:[[NSString alloc] initWithFormat:@"%@呼叫",[Opendoor EquNameById:[[Pub getApp].talk getRemoteEqu]]]];
|
||||
|
||||
[self.rview addSubview:self.spkView];
|
||||
[self.spkView addSubview:self.spkImage];
|
||||
[self.rview addSubview:self.cutView];
|
||||
[self.cutView addSubview:self.cutImage];
|
||||
[self.rview addSubview:self.hangupView];
|
||||
[self.hangupView addSubview:self.hangupImage];
|
||||
[self.rview addSubview:self.answerView];
|
||||
[self.answerView addSubview:self.answerImage];
|
||||
[self.rview addSubview:self.openView];
|
||||
[self.openView addSubview:self.openImage];
|
||||
|
||||
|
||||
[self.cutView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SaveImg)]];
|
||||
[self.hangupView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Hangup)]];
|
||||
[self.answerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Answer)]];
|
||||
[self.openView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Open)]];
|
||||
}
|
||||
else if([_CallTag isEqualToString:@"WATCH"]){
|
||||
[_statuLabel setText:[[NSString alloc] initWithFormat:@"监视%@",[Opendoor EquNameById:[[Pub getApp].talk getRemoteEqu]]]];
|
||||
|
||||
[self.rview addSubview:self.cutView];
|
||||
[self.cutView addSubview:self.cutImage];
|
||||
[self.rview addSubview:self.hangupView];
|
||||
[self.hangupView addSubview:self.hangupImage];
|
||||
[self.rview addSubview:self.openView];
|
||||
[self.openView addSubview:self.openImage];
|
||||
|
||||
|
||||
[self.cutView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SaveImg)]];
|
||||
[self.hangupView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Hangup)]];
|
||||
[self.openView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Open)]];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
CGFloat imgwidth = [UI getScreenHeight]*640/480;
|
||||
self.scrollView.contentSize=CGSizeMake(imgwidth, [UI getScreenHeight]);
|
||||
self.playerImage.frame = CGRectMake(0,0,imgwidth, [UI getScreenHeight]);
|
||||
[self.scrollView setContentOffset:CGPointMake((imgwidth-[UI getScreenWidth])/2, 0)];
|
||||
[UI setFrameInView:self.statuLabel Width:@"100vw" Height:@"20" TranslateX:@"0" TranslateY:@"5vh" InView:nil Position:UITopMid];
|
||||
|
||||
if([_CallTag isEqualToString:@"BECALL"]){
|
||||
[UI setFrameInView:self.spkView Width:@"14vmin" Height:@"14vmin" TranslateX:@"-36vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.spkView];
|
||||
[UI setFrameInView:self.spkImage Width:@"50%" Height:@"50%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.cutView Width:@"14vmin" Height:@"14vmin" TranslateX:@"-18vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.cutView];
|
||||
[UI setFrameInView:self.cutImage Width:@"50%" Height:@"50%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.hangupView Width:@"14vmin" Height:@"14vmin" TranslateX:@"0" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.hangupView];
|
||||
[UI setFrameInView:self.hangupImage Width:@"58%" Height:@"22%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.answerView Width:@"14vmin" Height:@"14vmin" TranslateX:@"18vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.answerView];
|
||||
[UI setFrameInView:self.answerImage Width:@"40%" Height:@"40%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.openView Width:@"14vmin" Height:@"14vmin" TranslateX:@"36vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.openView];
|
||||
[UI setFrameInView:self.openImage Width:@"35%" Height:@"40%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
}
|
||||
else if([_CallTag isEqualToString:@"WATCH"]){
|
||||
[UI setFrameInView:self.cutView Width:@"14vmin" Height:@"14vmin" TranslateX:@"-26vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.cutView];
|
||||
[UI setFrameInView:self.cutImage Width:@"50%" Height:@"50%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.hangupView Width:@"14vmin" Height:@"14vmin" TranslateX:@"0" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.hangupView];
|
||||
[UI setFrameInView:self.hangupImage Width:@"58%" Height:@"22%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.openView Width:@"14vmin" Height:@"14vmin" TranslateX:@"26vmin" TranslateY:@"10vmin" InView:nil Position:UIBottomMid];
|
||||
[UI setCornerRadius:self.openView];
|
||||
[UI setFrameInView:self.openImage Width:@"35%" Height:@"40%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
[[Pub getApp].talk watchByServer];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)setTime:(long)time0{
|
||||
int sec_total = (int)([Sformat timestamp] - time0)/1000;
|
||||
int sec = sec_total % 60;
|
||||
int min = (sec_total-sec)/60;
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
[self.statuLabel setText:[[NSString alloc] initWithFormat:@"%02d:%02d",min,sec]];
|
||||
//});
|
||||
|
||||
}
|
||||
- (void)SaveImg{
|
||||
long time = [Sformat timestamp];
|
||||
//
|
||||
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
|
||||
// // 构造保存文件的名称 保存成功会返回YES
|
||||
// NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:
|
||||
// [NSString stringWithFormat:@"%ld.jpg",time]];
|
||||
|
||||
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];// 拼接图⽚名为"currentImage.png"的路径
|
||||
NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%ld.jpg",time]];//获取⽹络请求中的url地址
|
||||
|
||||
|
||||
//保存操作
|
||||
BOOL result = [UIImageJPEGRepresentation(self.playerImage.image, .9) writeToFile:filePath atomically:YES];
|
||||
if (result == YES) {
|
||||
[self alert:@"保存截图成功"];
|
||||
[[Pub getApp].sysinfo SaveRecord:time Type:@"截图" Equ:[[Pub getApp].talk getRemoteEqu] Img:[NSString stringWithFormat:@"%ld.jpg",time] Note:@""];
|
||||
}else{
|
||||
[self alert:@"保存截图失败"];
|
||||
}
|
||||
//https://wenku.baidu.com/view/2ff5463ba000a6c30c22590102020740be1ecd95.html
|
||||
|
||||
}
|
||||
- (void)Hangup{
|
||||
NSLog(@"挂机");
|
||||
if([Pub getApp].talk.status>0){
|
||||
if([_CallTag isEqualToString:@"BECALL"]){
|
||||
[[Pub getApp].talk talkEnd];
|
||||
}
|
||||
else{
|
||||
[[Pub getApp].talk watchEnd];
|
||||
}
|
||||
}
|
||||
|
||||
if([_CallTag isEqualToString:@"WATCH"]){
|
||||
if([Pub getApp].talk.status==0){
|
||||
[[Pub getApp].udp stopSend:@"" rr6:152 rr8:1];
|
||||
}
|
||||
}
|
||||
[self UIClose];
|
||||
}
|
||||
- (void)UIClose{
|
||||
[[Pub getApp].talk status_ini];
|
||||
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
[Pub getApp].callOut = nil;
|
||||
|
||||
}
|
||||
- (void)Answer{
|
||||
if([Pub getApp].talk.status==6){
|
||||
NSLog(@"接听");
|
||||
[Pub getApp].TalkSendAudio = false;
|
||||
[[Pub getApp] ring_stop];
|
||||
[[Pub getApp].talk talkOn];
|
||||
|
||||
}
|
||||
else{
|
||||
[self TouchUp];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//接听成功
|
||||
- (void)AnswerSucc{
|
||||
NSLog(@"接听Succ");
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
[self.answerImage setImage:[UIImage imageNamed:@"ic_vd_mic_off"]];
|
||||
|
||||
[self.answerView addTarget:self action:@selector(TouchDown) forControlEvents:UIControlEventTouchDown];
|
||||
[self.answerView addTarget:self action:@selector(TouchUp) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.answerView addTarget:self action:@selector(TouchUp) forControlEvents:UIControlEventTouchUpOutside];
|
||||
|
||||
});
|
||||
}
|
||||
-(void)TouchDown{
|
||||
[self.answerImage setImage:[UIImage imageNamed:@"ic_vd_mic_on"]];
|
||||
[Pub getApp].TalkSendAudio = true;
|
||||
}
|
||||
-(void)TouchUp{
|
||||
[self.answerImage setImage:[UIImage imageNamed:@"ic_vd_mic_off"]];
|
||||
[Pub getApp].TalkSendAudio = false;
|
||||
|
||||
}
|
||||
- (void)Open{
|
||||
self.openAlert = [Msg OpendoorByPwd:self SelectedHandler:^(int index) {
|
||||
[self alert:@"请输入6位数字密码"];
|
||||
}];
|
||||
}
|
||||
- (void)OpenDoorGo:(NSString *)pwd{
|
||||
if(self.openAlert){
|
||||
[self.openAlert dismissViewControllerAnimated:YES completion:nil];
|
||||
[[Pub getApp].talk openDoor:pwd];
|
||||
}
|
||||
}
|
||||
- (void)RefImg:(NSData *)data{
|
||||
NSString *getStr = [self convertDataToHexStr:data];
|
||||
NSLog(@"111得到的十六进制图像数据为:%@", getStr);
|
||||
|
||||
NSData *binaryData = [self dataFromHexString:getStr];
|
||||
// 将NSData转换为二进制数组
|
||||
const uint8_t *bytes = (const uint8_t *)[binaryData bytes];
|
||||
NSUInteger length = [binaryData length];
|
||||
NSMutableArray *binaryArray = [NSMutableArray array];
|
||||
for (NSUInteger i = 0; i < length; i++) {
|
||||
[binaryArray addObject:@(bytes[i])];
|
||||
}
|
||||
NSLog(@"222得到的二进制图像数据为:%@", binaryArray);
|
||||
|
||||
UIImage *image = [UIImage imageWithData: data];
|
||||
//self.playerImage = [[UIImageView alloc] initWithImage:image];
|
||||
[self.playerImage setImage:image];
|
||||
}
|
||||
|
||||
//将NSData转换成十六进制的字符串则可使用如下方式:
|
||||
- (NSString *)convertDataToHexStr:(NSData *)data {
|
||||
if (!data || [data length] == 0) {
|
||||
return @"";
|
||||
}
|
||||
NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
|
||||
|
||||
[data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
|
||||
unsigned char *dataBytes = (unsigned char*)bytes;
|
||||
for (NSInteger i = 0; i < byteRange.length; i++) {
|
||||
NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
|
||||
if ([hexStr length] == 2) {
|
||||
[string appendString:hexStr];
|
||||
} else {
|
||||
[string appendFormat:@"0%@", hexStr];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
//将十六进制字符串转换为二进制数据
|
||||
- (NSData *)dataFromHexString:(NSString *)hexString {
|
||||
// 去除字符串中的空格和换行符
|
||||
NSString *cleanedString = [hexString stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
cleanedString = [cleanedString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
||||
|
||||
// 检查字符串长度是否为偶数
|
||||
if (cleanedString.length % 2 != 0) {
|
||||
// 如果长度为奇数,可以根据需要选择在字符串前面添加或去除一个字符
|
||||
// 例如,你可以选择在前面添加一个零,或者去除最后一个字符
|
||||
// cleanedString = [@"0" stringByAppendingString:cleanedString];
|
||||
// 或者
|
||||
// cleanedString = [cleanedString substringToIndex:cleanedString.length - 1];
|
||||
}
|
||||
|
||||
// 使用一个循环将每两个字符转换为一个字节
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
for (NSInteger i = 0; i < cleanedString.length; i += 2) {
|
||||
NSString *byteString = [cleanedString substringWithRange:NSMakeRange(i, 2)];
|
||||
NSScanner *scanner = [NSScanner scannerWithString:byteString];
|
||||
unsigned int byteValue;
|
||||
[scanner scanHexInt:&byteValue];
|
||||
uint8_t byte = (uint8_t)byteValue;
|
||||
[data appendBytes:&byte length:1];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:0/255. green:0/255. blue:0/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
- (UILabel *)statuLabel
|
||||
{
|
||||
if (!_statuLabel) {
|
||||
_statuLabel = [[UILabel alloc] init];
|
||||
_statuLabel.font = [UIFont systemFontOfSize:18.0f];
|
||||
_statuLabel.textColor = [UIColor whiteColor];
|
||||
_statuLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_statuLabel.text = NSLocalizedString(@"", nil);
|
||||
}
|
||||
return _statuLabel;
|
||||
}
|
||||
//免提
|
||||
- (UIView *)spkView
|
||||
{
|
||||
if (!_spkView) {
|
||||
_spkView = [[UIView alloc] init];
|
||||
_spkView.backgroundColor = [UI colorWithHex:0x999999 alpha: .8];
|
||||
}
|
||||
return _spkView;
|
||||
}
|
||||
- (UIImageView *)spkImage
|
||||
{
|
||||
if (!_spkImage) {
|
||||
_spkImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hf"]];
|
||||
}
|
||||
return _spkImage;
|
||||
}
|
||||
//截图
|
||||
- (UIView *)cutView
|
||||
{
|
||||
if (!_cutView) {
|
||||
_cutView = [[UIView alloc] init];
|
||||
_cutView.backgroundColor = [UI colorWithHex:0x999999 alpha: .8];
|
||||
}
|
||||
return _cutView;
|
||||
}
|
||||
- (UIImageView *)cutImage
|
||||
{
|
||||
if (!_cutImage) {
|
||||
_cutImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"save_photo"]];
|
||||
}
|
||||
return _cutImage;
|
||||
}
|
||||
//挂机
|
||||
- (UIView *)hangupView
|
||||
{
|
||||
if (!_hangupView) {
|
||||
_hangupView = [[UIView alloc] init];
|
||||
_hangupView.backgroundColor = [UI colorWithHex:0xff0000 alpha: .8];
|
||||
|
||||
}
|
||||
return _hangupView;
|
||||
}
|
||||
- (UIImageView *)hangupImage
|
||||
{
|
||||
if (!_hangupImage) {
|
||||
_hangupImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hangup"]];
|
||||
}
|
||||
return _hangupImage;
|
||||
}
|
||||
//接听
|
||||
- (UIButton *)answerView
|
||||
{
|
||||
if (!_answerView) {
|
||||
_answerView = [[UIButton alloc] init];
|
||||
_answerView.backgroundColor = [UI colorWithHex:0x2f6da8 alpha: .8];
|
||||
}
|
||||
return _answerView;
|
||||
}
|
||||
- (UIImageView *)answerImage
|
||||
{
|
||||
if (!_answerImage) {
|
||||
_answerImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"call_call_on"]];
|
||||
}
|
||||
return _answerImage;
|
||||
}
|
||||
//开门
|
||||
- (UIView *)openView
|
||||
{
|
||||
if (!_openView) {
|
||||
_openView = [[UIView alloc] init];
|
||||
_openView.backgroundColor = [UI colorWithHex:0x999999 alpha: .8];
|
||||
}
|
||||
return _openView;
|
||||
}
|
||||
- (UIImageView *)openImage
|
||||
{
|
||||
if (!_openImage) {
|
||||
_openImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unlock_on2"]];
|
||||
}
|
||||
return _openImage;
|
||||
}
|
||||
//播放画面
|
||||
- (UIScrollView *)scrollView{
|
||||
if(!_scrollView){
|
||||
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UI getScreenWidth], [UI getScreenHeight])];
|
||||
_scrollView.pagingEnabled = NO;
|
||||
_scrollView.showsHorizontalScrollIndicator = YES;
|
||||
_scrollView.showsVerticalScrollIndicator = NO;
|
||||
_scrollView.delegate = self;
|
||||
}
|
||||
return _scrollView;
|
||||
}
|
||||
|
||||
- (UIImageView *)playerImage
|
||||
{
|
||||
if (!_playerImage) {
|
||||
//_playerImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.jpg"]];
|
||||
_playerImage = [[UIImageView alloc] init];
|
||||
}
|
||||
return _playerImage;
|
||||
}
|
||||
@end
|
||||
@ -1,25 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "BaseViewController.h"
|
||||
#import "EquList.h"
|
||||
|
||||
@interface EquAdd : BaseViewController<CBCentralManagerDelegate,CBPeripheralDelegate>
|
||||
@property(nonatomic) NSString *equid;
|
||||
@property(nonatomic) NSString *name;
|
||||
@property(nonatomic) EquList *parent;
|
||||
|
||||
@property (nonatomic,strong)CBCentralManager *ble;
|
||||
@property (nonatomic,strong)CBPeripheral *device;
|
||||
@property (nonatomic,strong)CBCharacteristic *wrter;
|
||||
@property (nonatomic,strong)CBCharacteristic *reader;
|
||||
|
||||
@end
|
||||
|
||||
@ -1,346 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "EquAdd.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "Sformat.h"
|
||||
#import "EquList.h"
|
||||
#import "Opendoor.h"
|
||||
#import "EquConfig.h"
|
||||
|
||||
|
||||
@interface EquAdd ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)UILabel *equidLabel,*nameLabel;
|
||||
@property (nonatomic, strong)HKHTextField *equidTextField, *nameTextField;
|
||||
@property (nonatomic, strong)UIButton *addButton ,*selEquButton;
|
||||
@property (nonatomic, strong)UIAlertController *waiting;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *equArray;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EquAdd
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
//UIView *RootView = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil] objectAtIndex:0];
|
||||
//[self.title autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0,0,0,0)];
|
||||
|
||||
|
||||
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
if(self.equid == nil){
|
||||
[self setupBle];
|
||||
}
|
||||
|
||||
//https://blog.csdn.net/liumude123/article/details/80579152
|
||||
//[self.view setNeedsUpdateConstraints];
|
||||
|
||||
|
||||
|
||||
}
|
||||
- (void)updateViewConstraints
|
||||
{
|
||||
[super updateViewConstraints];
|
||||
NSLog(@"updateViewConstraints");
|
||||
|
||||
[self setUI];
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self.equidLabel];
|
||||
[self.rview addSubview:self.equidTextField];
|
||||
[self.rview addSubview:self.nameLabel];
|
||||
[self.rview addSubview:self.nameTextField];
|
||||
[self.rview addSubview:self.addButton];
|
||||
|
||||
|
||||
if(self.equid){
|
||||
[self setNavTitle:@"命名设备"];
|
||||
|
||||
self.equidTextField.enabled = NO;
|
||||
self.equidTextField.text = self.equid;
|
||||
self.nameTextField.text = self.name;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
[self.rview addSubview:self.selEquButton];
|
||||
self.equidTextField.enabled = NO;
|
||||
self.equidTextField.backgroundColor = [UIColor whiteColor];
|
||||
[self setNavTitle:@"添加设备"];
|
||||
|
||||
|
||||
|
||||
[self.equidTextField resignFirstResponder];
|
||||
//[self.equidTextField setUserInteractionEnabled:YES];
|
||||
[self.selEquButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelEqu)]];
|
||||
[self.addButton setTitle:@"点击搜索门锁" forState:UIControlStateNormal];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[self.addButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(AddEqu)]];
|
||||
}
|
||||
- (void)setUI
|
||||
{
|
||||
[UI SetRView:self.rview Top:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]+10] Right:@"20" Bottom:@"0" Left:@"20"];
|
||||
|
||||
|
||||
[UI setFrameInView:self.equidLabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopLeft];
|
||||
[UI setFrameInView:self.equidTextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight];
|
||||
[UI setFrameInView:self.nameLabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopLeft];
|
||||
[UI setFrameInView:self.nameTextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopRight];
|
||||
[UI chgMargin:self.equidTextField Css:@"0 0 0 80"];
|
||||
[UI chgMargin:self.nameTextField Css:@"0 0 0 80"];
|
||||
|
||||
|
||||
[UI setFrameInView:self.addButton Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"140" InView:nil Position:UITopMid];
|
||||
|
||||
|
||||
if(self.equid==nil){
|
||||
[UI setFrameInView:self.selEquButton Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight];
|
||||
[UI chgMargin:self.selEquButton Css:@"0 0 0 80"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupBle{
|
||||
_ble = [[CBCentralManager alloc] initWithDelegate:self queue:(nil)];
|
||||
self.equArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
|
||||
#pragma mark-CBCentralManagerDelegate
|
||||
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
|
||||
switch (central.state){
|
||||
case CBCentralManagerStatePoweredOff:{
|
||||
NSLog(@"蓝牙关闭");
|
||||
[self alert:@"手机蓝牙未开启"];
|
||||
}
|
||||
|
||||
break;
|
||||
case CBCentralManagerStatePoweredOn:{
|
||||
NSLog(@"蓝牙打开");
|
||||
[self ScanEqu];
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
|
||||
if(peripheral.name==nil)return;
|
||||
if(![peripheral.name hasPrefix:@"T9A"])return;
|
||||
NSLog(@"发现蓝牙:%@,%@",peripheral,advertisementData);
|
||||
if(self.waiting){
|
||||
[self.waiting dismissViewControllerAnimated:YES completion:nil];
|
||||
self.waiting = nil;
|
||||
}
|
||||
|
||||
if(self.device==nil){
|
||||
self.device = peripheral;
|
||||
self.equidTextField.text = self.device.name;
|
||||
self.nameTextField.placeholder = self.device.name;
|
||||
[self.addButton setTitle:@"添加设备" forState:UIControlStateNormal];
|
||||
}
|
||||
for(int i=0;i<self.equArray.count;i++){
|
||||
CBPeripheral *item = self.equArray[i];
|
||||
if([item.name isEqual:peripheral.name])return;
|
||||
}
|
||||
[self.equArray addObject:peripheral];
|
||||
}
|
||||
|
||||
|
||||
- (void)ScanEqu{
|
||||
self.waiting = [Msg Waiting:self Msg:@"请打开门锁蓝牙,正在搜索门锁…" SelectedHandler:^{
|
||||
self.waiting = nil;
|
||||
if(self.device==nil){
|
||||
[self alert:@"搜索失败,请确认门锁已开启蓝牙"];
|
||||
}
|
||||
}];
|
||||
[NSThread detachNewThreadSelector:@selector(ScanEqu_thr) toTarget:self withObject:nil];
|
||||
|
||||
|
||||
}
|
||||
- (void)ScanEqu_thr{
|
||||
|
||||
sleep(1);
|
||||
[_ble scanForPeripheralsWithServices:nil options:nil];
|
||||
sleep(10);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
if(self.waiting){
|
||||
[self.waiting dismissViewControllerAnimated:YES completion:nil];
|
||||
self.waiting = nil;
|
||||
if(self.device==nil){
|
||||
[self alert:@"搜索失败,请确认门锁已开启蓝牙"];
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
- (void)SelEqu{
|
||||
NSLog(@"SelEqu");
|
||||
|
||||
[Msg Select:self SourceView:self.equidTextField Title:@"选择设备" Options:self.equArray SelectedHandler:^(int index) {
|
||||
if(index>0 && index<self.equArray.count){
|
||||
self.device = self.equArray[index];
|
||||
self.equidTextField.text = self.device.name;
|
||||
self.nameTextField.placeholder = self.device.name;
|
||||
|
||||
}
|
||||
}];
|
||||
}
|
||||
- (void)AddEqu{
|
||||
if([self.equidTextField.text isEqualToString:@""]){
|
||||
[self ScanEqu];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *name = self.nameTextField.text;
|
||||
if([name isEqual:@""]){
|
||||
name = self.equidTextField.text;
|
||||
}
|
||||
[HttpManager BindEquSucc:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:self.equidTextField.text Name:name HttpResultHandler:^(NSDictionary *json) {
|
||||
|
||||
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
|
||||
[Opendoor refEqulist:^{
|
||||
if(self.parent)
|
||||
[self.parent setData];
|
||||
}];
|
||||
[self pageBack];
|
||||
if(self.equid==nil){
|
||||
EquConfig *equconfig = [[EquConfig alloc] init];
|
||||
equconfig.equid = self.device.name;
|
||||
[self.navigationController pushViewController:equconfig animated:YES];
|
||||
}
|
||||
}
|
||||
else{
|
||||
[self alert:[json objectForKey:@"result"]];
|
||||
}
|
||||
}];
|
||||
}
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
//_rview.backgroundColor = [UIColor redColor];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
- (UILabel *)equidLabel
|
||||
{
|
||||
if (!_equidLabel) {
|
||||
_equidLabel = [[UILabel alloc] init];
|
||||
//_equidLabel.backgroundColor = [UIColor orangeColor];
|
||||
//_equidLabel.numberOfLines = 0;
|
||||
_equidLabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_equidLabel.textColor = [UIColor blackColor];
|
||||
_equidLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_equidLabel.text = NSLocalizedString(@"设备号", nil);
|
||||
}
|
||||
return _equidLabel;
|
||||
}
|
||||
- (UILabel *)nameLabel
|
||||
{
|
||||
if (!_nameLabel) {
|
||||
_nameLabel = [[UILabel alloc] init];
|
||||
//_nameLabel.backgroundColor = [UIColor orangeColor];
|
||||
//_nameLabel.numberOfLines = 0;
|
||||
_nameLabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_nameLabel.textColor = [UIColor blackColor];
|
||||
_nameLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_nameLabel.text = NSLocalizedString(@"设备名称", nil);
|
||||
}
|
||||
return _nameLabel;
|
||||
}
|
||||
- (HKHTextField *)equidTextField
|
||||
{
|
||||
if (!_equidTextField) {
|
||||
_equidTextField = [[HKHTextField alloc] init];
|
||||
_equidTextField.borderStyle = UITextBorderStyleRoundedRect;
|
||||
_equidTextField.placeholder = @"设备号";
|
||||
|
||||
}
|
||||
return _equidTextField;
|
||||
}
|
||||
- (HKHTextField *)nameTextField
|
||||
{
|
||||
if (!_nameTextField) {
|
||||
_nameTextField = [[HKHTextField alloc] init];
|
||||
_nameTextField.borderStyle = UITextBorderStyleRoundedRect;
|
||||
_nameTextField.placeholder = @"设备名称";
|
||||
|
||||
}
|
||||
return _nameTextField;
|
||||
}
|
||||
|
||||
|
||||
- (UIButton *)selEquButton
|
||||
{
|
||||
if (!_selEquButton) {
|
||||
_selEquButton = [[UIButton alloc] init];
|
||||
[_selEquButton setTitle:@"" forState:UIControlStateNormal];
|
||||
[_selEquButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
|
||||
[_selEquButton.layer setMasksToBounds:YES];
|
||||
[_selEquButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
|
||||
//边框宽度
|
||||
[_selEquButton.layer setBorderWidth:1.0];
|
||||
_selEquButton.layer.opacity = 0.1;
|
||||
_selEquButton.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
|
||||
}
|
||||
return _selEquButton;
|
||||
}
|
||||
|
||||
- (UIButton *)addButton
|
||||
{
|
||||
if (!_addButton) {
|
||||
_addButton = [[UIButton alloc] init];
|
||||
[_addButton setTitle:@"提交" forState:UIControlStateNormal];
|
||||
[_addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[_addButton setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted];
|
||||
_addButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
[_addButton.layer setMasksToBounds:YES];
|
||||
[_addButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
|
||||
//边框宽度
|
||||
//[_addButton.layer setBorderWidth:1.0];
|
||||
//_addButton.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
|
||||
}
|
||||
return _addButton;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,27 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface EquConfig : BaseViewController<CBCentralManagerDelegate,CBPeripheralDelegate>
|
||||
@property(nonatomic) NSString *equid;
|
||||
|
||||
|
||||
@property (nonatomic,strong)CBCentralManager *ble;
|
||||
@property (nonatomic,strong)CBPeripheral *device;
|
||||
@property (nonatomic,strong)CBCharacteristic *writer;
|
||||
@property (nonatomic,strong)CBCharacteristic *reader;
|
||||
@property (nonatomic)BOOL needSend;
|
||||
@property (nonatomic)BOOL sending;
|
||||
@property (nonatomic)BOOL connected;
|
||||
@property (nonatomic,strong)NSData *data2send;
|
||||
|
||||
@end
|
||||
|
||||
@ -1,532 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "EquConfig.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "Sformat.h"
|
||||
#import "EquList.h"
|
||||
#import "WifiList.h"
|
||||
|
||||
|
||||
@interface EquConfig ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)UILabel *WIFILabel,*PwdLabel,*hitLabel;
|
||||
@property (nonatomic, strong)HKHTextField *WIFITextField, *PwdTextField;
|
||||
@property (nonatomic, strong)UIButton *searchWIFIButton,*configButton;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation EquConfig
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
//UIView *RootView = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil] objectAtIndex:0];
|
||||
//[self.title autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0,0,0,0)];
|
||||
|
||||
|
||||
[self setNavTitle:@"配置网关"];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
[self setupBle];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
- (void)updateViewConstraints
|
||||
{
|
||||
[super updateViewConstraints];
|
||||
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self.WIFILabel];
|
||||
[self.rview addSubview:self.WIFITextField];
|
||||
[self.rview addSubview:self.PwdLabel];
|
||||
[self.rview addSubview:self.PwdTextField];
|
||||
[self.rview addSubview:self.searchWIFIButton];
|
||||
[self.rview addSubview:self.configButton];
|
||||
[self.rview addSubview:self.hitLabel];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[self.searchWIFIButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelectWifi)]];
|
||||
[self.configButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ConfigEqu)]];
|
||||
}
|
||||
- (void)setUI
|
||||
{
|
||||
[UI SetRView:self.rview Top:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]+10] Right:@"20" Bottom:@"0" Left:@"20"];
|
||||
|
||||
|
||||
[UI setFrameInView:self.WIFILabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopLeft];
|
||||
[UI setFrameInView:self.WIFITextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight];
|
||||
//[UI setFrameInView:self.searchWIFIButton Width:@"80" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight];
|
||||
[UI setFrameInView:self.PwdLabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopLeft];
|
||||
[UI setFrameInView:self.PwdTextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopRight];
|
||||
//[UI chgMargin:self.WIFITextField Css:@"0 90 0 80"];
|
||||
[UI chgMargin:self.WIFITextField Css:@"0 0 0 80"];
|
||||
[UI chgMargin:self.PwdTextField Css:@"0 0 0 80"];
|
||||
|
||||
|
||||
[UI setFrameInView:self.configButton Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"140" InView:nil Position:UITopMid];
|
||||
[UI setFrameInView:self.hitLabel Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"190" InView:nil Position:UITopMid];
|
||||
|
||||
}
|
||||
- (void)setupBle{
|
||||
_connected = NO;
|
||||
_needSend = NO;
|
||||
_sending = NO;
|
||||
_ble = [[CBCentralManager alloc] initWithDelegate:self queue:(nil)];
|
||||
}
|
||||
#pragma mark-CBCentralManagerDelegate
|
||||
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
|
||||
switch (central.state){
|
||||
case CBCentralManagerStatePoweredOff:{
|
||||
NSLog(@"蓝牙关闭");
|
||||
[self alert:@"手机蓝牙未开启"];
|
||||
}
|
||||
|
||||
break;
|
||||
case CBCentralManagerStatePoweredOn:{
|
||||
NSLog(@"蓝牙打开");
|
||||
[self ScanEqu];
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
|
||||
if(peripheral.name==nil)return;
|
||||
if(![peripheral.name isEqual:self.equid])return;
|
||||
NSLog(@"发现蓝牙:%@,%@",peripheral,advertisementData);
|
||||
|
||||
if(self.device==nil){
|
||||
self.hitLabel.text = @"发现门锁";
|
||||
self.device = peripheral;
|
||||
}
|
||||
if(!_connected){
|
||||
self.hitLabel.text = @"正在连接门锁";
|
||||
[_ble connectPeripheral:self.device options:nil];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(nonnull CBPeripheral *)peripheral{
|
||||
NSLog(@"已连接门锁");
|
||||
self.hitLabel.text = @"已连接门锁";
|
||||
[self.device setDelegate:self];
|
||||
[self.device discoverServices:nil];
|
||||
}
|
||||
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(nonnull CBPeripheral *)peripheral error:(nullable NSError *)error{
|
||||
NSLog(@"连接门锁失败,重新连接");
|
||||
self.hitLabel.text = @"连接门锁失败,重新连接";
|
||||
[_ble connectPeripheral:self.device options:nil];
|
||||
}
|
||||
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(nonnull CBPeripheral *)peripheral error:(nullable NSError *)error{
|
||||
NSLog(@"连接断开,正在重新连接");
|
||||
self.hitLabel.text = @"连接断开,正在重新连接";
|
||||
_connected = NO;
|
||||
if(_sending){
|
||||
_sending = NO;
|
||||
_needSend = YES;
|
||||
}
|
||||
|
||||
[_ble connectPeripheral:self.device options:nil];
|
||||
}
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(nullable NSError *)error{
|
||||
if(error)return;
|
||||
NSLog(@"已连接至门锁");
|
||||
self.hitLabel.text = @"已连接至门锁";
|
||||
for(CBService *service in peripheral.services){
|
||||
NSLog(@"Service:%@;",service.UUID);
|
||||
if([service.UUID isEqual:[CBUUID UUIDWithString:@"FFF0"]]){
|
||||
NSLog(@"discoverCharacteristics:%@",service.UUID);
|
||||
[_device discoverCharacteristics:nil forService:service];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(nonnull CBService *)service error:(nullable NSError *)error{
|
||||
NSLog(@"已连接到门锁");
|
||||
self.hitLabel.text = @"已连接到门锁";
|
||||
for(CBCharacteristic *characteristic in service.characteristics){
|
||||
NSLog(@"Characteristic:%@",characteristic.UUID);
|
||||
if([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"FFF1"]]){
|
||||
self.reader = characteristic;
|
||||
[_device setNotifyValue:YES forCharacteristic:self.reader];
|
||||
[_device readValueForCharacteristic:self.reader];
|
||||
}
|
||||
else if([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"FFF2"]]){
|
||||
self.writer = characteristic;
|
||||
}
|
||||
}
|
||||
_connected = YES;
|
||||
if(_needSend){
|
||||
[self ConfigEqu_go];
|
||||
}
|
||||
}
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error{
|
||||
if(error){
|
||||
_sending = NO;
|
||||
_needSend = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
NSLog(@"通信失败");
|
||||
self.hitLabel.text = @"通信失败";
|
||||
return;
|
||||
}
|
||||
NSLog(@"didWriteValueForCharacteristic :发送成功");
|
||||
|
||||
}
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error{
|
||||
//收到数据
|
||||
int len = characteristic.value.length;
|
||||
NSLog(@"didUpdateValueForCharacteristic:%ld",len);
|
||||
Byte bb[len];
|
||||
[characteristic.value getBytes:&bb length:len];
|
||||
NSLog(@"%@",[[NSData alloc] initWithBytes:bb length:len]);
|
||||
if(len==20 && bb[0]==0x22){
|
||||
Byte temp[16];
|
||||
NSData *temp2;
|
||||
memcpy(temp,bb+3,16);
|
||||
temp2 = [Pub AES128_Decrypt:@"1123456789ABCDEE" encryptData:[[NSData alloc] initWithBytes:temp length:16]];
|
||||
NSLog(@"解密后:%@",temp2);
|
||||
if(temp2){
|
||||
Byte temp3[16];
|
||||
memcpy(temp3,temp2.bytes,16);
|
||||
if(temp3[0] == 0xf1){
|
||||
//配网数据反馈
|
||||
if( bb[1]== bb[2]+1){//最后一包
|
||||
if(temp3[3]==1){
|
||||
NSLog(@"已下发WIFI信息,请等待门锁连接网关");
|
||||
self.hitLabel.text = @"已下发WIFI信息,请等待门锁连接网关";
|
||||
_sending = NO;
|
||||
_needSend = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
else{
|
||||
NSLog(@"配网失败");
|
||||
self.hitLabel.text = @"配网失败" ;
|
||||
_sending = NO;
|
||||
_needSend = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(temp3[3]==1){
|
||||
[self Send20];
|
||||
}
|
||||
else{
|
||||
NSLog(@"配网失败");
|
||||
self.hitLabel.text = @"配网失败";
|
||||
_sending = NO;
|
||||
_needSend = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if(temp3[0] == 0xf2){
|
||||
//配网数据结果
|
||||
if(temp3[3] == 0){
|
||||
NSLog(@"配网成功");
|
||||
self.hitLabel.text = @"配网成功";
|
||||
//[Msg Alert:self Msg:@"配网成功"];
|
||||
[Msg MessageBox:self Msg:@"配网成功" SelectedHandler:^(int index) {
|
||||
[self pageBack];
|
||||
}];
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
NSLog(@"配网失败");
|
||||
self.hitLabel.text = @"无法连接网关,请检查WIFI名称和密码是否正确";
|
||||
[Msg Alert:self Msg:@"无法连接网关,请检查WIFI名称和密码是否正确"];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error{
|
||||
|
||||
//NSLog(@"didUpdateNotificationStateForCharacteristic:%ld",characteristic.value.length);
|
||||
|
||||
}
|
||||
- (void)SelectWifi{
|
||||
WifiList *wifi = [[WifiList alloc] init];
|
||||
[self.navigationController pushViewController:wifi animated:YES];
|
||||
}
|
||||
|
||||
- (void)ScanEqu{
|
||||
NSLog(@"ScanEqu");
|
||||
self.hitLabel.text = @"请打开门锁蓝牙,正在搜索门锁…";
|
||||
[_ble scanForPeripheralsWithServices:nil options:nil];
|
||||
}
|
||||
- (void)ConfigEqu{
|
||||
if(self.device==nil){
|
||||
_needSend = YES;
|
||||
[self ScanEqu];
|
||||
return;
|
||||
}
|
||||
if(!_connected){_needSend = YES;return;}
|
||||
if(_sending){return;}
|
||||
|
||||
|
||||
|
||||
|
||||
[self ConfigEqu_go];
|
||||
}
|
||||
|
||||
- (BOOL)SetUpData{
|
||||
if([self.WIFITextField.text isEqualToString:@""]){[self alert:@"请输入wifi名称"];return NO;}
|
||||
if([self.PwdTextField.text isEqualToString:@""]){[self alert:@"请输入wifi密码"];return NO;}
|
||||
int bblen = 64;
|
||||
Byte bb[bblen];
|
||||
memset(bb, 0, 64);
|
||||
[Pub addGKB:self.WIFITextField.text toByte:bb at:0];
|
||||
[Pub addGKB:self.PwdTextField.text toByte:bb at:30];
|
||||
[Pub addGKB:[Pub getApp].sysinfo.equid toByte:bb at:50];
|
||||
|
||||
int bag_len = 14;
|
||||
int bag_len_last = bblen % bag_len;
|
||||
int bag_num = (bblen-bag_len_last)/bag_len;
|
||||
if(bag_len_last!=0)bag_num++;
|
||||
|
||||
Byte package1[bag_num*20];
|
||||
memset(package1, 0, bag_num*20);
|
||||
for(int i=0;i<bag_num;i++){
|
||||
package1[0+i*20] = 0x22;
|
||||
package1[1+i*20] = bag_num;
|
||||
package1[2+i*20] = i;
|
||||
package1[3+i*20] = 0xF1;
|
||||
package1[4+i*20] = 1;
|
||||
if(i<bag_num-1){
|
||||
package1[5+i*20] = bag_len;
|
||||
memcpy(package1+6+i*20,bb+i*bag_len,bag_len);
|
||||
}
|
||||
else{
|
||||
package1[5+i*20] = bag_len_last;
|
||||
memcpy(package1+6+i*20,bb+i*bag_len,bag_len_last);
|
||||
}
|
||||
}
|
||||
//NSLog(@"package1 %@",[[NSData alloc] initWithBytes:package1 length:bag_num*20]);
|
||||
//数据加密
|
||||
int templen = 16;
|
||||
Byte temp[templen];
|
||||
memset(temp, 0, templen);
|
||||
NSData *temp2;
|
||||
Byte package2[bag_num*20];
|
||||
memset(package2, 0, bag_num*20);
|
||||
|
||||
for(int i=0;i<bag_num;i++){
|
||||
package2[0+i*20] = 0x22;
|
||||
package2[1+i*20] = bag_num;
|
||||
package2[2+i*20] = i;
|
||||
package2[3+i*20] = 0xF1;
|
||||
package2[4+i*20] = 1;
|
||||
|
||||
|
||||
memcpy(temp,package1+3 + i*20,16);
|
||||
NSLog(@"加密前 %@",[[NSData alloc] initWithBytes:temp length:templen]);
|
||||
temp2 = [Pub AES128_Encrypt:@"1123456789ABCDEE" encryptData:[[NSData alloc] initWithBytes:temp length:templen]];
|
||||
NSLog(@"加密后 %@",temp2);
|
||||
memcpy(package2+3 + i*20,temp2.bytes ,16);
|
||||
package2[19+i*20] = package1[19+i*20];
|
||||
}
|
||||
_data2send = [[NSData alloc] initWithBytes:package2 length:bag_num*20];
|
||||
//NSLog(@"_data2send %@",_data2send);
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)Send20{
|
||||
NSLog(@"Send20");
|
||||
if(_data2send){
|
||||
NSLog(@"Send20:%d",_data2send.length);
|
||||
if(_data2send.length>=20){
|
||||
NSData *send = [[NSData alloc] initWithBytes:_data2send.bytes length:20];
|
||||
[_device writeValue:send forCharacteristic:_writer type:CBCharacteristicWriteWithResponse];
|
||||
|
||||
int leftlen = _data2send.length - 20;
|
||||
if(leftlen>0){
|
||||
Byte left[leftlen];
|
||||
memcpy(left,_data2send.bytes+20,leftlen);
|
||||
_data2send = [[NSData alloc] initWithBytes:left length:leftlen];
|
||||
}
|
||||
else{
|
||||
_data2send = nil;
|
||||
_sending = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
self.hitLabel.text = @"通信结束";
|
||||
}
|
||||
}
|
||||
else{
|
||||
_data2send = nil;
|
||||
_sending = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
self.hitLabel.text = @"通信失败";
|
||||
}
|
||||
}
|
||||
else{
|
||||
_sending = NO;
|
||||
self.configButton.enabled = YES;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
self.hitLabel.text = @"通信结束";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)ConfigEqu_go{
|
||||
if(![self SetUpData])return;
|
||||
self.hitLabel.text = @"正在配置";
|
||||
self.configButton.enabled = NO;
|
||||
self.configButton.backgroundColor = [UI colorWithHex:0x999999];
|
||||
_sending = YES;
|
||||
[self Send20];
|
||||
}
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
//_rview.backgroundColor = [UIColor redColor];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
- (UILabel *)hitLabel
|
||||
{
|
||||
if (!_hitLabel) {
|
||||
_hitLabel = [[UILabel alloc] init];
|
||||
//_WIFILabel.backgroundColor = [UIColor orangeColor];
|
||||
//_WIFILabel.numberOfLines = 0;
|
||||
_hitLabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_hitLabel.textColor = [UIColor grayColor];
|
||||
_hitLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_hitLabel.text = NSLocalizedString(@"", nil);
|
||||
}
|
||||
return _hitLabel;
|
||||
}
|
||||
- (UILabel *)WIFILabel
|
||||
{
|
||||
if (!_WIFILabel) {
|
||||
_WIFILabel = [[UILabel alloc] init];
|
||||
//_WIFILabel.backgroundColor = [UIColor orangeColor];
|
||||
//_WIFILabel.numberOfLines = 0;
|
||||
_WIFILabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_WIFILabel.textColor = [UIColor blackColor];
|
||||
_WIFILabel.textAlignment = NSTextAlignmentLeft;
|
||||
_WIFILabel.text = NSLocalizedString(@"WIFI名称", nil);
|
||||
}
|
||||
return _WIFILabel;
|
||||
}
|
||||
- (UILabel *)PwdLabel
|
||||
{
|
||||
if (!_PwdLabel) {
|
||||
_PwdLabel = [[UILabel alloc] init];
|
||||
//_PwdLabel.backgroundColor = [UIColor orangeColor];
|
||||
//_PwdLabel.numberOfLines = 0;
|
||||
_PwdLabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_PwdLabel.textColor = [UIColor blackColor];
|
||||
_PwdLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_PwdLabel.text = NSLocalizedString(@"WIFI密码", nil);
|
||||
}
|
||||
return _PwdLabel;
|
||||
}
|
||||
- (HKHTextField *)WIFITextField
|
||||
{
|
||||
if (!_WIFITextField) {
|
||||
_WIFITextField = [[HKHTextField alloc] init];
|
||||
_WIFITextField.borderStyle = UITextBorderStyleRoundedRect;
|
||||
_WIFITextField.placeholder = @"门锁连接WIFI的名称";
|
||||
|
||||
}
|
||||
return _WIFITextField;
|
||||
}
|
||||
- (HKHTextField *)PwdTextField
|
||||
{
|
||||
if (!_PwdTextField) {
|
||||
_PwdTextField = [[HKHTextField alloc] init];
|
||||
_PwdTextField.borderStyle = UITextBorderStyleRoundedRect;
|
||||
_PwdTextField.placeholder = @"门锁连接WIFI的密码";
|
||||
_PwdTextField.secureTextEntry = YES;
|
||||
|
||||
}
|
||||
return _PwdTextField;
|
||||
}
|
||||
|
||||
- (UIButton *)searchWIFIButton
|
||||
{
|
||||
if (!_searchWIFIButton) {
|
||||
_searchWIFIButton = [[UIButton alloc] init];
|
||||
[_searchWIFIButton setTitle:@"搜索WIFI" forState:UIControlStateNormal];
|
||||
[_searchWIFIButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[_searchWIFIButton setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted];
|
||||
_searchWIFIButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
[_searchWIFIButton.layer setMasksToBounds:YES];
|
||||
[_searchWIFIButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
|
||||
_searchWIFIButton.font = [UIFont systemFontOfSize:14.0f];
|
||||
//边框宽度
|
||||
//[_searchWIFIButton.layer setBorderWidth:1.0];
|
||||
//_searchWIFIButton.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
|
||||
|
||||
}
|
||||
return _searchWIFIButton;
|
||||
}
|
||||
|
||||
- (UIButton *)configButton
|
||||
{
|
||||
if (!_configButton) {
|
||||
_configButton = [[UIButton alloc] init];
|
||||
[_configButton setTitle:@"开始配置" forState:UIControlStateNormal];
|
||||
[_configButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[_configButton setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted];
|
||||
_configButton.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
[_configButton.layer setMasksToBounds:YES];
|
||||
[_configButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
|
||||
//边框宽度
|
||||
//[_configButton.layer setBorderWidth:1.0];
|
||||
//_configButton.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
|
||||
}
|
||||
return _configButton;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseTableViewController.h"
|
||||
|
||||
@interface EquList : BaseTableViewController<UITableViewDelegate,UITableViewDataSource>
|
||||
|
||||
- (void)setData;
|
||||
@end
|
||||
|
||||
@ -1,143 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "EquList.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
//#import "EquListCell.h"
|
||||
#import "Opendoor.h"
|
||||
#import "EquAdd.h"
|
||||
#import "EquConfig.h"
|
||||
#import "FaceUpload.h"
|
||||
|
||||
@interface EquList ()
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EquList
|
||||
NSMutableArray *_dataArray;
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
// [self setNavTitle:@"我的设备"];
|
||||
// [self setNavRight:@"add" action:@selector(AddEqu)];
|
||||
// [self setUI];
|
||||
// [self setData];
|
||||
}
|
||||
/*
|
||||
- (void)setData{
|
||||
_dataArray = [[NSMutableArray alloc] initWithCapacity:0];
|
||||
[_dataArray addObjectsFromArray:[Opendoor getEqulist]];
|
||||
[self.tableView reloadData];
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
|
||||
|
||||
|
||||
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, [UI getScreenWidth], [UI getScreenHeight]-60) style:UITableViewStylePlain];
|
||||
[self.tableView registerClass:[EquListCell class] forCellReuseIdentifier:@"EquListCell"];
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
|
||||
NSLog(@"table:%f,%f,%f,%f",self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.frame.size.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)AddEqu{
|
||||
EquAdd *equadd = [[EquAdd alloc] init];
|
||||
equadd.parent = self;
|
||||
[self.navigationController pushViewController:equadd animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark 返回分组数
|
||||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||||
//NSLog(@"计算分组数");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#pragma mark 返回每组行数
|
||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
//NSLog(@"计算每组(组%li)行数",(long)section);
|
||||
return _dataArray.count;
|
||||
}
|
||||
|
||||
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 60;
|
||||
}
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSLog(@"cellForRowAtIndexPath:%ld",indexPath.row);
|
||||
//EquListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EquListCell" forIndexPath:indexPath];
|
||||
EquListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EquListCell"];
|
||||
|
||||
if (cell == nil) {
|
||||
cell = [[EquListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EquListCell"];
|
||||
}
|
||||
if(indexPath.row<_dataArray.count){
|
||||
cell.titleLabel.text = [_dataArray[indexPath.row] valueForKey:@"name"];
|
||||
cell.contentLabel.text = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
}
|
||||
|
||||
|
||||
// if (indexPath.row == self.timeListenData.count - 1) {
|
||||
// [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
||||
// }
|
||||
return cell;
|
||||
}
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
//NSLog(@"didSelectRowAtIndexPath:%ld",indexPath.row);
|
||||
if(indexPath.row<_dataArray.count){
|
||||
NSArray * options = @[@"命名设备",@"配置网关",@"人脸开门",@"删除"];
|
||||
[Msg Select:self SourceView:[tableView cellForRowAtIndexPath:indexPath] Title:@"请选择" Options:options SelectedHandler:^(int index) {
|
||||
if(index==0){
|
||||
EquAdd *equadd = [[EquAdd alloc] init];
|
||||
equadd.parent = self;
|
||||
equadd.equid = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
equadd.name = [_dataArray[indexPath.row] valueForKey:@"name"];
|
||||
[self.navigationController pushViewController:equadd animated:YES];
|
||||
}
|
||||
else if(index==1){
|
||||
|
||||
EquConfig *equconfig = [[EquConfig alloc] init];
|
||||
equconfig.equid = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
[self.navigationController pushViewController:equconfig animated:YES];
|
||||
}
|
||||
else if(index==2){
|
||||
FaceUpload *face = [[FaceUpload alloc] init];
|
||||
face.equid = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
face.index0 = 0;
|
||||
[self.navigationController pushViewController:face animated:YES];
|
||||
}
|
||||
else if(index==3){
|
||||
[HttpManager DelEqu:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:[_dataArray[indexPath.row] valueForKey:@"equid"] HttpResultHandler:^(NSDictionary *json) {
|
||||
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
|
||||
[Opendoor refEqulist:^{
|
||||
[self setData];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
@ -1,22 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
#import "FaceUpload.h"
|
||||
|
||||
@interface FaceSubPage : BaseViewController<UIImagePickerControllerDelegate>
|
||||
@property(nonatomic) UILabel *hit;
|
||||
@property(nonatomic) UIButton *button;
|
||||
@property(nonatomic) UIImageView *imgView;
|
||||
@property(nonatomic) NSString *no;
|
||||
|
||||
@property(nonatomic) FaceUpload *parent;
|
||||
|
||||
@end
|
||||
|
||||
@ -1,226 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FaceSubPage.h"
|
||||
#import <MobileCoreServices/MobileCoreServices.h>
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "EquList.h"
|
||||
|
||||
@interface FaceSubPage ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@end
|
||||
|
||||
@implementation FaceSubPage
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self.imgView];
|
||||
[self.rview addSubview:self.hit];
|
||||
[self.rview addSubview:self.button];
|
||||
|
||||
[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Action)]];
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
NSLog(@"FaceSubPage:%f,%f",self.rview.frame.origin.x,self.rview.frame.size.width);
|
||||
|
||||
|
||||
[UI setFrameInView:self.imgView Width:@"86vw" Height:@"60vh" TranslateX:@"0" TranslateY:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]+20] InView:nil Position:UITopMid];
|
||||
[UI setFrameByView:self.hit Width:@"86vw" Height:@"40" TranslateX:@"0" TranslateY:@"10" ByView:self.imgView Position:BottomAlignCenter];
|
||||
[UI setFrameByView:self.button Width:@"86vw" Height:@"40" TranslateX:@"0" TranslateY:@"10" ByView:self.hit Position:BottomAlignCenter];
|
||||
|
||||
}
|
||||
- (void)Action{
|
||||
NSLog(@"Action");
|
||||
if(_no){
|
||||
NSLog(@"删除");
|
||||
[HttpManager delPhoto:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token No:_no HttpResultHandler:^(NSDictionary *json) {
|
||||
[self.parent ReLoad:0];
|
||||
}];
|
||||
}
|
||||
else{
|
||||
NSLog(@"拍照");
|
||||
if (![self isCameraAvailable]){[self alert:@"没有摄像头"];return;}
|
||||
if (![self doesCameraSupportTakingPhotos]){[self alert:@"不支持拍照"];return;}
|
||||
|
||||
// 初始化图片选择控制器
|
||||
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
|
||||
[controller setSourceType:UIImagePickerControllerSourceTypeCamera];// 设置类型
|
||||
controller.cameraDevice = UIImagePickerControllerCameraDeviceFront;//默认前置摄像头
|
||||
// 设置所支持的类型,设置只能拍照,或则只能录像,或者两者都可以
|
||||
NSString *requiredMediaType = ( NSString *)kUTTypeImage;
|
||||
NSString *requiredMediaType1 = ( NSString *)kUTTypeMovie;
|
||||
//NSArray *arrMediaTypes=[NSArray arrayWithObjects:requiredMediaType, requiredMediaType1,nil];
|
||||
NSArray *arrMediaTypes=[NSArray arrayWithObjects:requiredMediaType,nil];
|
||||
[controller setMediaTypes:arrMediaTypes];
|
||||
// 设置录制视频的质量
|
||||
//[controller setVideoQuality:UIImagePickerControllerQualityTypeHigh];
|
||||
//设置最长摄像时间
|
||||
//[controller setVideoMaximumDuration:10.f];
|
||||
//[controller setAllowsEditing:YES];// 设置是否可以管理已经存在的图片或者视频
|
||||
[controller setDelegate:self];// 设置代理
|
||||
[_parent.navigationController presentModalViewController:controller animated:YES];
|
||||
//[controller release];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
|
||||
|
||||
NSLog(@"didFinishPickingMediaWithInfo");
|
||||
//NSLog(@"%@", info);
|
||||
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
|
||||
// 判断获取类型:图片
|
||||
if ([mediaType isEqualToString:( NSString *)kUTTypeImage]){
|
||||
UIImage *theImage = nil;
|
||||
// 判断,图片是否允许修改
|
||||
if ([picker allowsEditing]){
|
||||
//获取用户编辑之后的图像
|
||||
theImage = [info objectForKey:UIImagePickerControllerEditedImage];
|
||||
|
||||
} else {
|
||||
// 照片的元数据参数
|
||||
theImage = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
}
|
||||
[self.imgView setImage:theImage];
|
||||
|
||||
NSLog(@"UpPhoto");
|
||||
self.hit.text = @"正在上传照片…";
|
||||
[HttpManager UpPhoto:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:_parent.equid Imgdata:UIImageJPEGRepresentation(theImage, .1) HttpResultHandler:^(NSDictionary *json) {
|
||||
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
|
||||
NSLog(@"成功");
|
||||
self.hit.text = @"上传成功";
|
||||
[self.parent ReLoad:-2];
|
||||
}
|
||||
else{
|
||||
NSLog(@"失败");
|
||||
self.hit.text = @"上传失败";
|
||||
[self.parent alert:[json objectForKey:@"result"]];
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
|
||||
}
|
||||
[picker dismissModalViewControllerAnimated:YES];
|
||||
|
||||
}
|
||||
// 判断设备是否有摄像头
|
||||
- (BOOL)isCameraAvailable{
|
||||
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
|
||||
}
|
||||
|
||||
// 前面的摄像头是否可用
|
||||
- (BOOL) isFrontCameraAvailable{
|
||||
return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
|
||||
}
|
||||
|
||||
// 后面的摄像头是否可用
|
||||
- (BOOL) isRearCameraAvailable{
|
||||
return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
|
||||
}
|
||||
|
||||
|
||||
// 判断是否支持某种多媒体类型:拍照,视频
|
||||
- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{
|
||||
__block BOOL result = NO;
|
||||
if ([paramMediaType length] == 0){
|
||||
NSLog(@"Media type is empty.");
|
||||
return NO;
|
||||
}
|
||||
NSArray *availableMediaTypes =[UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
|
||||
[availableMediaTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL*stop) {
|
||||
NSString *mediaType = (NSString *)obj;
|
||||
if ([mediaType isEqualToString:paramMediaType]){
|
||||
result = YES;
|
||||
*stop= YES;
|
||||
}
|
||||
}];
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查摄像头是否支持录像
|
||||
- (BOOL) doesCameraSupportShootingVideos{
|
||||
return [self cameraSupportsMedia:( NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypeCamera];
|
||||
}
|
||||
|
||||
// 检查摄像头是否支持拍照
|
||||
- (BOOL) doesCameraSupportTakingPhotos{
|
||||
return [self cameraSupportsMedia:( NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:189/255. green:211/255. blue:194/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
- (UILabel *)hit
|
||||
{
|
||||
if (!_hit) {
|
||||
_hit = [[UILabel alloc] init];
|
||||
//_nameLabel.backgroundColor = [UIColor orangeColor];
|
||||
//_nameLabel.numberOfLines = 0;
|
||||
_hit.font = [UIFont systemFontOfSize:15.0f];
|
||||
_hit.textColor = [UIColor blackColor];
|
||||
_hit.textAlignment = NSTextAlignmentCenter;
|
||||
_hit.text = NSLocalizedString(@"提示", nil);
|
||||
}
|
||||
return _hit;
|
||||
}
|
||||
|
||||
- (UIImageView *)imgView
|
||||
{
|
||||
if (!_imgView) {
|
||||
_imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vcontacts2.png"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
_imgView.layer.opacity = .3;
|
||||
_imgView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
}
|
||||
return _imgView;
|
||||
}
|
||||
- (UIButton *)button
|
||||
{
|
||||
if (!_button) {
|
||||
_button = [[UIButton alloc] init];
|
||||
[_button setTitle:@"删除人脸信息" forState:UIControlStateNormal];
|
||||
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[_button setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted];
|
||||
_button.backgroundColor = [UIColor redColor];
|
||||
[_button.layer setMasksToBounds:YES];
|
||||
[_button.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
|
||||
|
||||
|
||||
}
|
||||
return _button;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,19 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
#import "BasePageViewController.h"
|
||||
|
||||
@interface FaceUpload : BaseViewController
|
||||
|
||||
@property(nonatomic) NSString *equid;
|
||||
@property(nonatomic) int index0;
|
||||
- (void)ReLoad:(int)index;
|
||||
@end
|
||||
|
||||
@ -1,202 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FaceUpload.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "HttpManager.h"
|
||||
#import "FaceSubPage.h"
|
||||
|
||||
@interface FaceUpload ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
//翻页视图控制器对象
|
||||
@property (nonatomic, strong) UIPageViewController * pageViewControl;
|
||||
@property (nonatomic, strong) NSMutableArray* dataArray;
|
||||
@end
|
||||
|
||||
@implementation FaceUpload
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
[self setNavTitle:@"人脸开门"];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
[self setData];
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setupViews{
|
||||
[self.view addSubview:self.rview];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)ReLoad:(int)index{
|
||||
NSArray *viewControlles = self.navigationController.viewControllers;
|
||||
NSMutableArray *newviewControlles = [NSMutableArray array];
|
||||
if ([viewControlles count] > 0) {
|
||||
for (int i=0; i < [viewControlles count]-1; i++) {
|
||||
[newviewControlles addObject:[viewControlles objectAtIndex:i]];
|
||||
}
|
||||
}
|
||||
|
||||
FaceUpload *face = [[FaceUpload alloc] init];
|
||||
face.index0 = index;
|
||||
face.equid = _equid;
|
||||
[self.navigationController pushViewController:face animated:YES];
|
||||
[newviewControlles addObject:face];
|
||||
[self.navigationController setViewControllers:newviewControlles animated:YES];
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setData{
|
||||
[HttpManager getPhotos:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:self.equid HttpResultHandler:^(NSDictionary *json) {
|
||||
_dataArray = [[NSMutableArray alloc]init];
|
||||
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
|
||||
//{"no":5,"username":"13430525341","stime":"2022-11-08 09:58","photo":""}
|
||||
|
||||
NSArray *arr = [json objectForKey:@"data"];
|
||||
|
||||
for(int i=0;i<arr.count;i++){
|
||||
FaceSubPage * item = [[FaceSubPage alloc] init];
|
||||
item.parent = self;
|
||||
item.no = [[NSString alloc] initWithFormat:@"%@",[arr[i] valueForKey:@"no"]] ;
|
||||
item.hit.text = [[NSString alloc] initWithFormat:@"%@上传于%@",[arr[i] valueForKey:@"username"],[arr[i] valueForKey:@"stime"]];
|
||||
//[_dataArray insertObject:item atIndex:_dataArray.count-1];
|
||||
NSData * imageData =[[NSData alloc] initWithBase64EncodedString:[arr[i] valueForKey:@"photo"] options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||
[item.imgView setImage:[[UIImage alloc] initWithData:imageData]];
|
||||
item.imgView.layer.opacity = 1;
|
||||
[_dataArray addObject:item];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(_dataArray.count<5){
|
||||
FaceSubPage * item = [[FaceSubPage alloc] init];
|
||||
item.parent = self;
|
||||
item.hit.text = @"请上传正面清晰大头照";
|
||||
item.button.backgroundColor = [UI colorWithHex:0x378fe8];
|
||||
[item.button setTitle:@"拍照上传人脸" forState:UIControlStateNormal];
|
||||
[_dataArray addObject:item];
|
||||
}
|
||||
|
||||
|
||||
|
||||
int index2 = 0;
|
||||
if(_index0==-2){
|
||||
index2 = _dataArray.count - 2;
|
||||
if(index2<0)index2 = 0;
|
||||
}
|
||||
|
||||
|
||||
_pageViewControl = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionSpineLocationKey:@0,UIPageViewControllerOptionInterPageSpacingKey:@10}];
|
||||
self.view.backgroundColor = [UIColor greenColor];
|
||||
//设置翻页视图的尺寸
|
||||
_pageViewControl.view.bounds = self.rview.bounds;
|
||||
//设置数据源与代理
|
||||
_pageViewControl.dataSource = self;
|
||||
_pageViewControl.delegate = self;
|
||||
//设置初始界面
|
||||
[_pageViewControl setViewControllers:@[_dataArray[index2]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
|
||||
//设置是否双面展示
|
||||
_pageViewControl.doubleSided = NO;
|
||||
//创建初始界面
|
||||
[self.rview addSubview:_pageViewControl.view];
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setUI{
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//翻页控制器进行向前翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
|
||||
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
|
||||
int index = (int)[_dataArray indexOfObject:viewController];
|
||||
if (index==0) {
|
||||
return nil;
|
||||
}else{
|
||||
return _dataArray[index-1];
|
||||
}
|
||||
}
|
||||
//翻页控制器进行向后翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
|
||||
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
|
||||
int index = (int)[_dataArray indexOfObject:viewController];
|
||||
if(index+1 >= _dataArray.count){
|
||||
return nil;
|
||||
}
|
||||
else{
|
||||
return _dataArray[index+1];
|
||||
}
|
||||
|
||||
|
||||
// if (index==9) {
|
||||
// return nil;
|
||||
// }else{
|
||||
// if (_dataArray.count-1>=(index+1)) {
|
||||
// return _dataArray[index+1];
|
||||
// }else{
|
||||
// FaceSubPage * item = [[FaceSubPage alloc] init];
|
||||
// item.hit.text = [[NSString alloc] initWithFormat:@"%d"]
|
||||
// [_dataArray addObject:item];
|
||||
// return item;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
//屏幕旋转触发的代理方法
|
||||
- (UIPageViewControllerSpineLocation) pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
|
||||
return UIPageViewControllerSpineLocationMin;
|
||||
}
|
||||
//设置分页控制器的分页数
|
||||
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
|
||||
|
||||
return _dataArray.count;
|
||||
}
|
||||
//设置初始的分页点
|
||||
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{
|
||||
int index2 = 0;
|
||||
if(_index0==-2){
|
||||
index2 = _dataArray.count - 2;
|
||||
if(index2<0)index2 = 0;
|
||||
}
|
||||
return index2;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:189/255. green:211/255. blue:194/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,21 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface OpenPwd : BaseViewController
|
||||
@property(nonatomic) UIViewController *parent;
|
||||
|
||||
- (void)setUI;
|
||||
- (void)focusTextField;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -1,168 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OpenPwd.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "Sformat.h"
|
||||
#import "EquList.h"
|
||||
#import "Opendoor.h"
|
||||
|
||||
|
||||
@interface OpenPwd ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)UILabel *pwdLabel;
|
||||
@property (nonatomic, strong)HKHTextField *pwdTextField;
|
||||
@property (nonatomic, strong)NSMutableArray *labels;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation OpenPwd
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
|
||||
for(int i=0;i<self.labels.count;i++){
|
||||
[self.rview addSubview:self.labels[i]];
|
||||
}
|
||||
|
||||
[self.rview addSubview:self.pwdTextField];
|
||||
|
||||
|
||||
[self.pwdTextField addTarget:self action:@selector(textDidChanged) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
}
|
||||
- (void)setUI
|
||||
{
|
||||
|
||||
|
||||
[UI setFrameInView:self.rview Width:@"200" Height:@"44" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UITopMid];
|
||||
|
||||
|
||||
[UI setFrameInView:self.pwdTextField Width:@"200" Height:@"44" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UITopMid];
|
||||
|
||||
for(int i=0;i<self.labels.count;i++){
|
||||
CGFloat x = 33*(i-2.5);
|
||||
[UI setFrameInView:self.labels[i] Width:@"33" Height:@"44" TranslateX:[[NSString alloc] initWithFormat:@"%f",x] TranslateY:@"0" InView:nil Position:UITopMid];
|
||||
}
|
||||
|
||||
}
|
||||
-(void) textDidChanged {
|
||||
if(self.pwdTextField.text.length > 6) {
|
||||
self.pwdTextField.text = [self.pwdTextField.text substringToIndex:6];
|
||||
}
|
||||
for(int i = 0;i < self.pwdTextField.text.length;i++){
|
||||
UILabel * label = self.labels[i];
|
||||
label.text = @"●";
|
||||
label.font = [UIFont systemFontOfSize:15.0f];
|
||||
}
|
||||
for(int i = self.pwdTextField.text.length;i < 6;i++){
|
||||
UILabel * label = self.labels[i];
|
||||
label.text = @"○";
|
||||
label.font = [UIFont systemFontOfSize:15.0f];
|
||||
}
|
||||
if(self.pwdTextField.text.length==6){
|
||||
if([@"Call" isEqualToString:NSStringFromClass([self.parent class])]){
|
||||
Call *call = (Call *)self.parent;
|
||||
[call OpenDoorGo:[NSString stringWithFormat:@"%@",self.pwdTextField.text]];
|
||||
}
|
||||
else if([@"Opendoor" isEqualToString:NSStringFromClass([self.parent class])]){
|
||||
Opendoor *open = (Opendoor *)self.parent;
|
||||
[open OpenDoorStep1:self.pwdTextField.text];
|
||||
}
|
||||
//[[Pub getApp].talk openDoor:self.pwdTextField.text];
|
||||
}
|
||||
}
|
||||
- (void)focusTextField{
|
||||
[self.pwdTextField becomeFirstResponder];
|
||||
}
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
//_rview.backgroundColor = [UI colorWithHex:0xff0000 alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
- (UILabel *)pwdLabel
|
||||
{
|
||||
if (!_pwdLabel) {
|
||||
_pwdLabel = [[UILabel alloc] init];
|
||||
//_nameLabel.backgroundColor = [UIColor orangeColor];
|
||||
//_nameLabel.numberOfLines = 0;
|
||||
_pwdLabel.font = [UIFont systemFontOfSize:15.0f];
|
||||
_pwdLabel.textColor = [UIColor blackColor];
|
||||
_pwdLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_pwdLabel.text = NSLocalizedString(@"设备名称", nil);
|
||||
}
|
||||
return _pwdLabel;
|
||||
}
|
||||
- (HKHTextField *)pwdTextField
|
||||
{
|
||||
if (!_pwdTextField) {
|
||||
_pwdTextField = [[HKHTextField alloc] init];
|
||||
_pwdTextField.borderStyle = UITextBorderStyleRoundedRect;
|
||||
//_pwdTextField.placeholder = @"密码";
|
||||
_pwdTextField.borderStyle = UITextBorderStyleNone;
|
||||
_pwdTextField.keyboardType = UIKeyboardTypeNumberPad;
|
||||
_pwdTextField.textAlignment = NSTextAlignmentCenter;
|
||||
_pwdTextField.backgroundColor = [UI colorWithHex:0xff0000 alpha:0];
|
||||
_pwdTextField.tintColor = [UI colorWithHex:0xff0000 alpha:0];
|
||||
_pwdTextField.textColor = [UI colorWithHex:0xff0000 alpha:0];
|
||||
}
|
||||
return _pwdTextField;
|
||||
}
|
||||
- (NSMutableArray *)labels{
|
||||
if (!_labels) {
|
||||
_labels = [[NSMutableArray alloc] initWithCapacity:0];
|
||||
|
||||
|
||||
for(int i=0;i<6;i++){
|
||||
UILabel * label = [[UILabel alloc] init];
|
||||
label.font = [UIFont systemFontOfSize:15.0f];
|
||||
label.textColor = [UIColor blackColor];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.text = NSLocalizedString(@"○", nil);
|
||||
|
||||
[_labels addObject:label];
|
||||
}
|
||||
|
||||
}
|
||||
return _labels;
|
||||
}
|
||||
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,20 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface P2pTest : BaseViewController<UIScrollViewDelegate>
|
||||
|
||||
- (void)GotMyPortInServer:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
- (void)GotRemoteIp:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
- (void)GotCall:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
- (void)GotDadong:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
- (void)GotNSAsk:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port ;
|
||||
@end
|
||||
|
||||
@ -1,583 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "P2pTest.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "EquList.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Sformat.h"
|
||||
#import <math.h>
|
||||
|
||||
@interface P2pTest ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)NSArray *cells;
|
||||
@property (nonatomic, strong)UILabel *hitLabel;
|
||||
@property (nonatomic, strong)AppDelegate *app;
|
||||
@property (nonatomic, strong)NSString *remote_ipv6;
|
||||
@property (nonatomic)int remote_portv6;
|
||||
|
||||
@property (nonatomic)int get_Address_type;
|
||||
@property (nonatomic)int get_Address_num;
|
||||
@property (nonatomic, strong)NSString *got_address;
|
||||
@property (nonatomic, strong)NSString *got_port;
|
||||
|
||||
@end
|
||||
|
||||
@implementation P2pTest
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
|
||||
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];//#378fe8
|
||||
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
|
||||
|
||||
[self setNavTitle:@"调试"];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
self.app = [Pub getApp];
|
||||
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self. hitLabel];
|
||||
for(int i=0;i<self.cells.count;i++){
|
||||
[self.rview addSubview:self.cells[i]];
|
||||
|
||||
if(i==0){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetMyPortInServer)]];
|
||||
}
|
||||
else if(i==1){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetRemoteIp)]];
|
||||
}
|
||||
else if(i==2){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Talk1)]];
|
||||
}
|
||||
else if(i==3){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Dadong1)]];
|
||||
}
|
||||
else if(i==4){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetMyPortInServer2)]];
|
||||
}
|
||||
else if(i==5){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Call_ipv4)]];
|
||||
}
|
||||
else if(i==6){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Call)]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
- (void)GetMyPortInServer{
|
||||
self.hitLabel.text = @"本地网络:";
|
||||
self.get_Address_type = 1;
|
||||
self.get_Address_num = 5;
|
||||
self.got_port = @"";
|
||||
self.got_address = @"";
|
||||
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=140;
|
||||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
//[self addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:33];
|
||||
|
||||
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8366 at:3 setTag:0];
|
||||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8367 at:3 setTag:0];
|
||||
//[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8366 at:3 setTag:0];
|
||||
[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8367 at:3 setTag:0];
|
||||
[_app.udp senddataInThr:data toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" toPort:8368 at:3 setTag:0];
|
||||
[_app.udp senddataInThr:data toHost:@"180.76.97.209" toPort:8366 at:3 setTag:0];
|
||||
}
|
||||
- (void)GetMyPortInServer2{
|
||||
self.hitLabel.text = @"本地网络:";
|
||||
self.get_Address_type = 2;
|
||||
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=140;
|
||||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
//[self addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:33];
|
||||
|
||||
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
//[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8369 at:3 setTag:0];
|
||||
[_app.udp senddataInThr:data toHost:@"180.76.97.209" toPort:8367 at:3 setTag:0];
|
||||
}
|
||||
- (void)GotMyPortInServer:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||||
[_app.udp stopSend:ip rr6:bb[6] rr8:bb[8] Port:port];
|
||||
NSString *got_address1 = [[NSString alloc] initWithFormat:@"%@:%d;",ip,port ];
|
||||
self.got_address = [[NSString alloc] initWithFormat:@"%@%@",[self.got_address stringByReplacingOccurrencesOfString:got_address1 withString:@""],got_address1 ];
|
||||
if([[_app.talk getIpFromBtye:bb At:29] isEqual:@"255.255.255.255"]){
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d",self.hitLabel.text,[_app.talk getIpv6FromBtye:bb At:35],[_app.talk getPortFromBtye:bb At:33] ];
|
||||
}
|
||||
else{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d反馈%@:%d",self.hitLabel.text,ip,port,[_app.talk getIpFromBtye:bb At:29],[_app.talk getPortFromBtye:bb At:33]];
|
||||
NSString *got_port1 = [[NSString alloc] initWithFormat:@"%d;",[_app.talk getPortFromBtye:bb At:33] ];
|
||||
self.got_port = [[NSString alloc] initWithFormat:@"%@%@",[self.got_port stringByReplacingOccurrencesOfString:got_port1 withString:@""],got_port1 ];
|
||||
}
|
||||
|
||||
if(self.get_Address_type==1){
|
||||
NSString *ipv6 = @"ipv6不可用";
|
||||
if([self.got_address rangeOfString:@"8369;"].location!=NSNotFound){
|
||||
if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num+2){
|
||||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location!=NSNotFound){
|
||||
ipv6 = @"ipv6可用";
|
||||
}
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\nip限制型,%@",self.hitLabel.text,ipv6 ];
|
||||
}
|
||||
}
|
||||
else{
|
||||
if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num+1){
|
||||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location!=NSNotFound){
|
||||
ipv6 = @"ipv6可用";
|
||||
}
|
||||
if([self.got_port componentsSeparatedByString:@";"].count== 2){
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口限制型,%@",self.hitLabel.text,ipv6 ];
|
||||
}
|
||||
else{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n对称型,%@,端口变化:%d",self.hitLabel.text,ipv6,[self portRang:self.got_port] ];
|
||||
}
|
||||
}
|
||||
else if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num){
|
||||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location==NSNotFound){
|
||||
if([self.got_port componentsSeparatedByString:@";"].count== 2){
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口限制型,%@",self.hitLabel.text,ipv6 ];
|
||||
}
|
||||
else{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n对称型,%@,端口变化:%d",self.hitLabel.text,ipv6,[self portRang:self.got_port] ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (self.get_Address_type==2){
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口变化:%d",self.hitLabel.text,[self portRang:self.got_port] ];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
- (int)portRang:(NSString *)str{
|
||||
|
||||
NSArray *ports = [str componentsSeparatedByString:@";"];
|
||||
int max = 0;
|
||||
int min = 0;
|
||||
for(int i=0;i<ports.count-1;i++){
|
||||
int add = [[ports objectAtIndex:i] intValue]-[[ports objectAtIndex:0] intValue];
|
||||
NSLog(@"add: %d",add);
|
||||
max = MAX(max, add);
|
||||
min = MIN(min, add);
|
||||
}
|
||||
|
||||
return max-min;
|
||||
}
|
||||
- (void)GetRemoteIp{
|
||||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||||
}else{
|
||||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||||
}
|
||||
|
||||
self.hitLabel.text = @"对方网络:";
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=141;
|
||||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[Pub getLocalIP] toByte:bb at:33];
|
||||
|
||||
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8367 at:3 setTag:0];
|
||||
//[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8367 at:3 setTag:0];
|
||||
}
|
||||
- (void)GotRemoteIp:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||||
[_app.udp stopSend:ip rr6:bb[6] rr8:bb[8] Port:port];
|
||||
[_app.talk SetRemoteIp:[_app.talk getIpFromBtye:bb At:29]];
|
||||
[_app.talk SetRemotePort:[_app.talk getPortFromBtye:bb At:33] ];
|
||||
_remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:35];
|
||||
_remote_portv6 = [_app.talk getPortFromBtye:bb At:51];
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d\n%@:%d",self.hitLabel.text,[_app.talk getIpFromBtye:bb At:29],[_app.talk getPortFromBtye:bb At:33] ,_remote_ipv6,_remote_portv6];
|
||||
}
|
||||
- (void)Call_ipv4{
|
||||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||||
}else{
|
||||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@",[_app.talk getRemoteEqu]];
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=144;
|
||||
[_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
//[app senddataInThr:data toHost:remoteIp byPort:8302];
|
||||
|
||||
[[Pub getApp].udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8367 at:10 setTag:0];
|
||||
}
|
||||
- (void)Call{
|
||||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||||
}else{
|
||||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@",[_app.talk getRemoteEqu]];
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=143;
|
||||
[_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
//[app senddataInThr:data toHost:remoteIp byPort:8302];
|
||||
|
||||
[[Pub getApp].udp senddataInThr:data toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" toPort:8368 at:10 setTag:0];
|
||||
}
|
||||
- (void)GotNSAsk:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||||
if(bb[8]==144){
|
||||
if(bb[7]==1){//
|
||||
Byte bb0[1];
|
||||
bb0[0]=0x30;
|
||||
NSData *data0 = [[NSData alloc] initWithBytes:bb length:1];
|
||||
|
||||
bb[7]=2;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:bblen];
|
||||
[_app.udp.udp sendData:data0
|
||||
toHost:_app.sysinfo.server_wan
|
||||
port:8367
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:_app.sysinfo.server_wan
|
||||
port:8367
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
|
||||
[_app.talk SetRemoteIp:[_app.talk getIpFromBtye:bb At:57]];
|
||||
[_app.talk SetRemotePort:[_app.talk getPortFromBtye:bb At:73] ];
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n收到解析:%@:%d" ,self.hitLabel.text,[_app.talk getRemoteIp],[_app.talk getRemotePort]];
|
||||
[self Dadong1];
|
||||
}
|
||||
else{
|
||||
|
||||
if([_app.udp stopSend:@"" rr6:bb[6] rr8:bb[8]]>-1){
|
||||
|
||||
|
||||
[_app.talk SetRemoteIp:[_app.talk getIpFromBtye:bb At:57]];
|
||||
[_app.talk SetRemotePort:[_app.talk getPortFromBtye:bb At:73] ];
|
||||
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n解析成功:%@:%d" ,self.hitLabel.text,[_app.talk getRemoteIp],[_app.talk getRemotePort]];
|
||||
|
||||
[self Dadong1_wait];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
if(bb[7]==1){//
|
||||
Byte bb0[1];
|
||||
bb0[0]=0x30;
|
||||
NSData *data0 = [[NSData alloc] initWithBytes:bb length:1];
|
||||
|
||||
bb[7]=2;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:bblen];
|
||||
[_app.udp.udp sendData:data0
|
||||
toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7"
|
||||
port:8368
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7"
|
||||
port:8368
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
|
||||
_remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:57];
|
||||
_remote_portv6 = [_app.talk getPortFromBtye:bb At:73];
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"收到解析:%@:%d",_remote_ipv6,_remote_portv6];
|
||||
// [_app.udp.udp sendData:data0
|
||||
// toHost:_remote_ipv6
|
||||
// port:_remote_portv6
|
||||
// withTimeout:-1
|
||||
// tag:0];
|
||||
// [_app.udp.udp sendData:data0
|
||||
// toHost:_remote_ipv6
|
||||
// port:_remote_portv6
|
||||
// withTimeout:-1
|
||||
// tag:0];
|
||||
[[Pub getApp].udp senddataInThr:data0 toHost:_remote_ipv6 toPort:_remote_portv6 at:4 setTag:0];
|
||||
}
|
||||
else{
|
||||
|
||||
if([_app.udp stopSend:@"" rr6:bb[6] rr8:bb[8]]>-1){
|
||||
|
||||
|
||||
_remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:57];
|
||||
_remote_portv6 = [_app.talk getPortFromBtye:bb At:73];
|
||||
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n解析成功:%@:%d" ,self.hitLabel.text,_remote_ipv6,_remote_portv6];
|
||||
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=142;
|
||||
[_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
|
||||
[[Pub getApp].udp senddataInThr:data toHost:_remote_ipv6 toPort:_remote_portv6 at:3 setTag:0];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
-(void)Talk1{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@:%d",[_app.talk getRemoteIp],[_app.talk getRemotePort]];
|
||||
Byte bb[512];
|
||||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||||
bb[6]=150;
|
||||
bb[7]=1;
|
||||
bb[8]=142;
|
||||
[_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||||
//[app senddataInThr:data toHost:remoteIp byPort:8302];
|
||||
|
||||
[[Pub getApp].udp senddataInThr:data toHost:[_app.talk getRemoteIp] toPort:[_app.talk getRemotePort] at:3 setTag:0];
|
||||
//[Pub getApp].udp senddataInThr:data toHost:self.remote_ipv6 toPort:self.remote_portv6 at:3 setTag:0];
|
||||
}
|
||||
|
||||
- (void)GotCall:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||||
if(bb[7]==1){
|
||||
[_app.udp stopSendDadong];
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被叫%@:%d",self.hitLabel.text,ip,port ];
|
||||
bb[7]=2;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:bblen];
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:ip
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
}
|
||||
else{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n呼通%@:%d",self.hitLabel.text,ip,port ];
|
||||
[_app.udp stopSend:ip rr6:bb[6] rr8:bb[8]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)GotDadong:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||||
if([ip componentsSeparatedByString:@"."].count==4){
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被打洞(%d)%@:%d",self.hitLabel.text,bb[0],ip,port ];
|
||||
[_app.talk SetRemoteIp:ip];
|
||||
[_app.talk SetRemotePort:port ];
|
||||
if(bb[0]==0x30){
|
||||
bb[0] = 0x31;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:bblen];
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:ip
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
}
|
||||
else{
|
||||
[self Talk1];
|
||||
}
|
||||
}
|
||||
else{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被打洞%@:%d",self.hitLabel.text,ip,port ];
|
||||
_remote_ipv6 = ip;
|
||||
_remote_portv6 = port;
|
||||
[_app.udp ChgSendIp:ip rr6:150 rr8:142 Port:port];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)Dadong1_wait{
|
||||
[NSThread detachNewThreadSelector:@selector(Dadong1_thr) toTarget:self withObject:nil];
|
||||
}
|
||||
-(void)Dadong1_thr{
|
||||
sleep(2);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
|
||||
[self Dadong1];
|
||||
});
|
||||
}
|
||||
|
||||
-(void)Dadong1{
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@:%d~%d",[_app.talk getRemoteIp],MAX(1000,[_app.talk getRemotePort]),MIN(65535,[_app.talk getRemotePort]+500)];
|
||||
Byte bb[1];
|
||||
bb[0]=0x30;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:1];
|
||||
//[[Pub getApp].udp senddataInThr:data toHost:[_app.talk getRemoteIp] toPort:[_app.talk getRemotePort]+1 at:3 setTag:0];
|
||||
// [_app.udp.udp sendData:data
|
||||
// toHost:self.remote_ipv6
|
||||
//
|
||||
// port:800
|
||||
// withTimeout:-1
|
||||
// tag:0];
|
||||
for(int i= MAX(1000,[_app.talk getRemotePort]);i<MIN(65535,[_app.talk getRemotePort]+500);i++){
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:[_app.talk getRemoteIp]
|
||||
port:i
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
|
||||
// [_app.udp.udp sendData:data
|
||||
// toHost:[_app.talk getRemoteIp]
|
||||
// port:i
|
||||
// withTimeout:-1
|
||||
// tag:0];
|
||||
//});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-(void)Dadong2{
|
||||
|
||||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@:%d",[_app.talk getRemoteIp],[_app.talk getRemotePort]];
|
||||
Byte bb[1];
|
||||
bb[0]=0x30;
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:1];
|
||||
//[[Pub getApp].udp senddataInThr:data toHost:[_app.talk getRemoteIp] toPort:[_app.talk getRemotePort]+1 at:3 setTag:0];
|
||||
[_app.udp.udp sendData:data
|
||||
toHost:[_app.talk getRemoteIp]
|
||||
port:[_app.talk getRemotePort]
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
|
||||
// self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@",[_app.talk getRemoteIp]];
|
||||
// [NSThread detachNewThreadSelector:@selector(Dadong2_thr) toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
- (void)setUI{
|
||||
|
||||
|
||||
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
//self.scrollView.contentSize=CGSizeMake( [UI getScreenWidth],4000);
|
||||
//self. hitLabel.frame = CGRectMake(0,0,[UI getScreenWidth], 4000);
|
||||
|
||||
[UI setFrameInView:self.hitLabel Width:@"100vw" Height:@"160" TranslateX:@"0" TranslateY:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]] InView:nil Position:UITopMid];
|
||||
|
||||
for(int i=0;i<self.cells.count;i++){
|
||||
NSString *top = [[NSString alloc] initWithFormat:@"%f", 10. + i*60.5] ;
|
||||
[UI setFrameByView:self.cells[i] Width:@"100vw" Height:@"60" TranslateX:@"0" TranslateY:top ByView:self.hitLabel Position:BottomAlignCenter];
|
||||
|
||||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[0] Width:@"70vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidLeft];
|
||||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[1] Width:@"30vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidRight];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)cells{
|
||||
if (!_cells) {
|
||||
UIView *cell1 = [[UIView alloc] init];
|
||||
cell1.backgroundColor = [UIColor whiteColor];
|
||||
[cell1 addSubview:[UI NewLabel:@"网络环境" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell1 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell2 = [[UIView alloc] init];
|
||||
cell2.backgroundColor = [UIColor whiteColor];
|
||||
[cell2 addSubview:[UI NewLabel:@"对方环境" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell2 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
|
||||
UIView *cell3 = [[UIView alloc] init];
|
||||
cell3.backgroundColor = [UIColor whiteColor];
|
||||
[cell3 addSubview:[UI NewLabel:@"呼叫模式1" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell3 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell4 = [[UIView alloc] init];
|
||||
cell4.backgroundColor = [UIColor whiteColor];
|
||||
[cell4 addSubview:[UI NewLabel:@"打洞模式1" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell4 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell5 = [[UIView alloc] init];
|
||||
cell5.backgroundColor = [UIColor whiteColor];
|
||||
[cell5 addSubview:[UI NewLabel:@"网络环境2" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell5 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell6 = [[UIView alloc] init];
|
||||
cell6.backgroundColor = [UIColor whiteColor];
|
||||
[cell6 addSubview:[UI NewLabel:@"ipv4一键呼叫" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell6 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell7 = [[UIView alloc] init];
|
||||
cell7.backgroundColor = [UIColor whiteColor];
|
||||
[cell7 addSubview:[UI NewLabel:@"ipv6一键呼叫" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell7 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
_cells = @[cell1,cell2,cell3,cell4,cell5,cell6,cell7];
|
||||
}
|
||||
return _cells;
|
||||
}
|
||||
- (UILabel *) hitLabel
|
||||
{
|
||||
if (!_hitLabel) {
|
||||
_hitLabel = [[UILabel alloc] init];
|
||||
//_webView.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
_hitLabel.font = [UIFont systemFontOfSize:13.0f];
|
||||
_hitLabel.textColor = [UIColor blackColor];
|
||||
_hitLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_hitLabel.text = NSLocalizedString(@"", nil);
|
||||
_hitLabel.numberOfLines = 0;
|
||||
}
|
||||
return _hitLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,18 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
//#import "My.h"
|
||||
|
||||
@interface Setting : BaseViewController
|
||||
|
||||
//@property(nonatomic) My *parent;
|
||||
|
||||
@end
|
||||
|
||||
@ -1,154 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Setting.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "EquList.h"
|
||||
|
||||
@interface Setting ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)NSArray *cells;
|
||||
@end
|
||||
|
||||
@implementation Setting
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
// [self setNavTitle:@"系统设置"];
|
||||
// [self setupViews];
|
||||
// [self setUI];
|
||||
// [self setData];
|
||||
}
|
||||
/*
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
|
||||
for(int i=0;i<self.cells.count;i++){
|
||||
[self.rview addSubview:self.cells[i]];
|
||||
|
||||
if(i==0){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SetPushOnoff)]];
|
||||
}
|
||||
else if(i==1){
|
||||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SetHFOnoff)]];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<self.cells.count;i++){
|
||||
NSString *top = [[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight] + i*60.5] ;
|
||||
[UI setFrameInView:self.cells[i] Width:@"100vw" Height:@"60" TranslateX:@"0" TranslateY:top InView:nil Position:UITopMid];
|
||||
|
||||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[0] Width:@"70vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidLeft];
|
||||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[1] Width:@"30vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidRight];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)setData{
|
||||
if([Pub getApp].sysinfo.push==1){
|
||||
UIView *cell = (UIView *)self.cells[0];
|
||||
((UILabel *)cell.subviews[1]).text = @"已开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
if([Pub getApp].sysinfo.HF==1){
|
||||
UIView *cell = (UIView *)self.cells[1];
|
||||
((UILabel *)cell.subviews[1]).text = @"已开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
}
|
||||
- (void)SetPushOnoff{
|
||||
[Pub getApp].sysinfo.push = 1-[Pub getApp].sysinfo.push;
|
||||
[[Pub getApp].sysinfo setSystemInfo:@"push" WithValue:[[NSString alloc] initWithFormat:@"%d",[Pub getApp].sysinfo.push]];
|
||||
UIView *cell = (UIView *)self.cells[0];
|
||||
if([Pub getApp].sysinfo.push==1){
|
||||
((UILabel *)cell.subviews[1]).text = @"已开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
else{
|
||||
((UILabel *)cell.subviews[1]).text = @"未开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UIColor grayColor];
|
||||
}
|
||||
[self.parent setNote];
|
||||
[HttpManager postPushkitToken:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token PushkitToken:[Pub getApp].sysinfo.pushkitToken
|
||||
Push:[[NSString alloc] initWithFormat:@"%d",[Pub getApp].sysinfo.push]
|
||||
IsSandbox:[[NSString alloc] initWithFormat:@"%d",[Pub getApp].sysinfo.sandbox] HttpResultHandler:^(NSDictionary *json) {
|
||||
NSLog(@"上传token成功");
|
||||
}];
|
||||
|
||||
}
|
||||
- (void)SetHFOnoff{
|
||||
[Pub getApp].sysinfo.HF = 1-[Pub getApp].sysinfo.HF;
|
||||
[[Pub getApp].sysinfo setSystemInfo:@"HF" WithValue:[[NSString alloc] initWithFormat:@"%d",[Pub getApp].sysinfo.push]];
|
||||
UIView *cell = (UIView *)self.cells[1];
|
||||
if([Pub getApp].sysinfo.HF==1){
|
||||
((UILabel *)cell.subviews[1]).text = @"已开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UI colorWithHex:0x378fe8];
|
||||
}
|
||||
else{
|
||||
((UILabel *)cell.subviews[1]).text = @"未开启";
|
||||
((UILabel *)cell.subviews[1]).textColor = [UIColor grayColor];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
- (NSArray *)cells{
|
||||
if (!_cells) {
|
||||
UIView *cell1 = [[UIView alloc] init];
|
||||
cell1.backgroundColor = [UIColor whiteColor];
|
||||
[cell1 addSubview:[UI NewLabel:@"推送功能" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell1 addSubview:[UI NewLabel:@"未开启" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
UIView *cell2 = [[UIView alloc] init];
|
||||
cell2.backgroundColor = [UIColor whiteColor];
|
||||
[cell2 addSubview:[UI NewLabel:@"默认免提" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||||
[cell2 addSubview:[UI NewLabel:@"未开启" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]];
|
||||
|
||||
|
||||
|
||||
|
||||
_cells = @[cell1,cell2 ];
|
||||
}
|
||||
return _cells;
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface Web : BaseViewController<UIScrollViewDelegate>
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -1,130 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Web.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "EquList.h"
|
||||
#import "HttpManager.h"
|
||||
|
||||
@interface Web ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
@property (nonatomic, strong)UIScrollView *scrollView;
|
||||
@property (nonatomic, strong)UILabel *webLabel;
|
||||
@end
|
||||
|
||||
@implementation Web
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
|
||||
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];//#378fe8
|
||||
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
|
||||
|
||||
[self setNavTitle:@"用户隐私协议"];
|
||||
[self setNavLeft:@"back" action:@selector(pageBack2)];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
|
||||
[HttpManager loadPage:@"http://47.107.109.110/app/privacy1.aspx" HttpResultHandler:^(NSData * data) {//
|
||||
//NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
//ret = [ret stringByAppendingFormat:@"<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>"];
|
||||
|
||||
NSDictionary *options = @{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding) };
|
||||
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
|
||||
|
||||
NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
|
||||
para.lineSpacing = 7;
|
||||
para.paragraphSpacing = 10;
|
||||
[attStr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, attStr.length)];
|
||||
|
||||
|
||||
self.webLabel.attributedText = attStr;
|
||||
//NSLog(@"%@",self.webLabel.attributedText);
|
||||
|
||||
CGRect desRect = [attStr boundingRectWithSize:CGSizeMake([UI getScreenWidth]-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
|
||||
self.scrollView.contentSize=CGSizeMake( [UI getScreenWidth],desRect.size.height + 100);
|
||||
self.webLabel.frame = CGRectMake(10,0,[UI getScreenWidth]-20, desRect.size.height + 40);
|
||||
}];
|
||||
|
||||
}
|
||||
- (void)pageBack2{
|
||||
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
self.edgesForExtendedLayout = UIRectEdgeNone;
|
||||
self.extendedLayoutIncludesOpaqueBars = NO;
|
||||
self.modalPresentationCapturesStatusBarAppearance = NO;
|
||||
self.automaticallyAdjustsScrollViewInsets = NO;
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
[self.rview addSubview:self.scrollView];
|
||||
[self.scrollView addSubview:self.webLabel];
|
||||
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
|
||||
|
||||
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
//self.scrollView.contentSize=CGSizeMake( [UI getScreenWidth],4000);
|
||||
//self.webLabel.frame = CGRectMake(0,0,[UI getScreenWidth], 4000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
|
||||
|
||||
- (UIScrollView *)scrollView{
|
||||
if(!_scrollView){
|
||||
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UI getScreenWidth], [UI getScreenHeight])];
|
||||
_scrollView.pagingEnabled = NO;
|
||||
_scrollView.showsHorizontalScrollIndicator = NO;
|
||||
_scrollView.showsVerticalScrollIndicator = YES;
|
||||
_scrollView.delegate = self;
|
||||
}
|
||||
return _scrollView;
|
||||
}
|
||||
- (UILabel *)webLabel
|
||||
{
|
||||
if (!_webLabel) {
|
||||
_webLabel = [[UILabel alloc] init];
|
||||
//_webView.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
_webLabel.font = [UIFont systemFontOfSize:13.0f];
|
||||
_webLabel.textColor = [UIColor blackColor];
|
||||
_webLabel.textAlignment = NSTextAlignmentLeft;
|
||||
_webLabel.text = NSLocalizedString(@"", nil);
|
||||
_webLabel.numberOfLines = 0;
|
||||
}
|
||||
return _webLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseTableViewController.h"
|
||||
|
||||
@interface WifiList : BaseTableViewController<UITableViewDelegate,UITableViewDataSource>
|
||||
|
||||
- (void)setData;
|
||||
@end
|
||||
|
||||
@ -1,130 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WifiList.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
//#import "EquListCell.h"
|
||||
#import "Opendoor.h"
|
||||
#import "EquAdd.h"
|
||||
#import "EquConfig.h"
|
||||
|
||||
@interface WifiList ()
|
||||
@property (nonatomic, strong)UIView *rview;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WifiList
|
||||
NSMutableArray *_dataArray;
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
// [self setNavTitle:@"选择WIFI"];
|
||||
// [self setUI];
|
||||
// [self setData];
|
||||
}
|
||||
/*
|
||||
- (void)setData{
|
||||
_dataArray = [[NSMutableArray alloc] initWithCapacity:0];
|
||||
[_dataArray addObjectsFromArray:[Opendoor getEqulist]];
|
||||
[self.tableView reloadData];
|
||||
|
||||
}
|
||||
- (void)setUI{
|
||||
|
||||
|
||||
|
||||
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, [UI getScreenWidth], [UI getScreenHeight]-60) style:UITableViewStylePlain];
|
||||
[self.tableView registerClass:[EquListCell class] forCellReuseIdentifier:@"EquListCell"];
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
|
||||
NSLog(@"table:%f,%f,%f,%f",self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.frame.size.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)AddEqu{
|
||||
EquAdd *equadd = [[EquAdd alloc] init];
|
||||
equadd.parent = self;
|
||||
[self.navigationController pushViewController:equadd animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark 返回分组数
|
||||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||||
//NSLog(@"计算分组数");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#pragma mark 返回每组行数
|
||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
//NSLog(@"计算每组(组%li)行数",(long)section);
|
||||
return _dataArray.count;
|
||||
}
|
||||
|
||||
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 60;
|
||||
}
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSLog(@"cellForRowAtIndexPath:%ld",indexPath.row);
|
||||
//EquListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EquListCell" forIndexPath:indexPath];
|
||||
EquListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EquListCell"];
|
||||
|
||||
if (cell == nil) {
|
||||
cell = [[EquListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EquListCell"];
|
||||
}
|
||||
if(indexPath.row<_dataArray.count){
|
||||
cell.titleLabel.text = [_dataArray[indexPath.row] valueForKey:@"name"];
|
||||
cell.contentLabel.text = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
}
|
||||
|
||||
|
||||
// if (indexPath.row == self.timeListenData.count - 1) {
|
||||
// [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
||||
// }
|
||||
return cell;
|
||||
}
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
//NSLog(@"didSelectRowAtIndexPath:%ld",indexPath.row);
|
||||
if(indexPath.row<_dataArray.count){
|
||||
NSArray * options = @[@"命名设备",@"配置网关",@"删除"];
|
||||
|
||||
[Msg Select:self SourceView:[tableView cellForRowAtIndexPath:indexPath] Title:@"请选择" Options:options SelectedHandler:^(int index) {
|
||||
if(index==0){
|
||||
EquAdd *equadd = [[EquAdd alloc] init];
|
||||
equadd.parent = self;
|
||||
equadd.equid = [_dataArray[indexPath.row] valueForKey:@"equid"];
|
||||
equadd.name = [_dataArray[indexPath.row] valueForKey:@"name"];
|
||||
[self.navigationController pushViewController:equadd animated:YES];
|
||||
}
|
||||
else if(index==1){
|
||||
|
||||
EquConfig *equconfig = [[EquConfig alloc] init];
|
||||
[self.navigationController pushViewController:equconfig animated:YES];
|
||||
}
|
||||
else if(index==2){
|
||||
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@end
|
||||
@ -1,26 +0,0 @@
|
||||
//
|
||||
// HttpManager.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface HttpManager: NSObject
|
||||
+ (void)SendSmsCode:(NSString *)username HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)Login:(NSString *)username Code:(NSString *)code HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)CheckLoginStatu:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)BindEquSucc:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid Name:(NSString *)name HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)EquList:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)DelEqu:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)Gzh_Qrcode:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)HasBindGzh:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)UnbindGzh:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)GetLatestVersionCode:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)UpPhoto:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid Imgdata:(NSData*) data HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)getPhotos:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)delPhoto:(NSString *)username Token:(NSString *)token No:(NSString *)no HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)postPushkitToken:(NSString *)username Token:(NSString *)token PushkitToken:(NSString *)pushkitToken Push:(NSString *)push IsSandbox:(NSString *)sandbox HttpResultHandler:(void (^)(NSDictionary *json)) handler;
|
||||
+ (void)loadPage:(NSString *)url HttpResultHandler:(void (^)(NSData * data)) handler;
|
||||
@end
|
||||
@ -1,310 +0,0 @@
|
||||
//
|
||||
// HttpManager.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
|
||||
#import "HttpManager.h"
|
||||
#import "Pub.h"
|
||||
#import "Sformat.h"
|
||||
#define Share_AppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
|
||||
@interface HttpManager (){
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@implementation HttpManager{
|
||||
|
||||
}
|
||||
|
||||
+ (NSString *)InitUrl{
|
||||
NSString *url = [@"http://" stringByAppendingString:[Pub getSysInfo].server_wan];
|
||||
url = [url stringByAppendingString:@"/TalkApp/api.aspx"];
|
||||
return url;
|
||||
}
|
||||
+ (void)SendSmsCode:(NSString *)username HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"SendSmsCode" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username"]];
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
}
|
||||
+ (void)Login:(NSString *)username Code:(NSString *)code HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"Login" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:code forKey:@"code"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"code"]];
|
||||
|
||||
|
||||
|
||||
// [self Post:url WithData:paramDic completionHandler:^(NSURLResponse * response, NSData * data, NSError * connectionError) {
|
||||
// NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
// NSLog(@"%@",ret);
|
||||
//
|
||||
// }];
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
|
||||
+ (void)CheckLoginStatu:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"CheckLoginStatu" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)BindEquSucc:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid Name:(NSString *)name HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
//NSString *name_encode = [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
//解码 stringByReplacingPercentEscapesUsingEncoding
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
|
||||
[paramDic setValue:@"BindEquSucc" forKey:@"op"];
|
||||
[paramDic setValue:username forKey:@"username"];
|
||||
[paramDic setValue:token forKey:@"token"];
|
||||
[paramDic setValue:equid forKey:@"equid"];
|
||||
[paramDic setValue:name forKey:@"name"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"equid",@"name"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)EquList:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"EquList" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)DelEqu:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"DelEqu" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
[paramDic setObject:equid forKey:@"equid"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"equid"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)Gzh_Qrcode:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"Gzh_Qrcode" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)HasBindGzh:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"HasBindGzh" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)UnbindGzh:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"UnbindGzh" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
|
||||
+ (void)GetLatestVersionCode:(NSString *)username Token:(NSString *)token HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"GetLatestVersionCode" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)UpPhoto:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid Imgdata:(NSData*) data HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"UpPhoto" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
[paramDic setObject:equid forKey:@"equid"];
|
||||
|
||||
NSData *data1 = [data base64EncodedDataWithOptions:(0)];
|
||||
NSString * imgdata = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];
|
||||
|
||||
[paramDic setObject:imgdata forKey:@"imgdata"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"equid",@"imgdata"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
+ (void)delPhoto:(NSString *)username Token:(NSString *)token No:(NSString *)no HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"delPhoto" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
[paramDic setObject:no forKey:@"no"];
|
||||
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"no"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
|
||||
+ (void)getPhotos:(NSString *)username Token:(NSString *)token Equid:(NSString *)equid HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"getPhotos" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
[paramDic setObject:equid forKey:@"equid"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"equid"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
|
||||
+ (void)postPushkitToken:(NSString *)username Token:(NSString *)token PushkitToken:(NSString *)pushkitToken Push:(NSString *)push IsSandbox:(NSString *)sandbox HttpResultHandler:(void (^)(NSDictionary *json)) handler{
|
||||
|
||||
NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
|
||||
[paramDic setObject:@"postPushkitToken" forKey:@"op"];
|
||||
[paramDic setObject:username forKey:@"username"];
|
||||
[paramDic setObject:token forKey:@"token"];
|
||||
[paramDic setObject:pushkitToken forKey:@"pushkitToken"];
|
||||
[paramDic setObject:push forKey:@"push"];
|
||||
[paramDic setObject:sandbox forKey:@"sandbox"];
|
||||
paramDic = [self AddSign:paramDic WithKey:[[NSString alloc] initWithFormat:@"talkapp%@",[Sformat yyyy_MM_dd]] Field:@[@"op",@"username",@"token",@"pushkitToken"]];
|
||||
|
||||
|
||||
[self Post:[self InitUrl] WithData:paramDic HttpResultHandler:handler];
|
||||
|
||||
}
|
||||
|
||||
+ (void)loadPage:(NSString *)url HttpResultHandler:(void (^)(NSData * data)) handler{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
|
||||
request.HTTPMethod = @"POST";
|
||||
NSString *body = @"ios=1";
|
||||
|
||||
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[NSURLConnection sendAsynchronousRequest:request queue: [[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * response, NSData * data, NSError * connectionError) {
|
||||
//NSLog(@"ret :%@",connectionError);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
//[Msg Alert:self Msg:ret];
|
||||
//NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
handler(data);
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
+(NSMutableDictionary *)AddSign:(NSMutableDictionary *)paramDic WithKey:(NSString *) key Field:(NSArray *)field{
|
||||
NSString *str4sign = @"";
|
||||
// for(id key in paramDic){
|
||||
// str4sign = [str4sign stringByAppendingString:key];
|
||||
// str4sign = [str4sign stringByAppendingString:[paramDic objectForKey:key] ];
|
||||
// }
|
||||
for(id item in field){
|
||||
//NSLog(@"AddSign:item=%@",item);
|
||||
//NSLog(@"AddSign:value=%@",[paramDic objectForKey:item] );
|
||||
str4sign = [str4sign stringByAppendingString:item];
|
||||
str4sign = [str4sign stringByAppendingString:[paramDic objectForKey:item] ];
|
||||
}
|
||||
str4sign = [str4sign stringByAppendingString:key];
|
||||
//NSLog(@"AddSign:%@",str4sign);
|
||||
[paramDic setObject:[Pub md5_:str4sign] forKey:@"sign"];
|
||||
return paramDic;
|
||||
}
|
||||
|
||||
+ (void)Post:(NSString *)url WithData:(NSMutableDictionary *)paramDic HttpResultHandler:(void (^)(NSDictionary *json)) handler {
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
|
||||
request.HTTPMethod = @"POST";
|
||||
|
||||
NSString *body = @"ios=1";
|
||||
NSString *str4sign = @"";
|
||||
for(id key in paramDic){
|
||||
body = [body stringByAppendingString:[[NSString alloc] initWithFormat:@"&%@=",key]];
|
||||
body = [body stringByAppendingString:[paramDic objectForKey:key] ];
|
||||
}
|
||||
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
//NSLog(@"body :%@",body);
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
|
||||
//NSLog(@"systemVersion :%f",[[UIDevice currentDevice].systemVersion floatValue]);
|
||||
|
||||
NSURLSession *session = [NSURLSession sharedSession];
|
||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
|
||||
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
|
||||
{
|
||||
//NSLog(@"ret :%@",error);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
//[Msg Alert:self Msg:ret];
|
||||
NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
//NSLog(@"ret :%@",ret);
|
||||
NSDictionary * json = [Pub DictionaryWithJsonString:ret];
|
||||
if(!json){
|
||||
json = [Pub DictionaryWithJsonString:@"{\"result\":\"网络异常\"}"];
|
||||
}
|
||||
handler(json);
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
|
||||
}
|
||||
else{
|
||||
//[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:handler];
|
||||
[NSURLConnection sendAsynchronousRequest:request queue: [[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * response, NSData * data, NSError * connectionError) {
|
||||
//NSLog(@"ret :%@",connectionError);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
//[Msg Alert:self Msg:ret];
|
||||
NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
//NSLog(@"ret :%@",ret);
|
||||
NSDictionary * json = [Pub DictionaryWithJsonString:ret];
|
||||
if(!json){
|
||||
json = [Pub DictionaryWithJsonString:@"{\"result\":\"网络异常\"}"];
|
||||
}
|
||||
handler(json);
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,17 +0,0 @@
|
||||
//
|
||||
// HttpManager.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface Msg: NSObject
|
||||
+ (void)alert:(NSString *)msg;
|
||||
+ (void)Alert:(UIViewController *)page Msg:(NSString *)msg;
|
||||
+ (UIAlertController *)Waiting:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(void)) handler;
|
||||
+ (void)MessageBox:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(int index)) handler;
|
||||
+ (UIAlertController *)OpendoorByPwd:(UIViewController *)page SelectedHandler:(void (^)(int index)) handler ;
|
||||
+ (void)Select:(UIViewController *)page SourceView:(UIView *)view Title:(NSString *)title Options:(NSArray *)arr SelectedHandler:(void (^)(int index)) handler;
|
||||
@end
|
||||
@ -1,152 +0,0 @@
|
||||
//
|
||||
// HttpManager.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
//#import "HKHTextField.h"
|
||||
#import "BaseViewController.h"
|
||||
#import "OpenPwd.h"
|
||||
#import "UI.h"
|
||||
|
||||
|
||||
@interface Msg (){
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@implementation Msg{
|
||||
|
||||
}
|
||||
+ (void)alert:(NSString *)msg{
|
||||
@try
|
||||
{
|
||||
|
||||
if([@"MainTabBar" isEqualToString:NSStringFromClass([[Pub getApp].window.rootViewController class])]){
|
||||
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
|
||||
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
|
||||
BaseViewController *v = (BaseViewController *)nav.viewControllers[nav.viewControllers.count-1];
|
||||
[v alert:msg];
|
||||
|
||||
|
||||
}
|
||||
|
||||
} @catch (NSException * e) {
|
||||
NSLog(@"%@",e);
|
||||
}
|
||||
|
||||
}
|
||||
+ (void)Alert:(UIViewController *)page Msg:(NSString *)msg{
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
|
||||
NSLog(@"无需处理");
|
||||
}];
|
||||
[alertController addAction:okAction];
|
||||
[page presentViewController:alertController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (UIAlertController *)Waiting:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(void)) handler {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
|
||||
|
||||
if(handler)handler();
|
||||
}];
|
||||
[alertController addAction:cancelAction];
|
||||
[page presentViewController:alertController animated:YES completion:nil];
|
||||
return alertController;
|
||||
}
|
||||
|
||||
+ (void)MessageBox:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(int index)) handler {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
handler(1);
|
||||
NSLog(@"确定");
|
||||
}];
|
||||
[alertController addAction:cancelAction];
|
||||
[alertController addAction:okAction];
|
||||
[page presentViewController:alertController animated:YES completion:nil];
|
||||
}
|
||||
+ (UIAlertController *)OpendoorByPwd:(UIViewController *)page SelectedHandler:(void (^)(int index)) handler {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请输入开门密码" message:@"\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
handler(1);
|
||||
NSLog(@"确定");
|
||||
}];
|
||||
[alertController addAction:cancelAction];
|
||||
[alertController addAction:okAction];
|
||||
|
||||
OpenPwd *open = [[OpenPwd alloc] init];
|
||||
open.parent = page;
|
||||
[alertController addChildViewController:open];
|
||||
[alertController.view addSubview:open.view];
|
||||
open.view.frame = CGRectMake(0, 50, 270, 50);
|
||||
[open setUI];
|
||||
|
||||
|
||||
[page presentViewController:alertController animated:YES completion:^{
|
||||
[open focusTextField];
|
||||
}];
|
||||
//[alertController dismissViewControllerAnimated:YES completion:nil];
|
||||
return alertController;
|
||||
}
|
||||
|
||||
+ (void)Select:(UIViewController *)page SourceView:(UIView *)view Title:(NSString *)title Options:(NSArray *)arr SelectedHandler:(void (^)(int index)) handler {
|
||||
|
||||
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
NSLog(@"Select1");
|
||||
actionSheet.popoverPresentationController.sourceView = page.view;
|
||||
NSLog(@"Select2");
|
||||
@try
|
||||
{
|
||||
actionSheet.popoverPresentationController.sourceRect = CGRectMake(view.frame.origin.x + (view.frame.size.width-200)/2, view.frame.origin.y + 50, 200, 100);
|
||||
|
||||
} @catch (NSException * e) {
|
||||
actionSheet.popoverPresentationController.sourceRect = CGRectMake([UI getScreenWidth] - 200, 0, 200, 100);
|
||||
}
|
||||
|
||||
//actionSheet.popoverPresentationController.sourceRect = page.view.frame;
|
||||
NSLog(@"Select3");
|
||||
for (int i=0;i<arr.count;i++){
|
||||
NSLog(@"Select:%@", NSStringFromClass([arr[i] class]));
|
||||
if([@"__NSDictionaryM" isEqualToString:NSStringFromClass([arr[i] class])]){
|
||||
UIAlertAction *action1 = [UIAlertAction actionWithTitle:[arr[i] valueForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
handler(i);
|
||||
}];
|
||||
[actionSheet addAction:action1];
|
||||
}
|
||||
else if([@"CBPeripheral" isEqualToString:NSStringFromClass([arr[i] class])]){
|
||||
UIAlertAction *action1 = [UIAlertAction actionWithTitle:[arr[i] valueForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
handler(i);
|
||||
}];
|
||||
[actionSheet addAction:action1];
|
||||
|
||||
}
|
||||
else{
|
||||
UIAlertAction *action1 = [UIAlertAction actionWithTitle:arr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
|
||||
handler(i);
|
||||
}];
|
||||
[actionSheet addAction:action1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
|
||||
handler(-1);
|
||||
}];
|
||||
|
||||
//把action添加到actionSheet里
|
||||
[actionSheet addAction:cancel];
|
||||
|
||||
//相当于之前的[actionSheet show];
|
||||
|
||||
[page presentViewController:actionSheet animated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,52 +0,0 @@
|
||||
//
|
||||
// HttpManager.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "sysinfo.h"
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <sys/socket.h> // Per msqr
|
||||
#include <sys/sysctl.h>
|
||||
#import <ifaddrs.h>
|
||||
#import <arpa/inet.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <CommonCrypto/CommonCryptor.h>
|
||||
#import "AppDelegate.h"
|
||||
#import "BaseNavigationController.h"
|
||||
|
||||
#ifndef Talk_Pub_h
|
||||
#define Talk_Pub_h
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@interface Pub: NSObject
|
||||
+ (AppDelegate *)getApp;
|
||||
+ (sysInfo *)getSysInfo;
|
||||
+ (NSString *)MD5:(NSString *)input;
|
||||
+ (NSString *)md5_:(NSString *)input;
|
||||
+ (NSDictionary *)DictionaryWithJsonString:(NSString *)jsonString;
|
||||
+ (BaseNavigationController *)getNav;
|
||||
+ (void)addHead:(NSString *)head toByte:(Byte *)bb;
|
||||
+ (void)addEquid:(NSString *)equId toByte:(Byte *)bb at:(int)pos;
|
||||
+ (int)getBBlen:(Byte *)bb Len:(int)len;
|
||||
+ (int)addGKB:(NSString *)equId toByte:(Byte *)bb at:(int)pos;
|
||||
+ (void)addIp:(NSString *)ip toByte:(Byte *)bb at:(int)pos;
|
||||
+ (void)addMac:(NSString *)mac toByte:(Byte *)bb at:(int)pos;
|
||||
+ (void)addInt:(int)port toByte:(Byte *)bb at:(int)pos;
|
||||
+ (void)addShort:(int)port toByte:(Byte *)bb at:(int)pos;
|
||||
+ (short)getShortFromByte:(Byte *)bb at:(int)pos;
|
||||
+ (int)Ox:(NSString *)v;
|
||||
+ (NSString *)getLocalIP;
|
||||
+ (NSString *)getMac;
|
||||
+ (NSString *)getEquidFrombb:(Byte *)bb at:(int)pos;
|
||||
+ (NSString *)NSdata2String:(NSData *)data;
|
||||
+ (NSData *)AES128_Encrypt:(NSString *)key encryptData:(NSData *)data;
|
||||
+ (NSData *)AES128_Decrypt:(NSString *)key encryptData:(NSData *)data;
|
||||
+ (NSString *)convertDataToHexStr:(NSData *)data;//将NSData转换成十六进制数据
|
||||
+ (NSData *)dataFromHexString:(NSString *)hexString;//将十六进制字符串转换为二进制数据
|
||||
@end
|
||||
@ -1,406 +0,0 @@
|
||||
//
|
||||
// HttpManager.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
|
||||
#import "Pub.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@interface Pub (){
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@implementation Pub{
|
||||
|
||||
}
|
||||
+ (AppDelegate *)getApp{
|
||||
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
return app;
|
||||
}
|
||||
+ (sysInfo *)getSysInfo{
|
||||
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
return app.sysinfo;
|
||||
}
|
||||
+ (BaseNavigationController*)getNav{
|
||||
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
|
||||
if(tab){
|
||||
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
|
||||
return nav;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSString *)MD5:(NSString *)input //大写
|
||||
{
|
||||
const char *cStr = [input UTF8String];
|
||||
unsigned char digest[16];
|
||||
CC_MD5( cStr, (CC_LONG)strlen(cStr), digest ); // This is the md5 call
|
||||
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
|
||||
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
|
||||
[output appendFormat:@"%02X", digest[i]];
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
+ (NSString *)md5_:(NSString *)input //大写
|
||||
{
|
||||
const char *cStr = [input UTF8String];
|
||||
unsigned char digest[16];
|
||||
CC_MD5( cStr, (CC_LONG)strlen(cStr), digest ); // This is the md5 call
|
||||
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
|
||||
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
|
||||
[output appendFormat:@"%02x", digest[i]];
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)DictionaryWithJsonString:(NSString *)jsonString {
|
||||
if (jsonString == nil) { return nil; }
|
||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *err;
|
||||
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
|
||||
if(err) {
|
||||
NSLog(@"json解析失败:%@",err);
|
||||
return nil;
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
|
||||
+ (void)addHead:(NSString *)head toByte:(Byte *)bb
|
||||
{
|
||||
Byte *tempbb;
|
||||
NSString *tempS;
|
||||
NSData *tempData;
|
||||
tempS = @"XXXCID";
|
||||
tempData = [tempS dataUsingEncoding:NSUTF8StringEncoding];
|
||||
tempbb = (Byte *)[tempData bytes];
|
||||
memcpy(bb, tempbb, 6);
|
||||
}
|
||||
|
||||
+ (void)addEquid:(NSString *)equId toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
Byte *tempbb;
|
||||
NSString *tempS;
|
||||
NSData *tempData;
|
||||
//本地
|
||||
tempS = equId;
|
||||
tempData = [tempS dataUsingEncoding:NSUTF8StringEncoding];
|
||||
tempbb = (Byte *)[tempData bytes];
|
||||
memcpy(bb+pos, tempbb, [tempData length]);
|
||||
for (int i=(int)[tempData length]; i<20; i++){
|
||||
bb[i+pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+ (int)getBBlen:(Byte *)bb Len:(int)len{
|
||||
for(int i=0; i<len; i++){
|
||||
if (bb[i] == 0){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
+ (int)addGKB:(NSString *)equId toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
Byte *tempbb;
|
||||
NSString *tempS;
|
||||
NSData *tempData;
|
||||
//本地
|
||||
|
||||
NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
||||
tempS = equId;
|
||||
tempData = [tempS dataUsingEncoding:gbkEncoding];
|
||||
tempbb = (Byte *)[tempData bytes];
|
||||
memcpy(bb+pos, tempbb, [tempData length]);
|
||||
return (int)[tempData length] ;
|
||||
}
|
||||
|
||||
+ (void)addIp:(NSString *)ip toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
NSArray *tempA = [ip componentsSeparatedByString:@"."];
|
||||
for (int i=0; i<tempA.count; i++){
|
||||
bb[i+pos] = [(NSString *)[tempA objectAtIndex:i] intValue];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)addMac:(NSString *)mac toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
NSArray *tempA = [mac componentsSeparatedByString:@":"];
|
||||
for (int i=0; i<tempA.count; i++){
|
||||
bb[i+pos] = [self Ox:(NSString *)[tempA objectAtIndex:i]];
|
||||
bb[i+pos] = [self Ox:(NSString *)[tempA objectAtIndex:i]];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)addInt:(int)port toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
bb[pos+3] = (Byte)((port & 0xFF000000) >> 24);
|
||||
bb[pos+2] = (Byte)((port & 0x00FF0000) >> 16);
|
||||
bb[pos+1] = (Byte)((port & 0x0000FF00) >> 8);
|
||||
bb[pos] = (Byte)((port & 0x000000FF) );
|
||||
|
||||
}
|
||||
+ (void)addShort:(int)port toByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
bb[pos+1] = (Byte)((port & 0x0000FF00) >> 8);
|
||||
bb[pos] = (Byte)((port & 0x000000FF) );
|
||||
|
||||
}
|
||||
+ (short)getShortFromByte:(Byte *)bb at:(int)pos
|
||||
{
|
||||
return bb[pos] + bb[pos+1]*256;
|
||||
}
|
||||
|
||||
+ (int)Ox:(NSString *)v
|
||||
{
|
||||
int n = 0;
|
||||
int p = 0;
|
||||
NSString *s;
|
||||
for (int i=0; i<v.length; i++){
|
||||
s = [v substringWithRange:NSMakeRange(i, 1)];
|
||||
if ([s isEqualToString:@"A"]|[s isEqualToString:@"a"]) p=10;
|
||||
else if ([s isEqualToString:@"B"]|[s isEqualToString:@"b"]) p=11;
|
||||
else if ([s isEqualToString:@"C"]|[s isEqualToString:@"c"]) p=12;
|
||||
else if ([s isEqualToString:@"D"]|[s isEqualToString:@"d"]) p=13;
|
||||
else if ([s isEqualToString:@"E"]|[s isEqualToString:@"e"]) p=14;
|
||||
else if ([s isEqualToString:@"F"]|[s isEqualToString:@"f"]) p=15;
|
||||
else p = [s intValue];
|
||||
for (int j=i+1; j<v.length; j++){
|
||||
p = p*16;
|
||||
}
|
||||
n += p;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
+ (NSString *)getLocalIP
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
NSString *address = @"error";
|
||||
struct ifaddrs *interfaces = NULL;
|
||||
struct ifaddrs *temp_addr = NULL;
|
||||
int success = 0;
|
||||
// retrieve the current interfaces - returns 0 on success
|
||||
success = getifaddrs(&interfaces);
|
||||
if (success == 0) {
|
||||
// Loop through linked list of interfaces
|
||||
temp_addr = interfaces;
|
||||
while(temp_addr != NULL) {
|
||||
if(temp_addr->ifa_addr->sa_family == AF_INET) {
|
||||
// Check if interface is en0 which is the wifi connection on the iPhone
|
||||
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
|
||||
// Get NSString from C String
|
||||
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
|
||||
}
|
||||
}
|
||||
temp_addr = temp_addr->ifa_next;
|
||||
}
|
||||
}
|
||||
// Free memory
|
||||
freeifaddrs(interfaces);
|
||||
[Pub getApp].sysinfo.equip = address;
|
||||
});
|
||||
return [Pub getApp].sysinfo.equip;
|
||||
|
||||
}
|
||||
|
||||
//针对ipv6网络环境下适配,ipv4环境直接使用原来的地址
|
||||
|
||||
+ (NSString *)getMac
|
||||
{
|
||||
int mib[6];
|
||||
size_t len;
|
||||
char *buf;
|
||||
unsigned char *ptr;
|
||||
struct if_msghdr *ifm;
|
||||
struct sockaddr_dl *sdl;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = AF_ROUTE;
|
||||
mib[2] = 0;
|
||||
mib[3] = AF_LINK;
|
||||
mib[4] = NET_RT_IFLIST;
|
||||
|
||||
if ((mib[5] = if_nametoindex("en0")) == 0) {
|
||||
printf("Error: if_nametoindex error/n");
|
||||
return NULL;
|
||||
}
|
||||
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
|
||||
printf("Error: sysctl, take 1/n");
|
||||
return NULL;
|
||||
}
|
||||
buf = malloc(len);
|
||||
if (buf == NULL) {
|
||||
printf("Could not allocate memory. error!/n");
|
||||
return NULL;
|
||||
}
|
||||
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
|
||||
//printf("Error: sysctl, take 2");
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
ifm = (struct if_msghdr *)buf;
|
||||
sdl = (struct sockaddr_dl *)(ifm + 1);
|
||||
ptr = (unsigned char *)LLADDR(sdl);
|
||||
NSString *outstring = [NSString stringWithFormat:@"%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
|
||||
free(buf);
|
||||
return [outstring uppercaseString];
|
||||
}
|
||||
+ (NSString *)getEquidFrombb:(Byte *)bb at:(int)pos {
|
||||
NSString *equid = nil;
|
||||
int equlen=8;
|
||||
if (bb[pos]==77) {//M
|
||||
equlen=8;
|
||||
}
|
||||
else if(bb[pos]==87) {//W
|
||||
equlen=5;
|
||||
}
|
||||
else if(bb[pos]==72){//H
|
||||
equlen=12;
|
||||
}
|
||||
else if(bb[pos]==83){//S
|
||||
equlen=12;
|
||||
}
|
||||
else if(bb[pos]==0x50){//P
|
||||
equlen=12;
|
||||
}
|
||||
else if(bb[pos]==0x54){//T
|
||||
equlen=16;
|
||||
}
|
||||
else{
|
||||
equlen=12;
|
||||
}
|
||||
|
||||
Byte tempbb[equlen];
|
||||
memcpy(tempbb, bb+pos, equlen);
|
||||
NSData *aadata = [[NSData alloc] initWithBytes:tempbb length:equlen];
|
||||
NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
||||
equid = [[NSString alloc] initWithData:aadata encoding:gbkEncoding];
|
||||
return equid;
|
||||
}
|
||||
+ (NSString *)NSdata2String:(NSData *)data{
|
||||
NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
||||
return [[NSString alloc] initWithData:data encoding:gbkEncoding];
|
||||
}
|
||||
+ (NSData *)AES128_Encrypt:(NSString *)key encryptData:(NSData *)data{
|
||||
|
||||
char keyPtr[kCCKeySizeAES128+1];
|
||||
bzero(keyPtr, sizeof(keyPtr));
|
||||
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
|
||||
|
||||
//无向量
|
||||
// char ivPtr[kCCKeySizeAES128+1];
|
||||
// memset(ivPtr, 0, sizeof(ivPtr));
|
||||
// [gIv getCString:ivPtr maxLength:sizeof(ivPtr) encoding:NSUTF8StringEncoding];
|
||||
|
||||
NSUInteger dataLength = [data length];
|
||||
size_t bufferSize = dataLength + kCCBlockSizeAES128;
|
||||
void *buffer = malloc(bufferSize);
|
||||
size_t numBytesEncrypted = 0;
|
||||
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
|
||||
kCCAlgorithmAES128,
|
||||
kCCOptionPKCS7Padding,
|
||||
keyPtr,
|
||||
kCCBlockSizeAES128,
|
||||
nil,
|
||||
[data bytes],
|
||||
dataLength,
|
||||
buffer,
|
||||
bufferSize,
|
||||
&numBytesEncrypted);
|
||||
if (cryptStatus == kCCSuccess) {
|
||||
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
|
||||
}
|
||||
free(buffer);
|
||||
return nil;
|
||||
}
|
||||
+ (NSData *)AES128_Decrypt:(NSString *)key encryptData:(NSData *)data{
|
||||
char keyPtr[kCCKeySizeAES128+1];
|
||||
bzero(keyPtr, sizeof(keyPtr));
|
||||
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
|
||||
|
||||
//无向量
|
||||
// char ivPtr[kCCKeySizeAES128+1];
|
||||
// memset(ivPtr, 0, sizeof(ivPtr));
|
||||
// [gIv getCString:ivPtr maxLength:sizeof(ivPtr) encoding:NSUTF8StringEncoding];
|
||||
|
||||
NSUInteger dataLength = [data length];
|
||||
size_t bufferSize = dataLength + kCCBlockSizeAES128;
|
||||
void *buffer = malloc(bufferSize);
|
||||
size_t numBytesDecrypted = 0;
|
||||
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
|
||||
kCCAlgorithmAES128,
|
||||
kCCOptionPKCS7Padding,
|
||||
keyPtr,
|
||||
kCCBlockSizeAES128,
|
||||
nil,
|
||||
[data bytes],
|
||||
dataLength,
|
||||
buffer,
|
||||
bufferSize,
|
||||
&numBytesDecrypted);
|
||||
if (cryptStatus == kCCSuccess) {
|
||||
return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
|
||||
}
|
||||
free(buffer);
|
||||
return nil;
|
||||
}
|
||||
|
||||
//将NSData转换成十六进制的字符串则可使用如下方式:
|
||||
+ (NSString *)convertDataToHexStr:(NSData *)data {
|
||||
if (!data || [data length] == 0) {
|
||||
return @"";
|
||||
}
|
||||
NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
|
||||
|
||||
[data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
|
||||
unsigned char *dataBytes = (unsigned char*)bytes;
|
||||
for (NSInteger i = 0; i < byteRange.length; i++) {
|
||||
NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
|
||||
if ([hexStr length] == 2) {
|
||||
[string appendString:hexStr];
|
||||
} else {
|
||||
[string appendFormat:@"0%@", hexStr];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
//将十六进制字符串转换为二进制数据
|
||||
+ (NSData *)dataFromHexString:(NSString *)hexString {
|
||||
// 去除字符串中的空格和换行符
|
||||
NSString *cleanedString = [hexString stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
cleanedString = [cleanedString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
||||
|
||||
// 检查字符串长度是否为偶数
|
||||
if (cleanedString.length % 2 != 0) {
|
||||
// 如果长度为奇数,可以根据需要选择在字符串前面添加或去除一个字符
|
||||
// 例如,你可以选择在前面添加一个零,或者去除最后一个字符
|
||||
// cleanedString = [@"0" stringByAppendingString:cleanedString];
|
||||
// 或者
|
||||
// cleanedString = [cleanedString substringToIndex:cleanedString.length - 1];
|
||||
}
|
||||
|
||||
// 使用一个循环将每两个字符转换为一个字节
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
for (NSInteger i = 0; i < cleanedString.length; i += 2) {
|
||||
NSString *byteString = [cleanedString substringWithRange:NSMakeRange(i, 2)];
|
||||
NSScanner *scanner = [NSScanner scannerWithString:byteString];
|
||||
unsigned int byteValue;
|
||||
[scanner scanHexInt:&byteValue];
|
||||
uint8_t byte = (uint8_t)byteValue;
|
||||
[data appendBytes:&byte length:1];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@end
|
||||
@ -1,22 +0,0 @@
|
||||
//
|
||||
// HttpManager.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface Sformat: NSObject
|
||||
|
||||
+ (NSString *)yyyy_MM_dd;
|
||||
+ (long)timestamp;
|
||||
+ (long)timestamp:(NSDate *)date;
|
||||
+ (NSString *)Hex:(NSData *)data;
|
||||
+ (NSDate *)DateByTimestamp:(NSString *)timestamp;
|
||||
+ (NSString *)yyyy_MM_dd_HH_mm:(NSString *)timestamp;
|
||||
+ (NSString *)yyyy_MM_dd_HH_mm_cn:(NSString *)timestamp;
|
||||
+ (NSDate *)dateWithYearsBeforeNow:(NSInteger)year;
|
||||
+ (NSDate *)dateWithMonthBeforeNow:(NSInteger)month;
|
||||
+ (NSDate *)dateWithDayBeforeNow:(NSInteger)day;
|
||||
|
||||
@end
|
||||
@ -1,127 +0,0 @@
|
||||
//
|
||||
// HttpManager.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/11/6.
|
||||
//
|
||||
|
||||
#import "Sformat.h"
|
||||
|
||||
|
||||
@interface Sformat (){
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@implementation Sformat{
|
||||
|
||||
}
|
||||
+ (NSString *)yyyy_MM_dd{
|
||||
NSDate *now = [NSDate date];
|
||||
|
||||
NSCalendar *calendar = [NSCalendar currentCalendar];
|
||||
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
|
||||
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
|
||||
|
||||
int year = [dateComponent year];
|
||||
int month = [dateComponent month];
|
||||
int day = [dateComponent day];
|
||||
|
||||
return [[NSString alloc] initWithFormat:@"%04d-%02d-%02d",year,month,day];
|
||||
}
|
||||
+ (long)timestamp{
|
||||
NSDate *now = [NSDate date];
|
||||
return [now timeIntervalSince1970]*1000;
|
||||
}
|
||||
+ (long)timestamp:(NSDate *)date{
|
||||
return [date timeIntervalSince1970]*1000;
|
||||
}
|
||||
|
||||
+ (NSDate *)DateByTimestamp:(NSString *)timestamp{
|
||||
NSTimeInterval time = [timestamp floatValue] / 1000;
|
||||
return [NSDate dateWithTimeIntervalSince1970:time];
|
||||
}
|
||||
|
||||
+ (NSString *)yyyy_MM_dd_HH_mm:(NSString *)timestamp{
|
||||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||||
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
||||
return [dateFormatter stringFromDate:[self DateByTimestamp:timestamp]];
|
||||
}
|
||||
+ (NSString *)yyyy_MM_dd_HH_mm_cn:(NSString *)timestamp{
|
||||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||||
[dateFormatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
|
||||
return [dateFormatter stringFromDate:[self DateByTimestamp:timestamp]];
|
||||
}
|
||||
|
||||
+ (NSDate *)dateWithYearsBeforeNow:(NSInteger)year{
|
||||
NSDate *currentDate = [NSDate date];
|
||||
NSCalendar *calendar = nil;
|
||||
if (FALSE) {//IOS8Higher
|
||||
calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
|
||||
} else {
|
||||
calendar = [NSCalendar currentCalendar];
|
||||
}
|
||||
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
|
||||
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:currentDate];
|
||||
[dateComponent setYear:year * -1];
|
||||
|
||||
return [calendar dateFromComponents:dateComponent];
|
||||
}
|
||||
+ (NSDate *)dateWithMonthBeforeNow:(NSInteger)month{
|
||||
NSDate *currentDate = [NSDate date];
|
||||
NSCalendar *calendar = nil;
|
||||
//calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
|
||||
calendar = [NSCalendar currentCalendar];
|
||||
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ;
|
||||
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:currentDate];
|
||||
[dateComponent setMonth:-1*month];
|
||||
|
||||
return [calendar dateFromComponents:dateComponent];
|
||||
}
|
||||
+ (NSDate *)dateWithDayBeforeNow:(NSInteger)day{
|
||||
NSDate *currentDate = [NSDate date];
|
||||
NSCalendar *calendar = nil;
|
||||
if (FALSE) {//IOS8Higher
|
||||
calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
|
||||
} else {
|
||||
calendar = [NSCalendar currentCalendar];
|
||||
}
|
||||
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
|
||||
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:currentDate];
|
||||
[dateComponent setDay:-1*day];
|
||||
|
||||
return [calendar dateFromComponents:dateComponent];
|
||||
}
|
||||
|
||||
+ (NSString *)Hex:(NSData *)data {
|
||||
if (!data || [data length] == 0) {
|
||||
return @"";
|
||||
|
||||
}
|
||||
|
||||
NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
|
||||
|
||||
[data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
|
||||
unsigned char *dataBytes = (unsigned char*)bytes;
|
||||
|
||||
for (NSInteger i = 0; i < byteRange.length; i++) {
|
||||
NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
|
||||
|
||||
if ([hexStr length] == 2) {
|
||||
[string appendString:hexStr];
|
||||
|
||||
} else {
|
||||
[string appendFormat:@"0%@", hexStr];
|
||||
|
||||
}
|
||||
if(i < byteRange.length-1){
|
||||
[string appendString:@" "];
|
||||
}
|
||||
}
|
||||
|
||||
}];
|
||||
|
||||
return string;
|
||||
|
||||
}
|
||||
@end
|
||||
@ -1,22 +0,0 @@
|
||||
//
|
||||
// IframeInfo.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 13-2-19.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface IframeInfo : NSObject
|
||||
@property (nonatomic,assign) int iframe_index;
|
||||
@property (nonatomic,assign) int iframe_time;
|
||||
@property (nonatomic,assign) long long bag_num;
|
||||
@property (nonatomic,assign) long long bag_receive;
|
||||
@property (nonatomic,assign) Boolean isFull;
|
||||
@property (nonatomic,assign) int cur_len;
|
||||
@property (nonatomic,assign) int bb_len;
|
||||
@property (nonatomic,assign) Byte *bb;
|
||||
@property (nonatomic, assign) int codecMode;
|
||||
|
||||
@end
|
||||
@ -1,29 +0,0 @@
|
||||
//
|
||||
// IframeInfo.m
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 13-2-19.
|
||||
//
|
||||
//
|
||||
|
||||
#import "IframeInfo.h"
|
||||
|
||||
@implementation IframeInfo
|
||||
@synthesize iframe_index;
|
||||
@synthesize iframe_time;
|
||||
@synthesize bag_num;
|
||||
@synthesize bag_receive;
|
||||
@synthesize isFull;
|
||||
@synthesize cur_len;
|
||||
@synthesize bb;
|
||||
@synthesize codecMode;
|
||||
|
||||
-(id)init{
|
||||
iframe_index = -1;
|
||||
bag_num = 0;
|
||||
bag_receive = 0;
|
||||
isFull = NO;
|
||||
cur_len = 0;
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
@ -1,50 +0,0 @@
|
||||
//
|
||||
// playAudio.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-11-20.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
#define NUM_BUFFERS 10
|
||||
#define ABUF_NUM 100
|
||||
#define ISAC_SIZE (240)
|
||||
|
||||
typedef NS_ENUM(NSInteger, EquType) {
|
||||
k8126,
|
||||
k8130,
|
||||
kWebrtc
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, AudiodecodeType) {
|
||||
k711,
|
||||
k722,
|
||||
kIsac
|
||||
};
|
||||
|
||||
@interface playAudio : NSObject {
|
||||
AudioQueueRef queue;
|
||||
AudioQueueBufferRef buffers[NUM_BUFFERS];
|
||||
AudioStreamBasicDescription dataformat;
|
||||
}
|
||||
|
||||
@property Byte *Abuf;
|
||||
@property int Abuf_p;
|
||||
@property int Abuf_len;
|
||||
@property int Version;
|
||||
@property float vol;
|
||||
@property int EuqAudioType;
|
||||
@property int AudiodecodeType;
|
||||
|
||||
- (void)AudioPlayStartWithMode:(int)mod;
|
||||
- (void)AudioEnd;
|
||||
- (int)AudioStartWithRate:(int)rate setChannels:(int)channels setSamples:(int)samples setBuf_samples:(int)buf_samples setVersion:(int)v;
|
||||
- (void)audioQueueOutputWithQueue:(AudioQueueRef)q queueBuffer:(AudioQueueBufferRef)buf;
|
||||
- (void)setVolume:(float)v;
|
||||
|
||||
+ (void)initAudioSession;
|
||||
|
||||
@end
|
||||
@ -1,241 +0,0 @@
|
||||
//
|
||||
// playAudio.m
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-11-20.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "playAudio.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#define SAMPLE_RATE (8000)
|
||||
#define WEBRTC_AUDIO_BUF_SIZE (160*3*2) //30ms (10ms=160samples)
|
||||
|
||||
@implementation playAudio {
|
||||
AppDelegate * app;
|
||||
}
|
||||
|
||||
@synthesize Abuf;
|
||||
@synthesize Abuf_p;
|
||||
@synthesize Abuf_len;
|
||||
@synthesize Version;
|
||||
@synthesize vol;
|
||||
|
||||
static int BYTES_PER_SAMPLES;
|
||||
static bool isAudioStop;
|
||||
|
||||
- (id)init {
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
Abuf = (Byte*)malloc(ABUF_NUM * 64);
|
||||
if ( self = [super init] ) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/* max number of samples per frame (= 60 ms frame) */
|
||||
|
||||
//回调 每当一组音频数据读取完毕之后会自动触发回调方法,读取下一帧数据
|
||||
void buffer_callback(void *inUserData, AudioQueueRef q, AudioQueueBufferRef buf) {
|
||||
//__bridge
|
||||
// NSLog(@"333buffer_callback");
|
||||
playAudio* player = (__bridge playAudio*)inUserData;
|
||||
[player audioQueueOutputWithQueue:q queueBuffer:buf];
|
||||
}
|
||||
|
||||
- (short)G711Decode_u_law_2_linear:(Byte)b {
|
||||
// NSLog(@"444G711Decode_u_law_2_linear");
|
||||
//u律 8126
|
||||
short t;
|
||||
b = ~b;
|
||||
t = ((b&0xf)<<3)+0x84;
|
||||
t <<= ((unsigned)b&0x70)>>4;
|
||||
return ((b&0x80)?(0x84-t):(t-0x84));
|
||||
}
|
||||
|
||||
- (short)G711Decode_a_law_2_linear:(Byte)b {
|
||||
//a律 8300
|
||||
int t;
|
||||
int seg;
|
||||
b ^= 0x55;
|
||||
t = (b&0xf)<<4;
|
||||
seg = ((unsigned)b&0x70)>>4;//seg=((unsigned)b&0x70)>>4;
|
||||
switch (seg){
|
||||
case 0:{
|
||||
t += 8;
|
||||
}
|
||||
break;
|
||||
case 1:{
|
||||
t += 0x108;
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
t += 0x108;
|
||||
t <<= seg-1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ((b&0x80)?t:-t);
|
||||
}
|
||||
|
||||
- (void)audioQueueOutputWithQueue:(AudioQueueRef)q queueBuffer:(AudioQueueBufferRef)buf {
|
||||
// NSLog(@"222audioQueueOutputWithQueue: _AudiodecodeType = %d", _AudiodecodeType);
|
||||
if (_AudiodecodeType == k711) {
|
||||
buf->mAudioDataByteSize = BYTES_PER_SAMPLES;
|
||||
short *b = buf->mAudioData;
|
||||
if (Abuf_len>0) {
|
||||
//NSLog(@"8130 audio play ...");
|
||||
int pos = Abuf_p*64;
|
||||
for (int i=0; i<BYTES_PER_SAMPLES/2; i++) {
|
||||
b[i] = [self G711Decode_u_law_2_linear:Abuf[pos+i]];
|
||||
|
||||
}
|
||||
Abuf_len --;
|
||||
Abuf_p=(Abuf_p+1)%100;
|
||||
|
||||
}
|
||||
else {
|
||||
for (int i=0; i<BYTES_PER_SAMPLES/2; i++) {
|
||||
b[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isAudioStop == NO && (!app.TalkSendAudio) ) {//因为在停止播放的过程中,buffer_callback还在被调用
|
||||
int ret = AudioQueueEnqueueBuffer(q, buf, 0, NULL);
|
||||
if (ret) {
|
||||
NSLog(@"enqueue error:%d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)AudioPlayStartWithMode:(int)mod {
|
||||
// NSLog(@"111AudioPlayStartWithMode mod = %d", mod);
|
||||
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
int channels = 1;//default 1
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
isAudioStop = NO;
|
||||
|
||||
_AudiodecodeType = k711;
|
||||
Abuf = malloc(64*ABUF_NUM);
|
||||
BYTES_PER_SAMPLES = 64 * 2 * channels;
|
||||
|
||||
|
||||
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mSampleRate = SAMPLE_RATE;
|
||||
dataformat.mBitsPerChannel = 16;
|
||||
dataformat.mChannelsPerFrame = 1;
|
||||
dataformat.mFramesPerPacket = 1;
|
||||
dataformat.mBytesPerFrame = (dataformat.mBitsPerChannel / 8) * dataformat.mChannelsPerFrame;
|
||||
dataformat.mBytesPerPacket = dataformat.mBytesPerFrame * dataformat.mFramesPerPacket;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||
|
||||
AudioQueueNewOutput(&dataformat, buffer_callback, (__bridge void *)(self), NULL, kCFRunLoopCommonModes, 0, &queue);
|
||||
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, 1.0);
|
||||
|
||||
unsigned int err;
|
||||
for (int i=0; i<NUM_BUFFERS; i++) {
|
||||
err = AudioQueueAllocateBuffer(queue, BYTES_PER_SAMPLES, &buffers[i]);
|
||||
|
||||
|
||||
[self audioQueueOutputWithQueue:queue queueBuffer:buffers[i]];
|
||||
}
|
||||
|
||||
AudioQueueStart(queue, NULL);
|
||||
|
||||
}
|
||||
|
||||
- (int)AudioStartWithRate:(int)rate setChannels:(int)channels setSamples:(int)samples setBuf_samples:(int)buf_samples setVersion:(int)v {
|
||||
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
|
||||
//added by huangkanghui at 2016.05.25
|
||||
//Version = 8130;
|
||||
_AudiodecodeType = kIsac;
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
//Abuf = malloc(64*ABUF_NUM);
|
||||
Abuf = malloc(160*ABUF_NUM);
|
||||
|
||||
BYTES_PER_SAMPLES = buf_samples * 2 * channels;
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mSampleRate = 8000;//16000;//rate;//8000.0;
|
||||
dataformat.mBitsPerChannel = 16;
|
||||
dataformat.mChannelsPerFrame = 1;
|
||||
dataformat.mFramesPerPacket = 1;
|
||||
dataformat.mBytesPerFrame = (dataformat.mBitsPerChannel / 8) * dataformat.mChannelsPerFrame;
|
||||
dataformat.mBytesPerPacket = dataformat.mBytesPerFrame * dataformat.mFramesPerPacket;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||
/*BYTES_PER_SAMPLES = buf_samples * 2 * channels;
|
||||
|
||||
dataformat.mSampleRate = rate;
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||
dataformat.mBytesPerPacket = BYTES_PER_SAMPLES;
|
||||
dataformat.mFramesPerPacket = buf_samples;
|
||||
dataformat.mBytesPerFrame = 2*channels;
|
||||
dataformat.mChannelsPerFrame = channels;
|
||||
dataformat.mBitsPerChannel = 16; */
|
||||
NSLog(@"aoutinit1:%d:%d:%d:%d", rate, channels, samples, buf_samples);
|
||||
|
||||
unsigned int err = AudioQueueNewOutput(&dataformat, buffer_callback, (__bridge void *)(self), NULL, kCFRunLoopCommonModes, 0, &queue);
|
||||
if (err) {
|
||||
//NSLog(@"AudioQueueNewOutput error");
|
||||
return -1;
|
||||
}
|
||||
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, 1.0);
|
||||
|
||||
int i;
|
||||
for (i=0; i<NUM_BUFFERS; i++) {
|
||||
//err = AudioQueueAllocateBuffer(queue, BYTES_PER_SAMPLES, &buffers[i]);
|
||||
err = AudioQueueAllocateBuffer(queue, WEBRTC_AUDIO_BUF_SIZE, &buffers[i]);
|
||||
if (err) {
|
||||
return -2;
|
||||
}
|
||||
[self audioQueueOutputWithQueue:queue queueBuffer:buffers[i]];
|
||||
}
|
||||
|
||||
AudioQueueStart(queue, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void)setVolume:(float)v {
|
||||
NSLog(@"setv:%.2f", v);
|
||||
//vol=v;
|
||||
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, (int)v);
|
||||
}
|
||||
|
||||
- (void)AudioEnd {
|
||||
//unsigned int err = AudioQueueStop(queue, NULL);
|
||||
isAudioStop = YES;
|
||||
unsigned int err = AudioQueueStop(queue, TRUE);
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
for (NSInteger i = 0; i < NUM_BUFFERS; i++) {
|
||||
AudioQueueFreeBuffer(queue, buffers[i]);
|
||||
}
|
||||
AudioQueueDispose(queue, TRUE);
|
||||
free(Abuf);
|
||||
if(err){
|
||||
NSLog(@"AudioQueue1End error");
|
||||
}
|
||||
//NSLog(@"playAudioEnd ...");
|
||||
}
|
||||
|
||||
+ (void)initAudioSession {
|
||||
//AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void *)(self));
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
||||
|
||||
NSError *err;
|
||||
[[AVAudioSession sharedInstance] setActive:TRUE error:&err];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@ -1,54 +0,0 @@
|
||||
//
|
||||
// recordAudio.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-11-22.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
//#import <AudioUnit/AudioUnit.h>//kAudioUnitSubType
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AudioToolbox/AudioQueue.h>
|
||||
#import <AudioToolbox/AudioServices.h>
|
||||
#import <CoreAudio/CoreAudioTypes.h>
|
||||
//#import "smbPitchShift.h"
|
||||
|
||||
|
||||
#define NUM_BUFFERS 10
|
||||
#define ABUF_NUM 100
|
||||
#define RECORD_SIZE (160)
|
||||
#define RECORD_ISAC_SIZE (240)
|
||||
#define RECORD_FRAME_BUF (320)
|
||||
#define RECORD_SAMPLES (160)
|
||||
|
||||
/*
|
||||
typedef NS_ENUM(NSInteger, AudioEncodeType) {
|
||||
k8126,
|
||||
k8130,
|
||||
k711,
|
||||
k722,
|
||||
kIsac
|
||||
};
|
||||
*/
|
||||
@interface recordAudio : NSObject{
|
||||
AudioQueueRef queue;
|
||||
AudioQueueBufferRef buffers[NUM_BUFFERS];
|
||||
AudioStreamBasicDescription dataformat;
|
||||
AudioQueueLevelMeterState *levels;
|
||||
}
|
||||
|
||||
@property Byte *Abuf;
|
||||
@property int Abuf_p;
|
||||
@property int Abuf_len;
|
||||
@property int Version;
|
||||
@property int firstopen;
|
||||
@property int AudioEncodeType;
|
||||
@property int EuqAudioType;
|
||||
//@property (nonatomic, strong) webrtc_audio_processing* audio_process;
|
||||
|
||||
//- (void)AudioRecordStart;
|
||||
- (int)AudioRecordStartWithMode:(int)mod;
|
||||
- (void)AudioEnd;
|
||||
- (int)AudioStartWithRate:(int)rate setChannels:(int)channels setSamples:(int)samples setBuf_samples:(int)buf_samples setVersion:(int)v;
|
||||
- (void)audioQueueInputWithQueue:(AudioQueueRef)q queueBuffer:(AudioQueueBufferRef)buf;
|
||||
|
||||
@end
|
||||
@ -1,763 +0,0 @@
|
||||
//
|
||||
// playAudio.m
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-11-20.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "recordAudio.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#define SAMPLE_RATE (8000)
|
||||
|
||||
@implementation recordAudio{
|
||||
AppDelegate * app;
|
||||
}
|
||||
|
||||
@synthesize Abuf;
|
||||
@synthesize Abuf_p;
|
||||
@synthesize Abuf_len;
|
||||
@synthesize firstopen;
|
||||
@synthesize Version;
|
||||
static int BYTES_PER_SAMPLES;
|
||||
static bool isRecordAudioStop;
|
||||
|
||||
uint8_t encodeBuff[RECORD_FRAME_BUF*2];
|
||||
|
||||
AudioUnit *audioUnit = NULL;
|
||||
AudioUnit _auVoiceProcessing;
|
||||
|
||||
SInt16 captureBuff[240];
|
||||
// The sampling rate to use with Audio Device Buffer
|
||||
uint32_t _adbSampFreq;
|
||||
|
||||
static short seg_end[8] = {0xff, 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff};
|
||||
static short search(short val, short *table, short size) {
|
||||
short i;
|
||||
for (i=0; i<size; i++) {
|
||||
if(val<=*table++)
|
||||
return(i);
|
||||
}
|
||||
return(size);
|
||||
}
|
||||
|
||||
- (Byte)G711Encode_linear_2_u_law:(short)p {
|
||||
//u律 8126
|
||||
//NSLog(@"p=%d",p);
|
||||
short mask;
|
||||
short seg;
|
||||
Byte uval;
|
||||
if (p<0) {
|
||||
p = 0x84-p;
|
||||
mask = 0x7f;
|
||||
} else {
|
||||
p += 0x84;
|
||||
mask = 0xff;
|
||||
}
|
||||
seg = search(p, seg_end, 8);
|
||||
if (seg>=8) {
|
||||
//NSLog(@"a%d",0x7f^mask);
|
||||
return(0x7f^mask);
|
||||
} else {
|
||||
uval=(seg<<4)|((p>>(seg+3))&0xf);
|
||||
//NSLog(@"b%d",uval^mask);
|
||||
return(uval^mask);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (Byte)G711Encode_linear_2_a_law:(short)p {
|
||||
//a律 8130
|
||||
short mask;
|
||||
short seg;
|
||||
Byte aval;
|
||||
if (p>=0) {
|
||||
mask = 0xD5;
|
||||
} else {
|
||||
mask = 0x55;
|
||||
p = (short)(-p-1);
|
||||
if(p<0) p = 32767;
|
||||
}
|
||||
|
||||
seg = search(p,seg_end,(short)8);
|
||||
if (seg>=8) {
|
||||
//NSLog(@"a%d",0x7f^mask);
|
||||
return(0x7f^mask);
|
||||
} else {
|
||||
aval = seg<<4;
|
||||
if(seg<2)
|
||||
aval |= (p>>4)&0xf;
|
||||
else
|
||||
aval |= (p>>(seg+3))&0xf;
|
||||
return(aval^mask);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Buffer_callback(void *inUserData, AudioQueueRef q, AudioQueueBufferRef buf, const AudioTimeStamp *inStartTime, UInt32 inNumPackets, const AudioStreamPacketDescription *inPacketDesc) {
|
||||
//NSLog(@"Buffer_callback:%d, %d, %d, %d", inStartTime->mSampleTime, inStartTime->mRateScalar, inStartTime->mHostTime, inNumPackets);
|
||||
recordAudio* player = (__bridge recordAudio*)inUserData;
|
||||
[player audioQueueInputWithQueue:q queueBuffer:buf];
|
||||
}
|
||||
|
||||
- (void)audioQueueInputWithQueue:(AudioQueueRef)q queueBuffer:(AudioQueueBufferRef)buf {
|
||||
if (isRecordAudioStop == YES) {//操作停止录音后,还会继续回调 所以在停止过程中不执行
|
||||
return;
|
||||
}
|
||||
//NSLog(@"record Buffer_callback");
|
||||
short *b = buf->mAudioData;
|
||||
|
||||
if (Abuf_len<ABUF_NUM) {
|
||||
int pp = (Abuf_p+Abuf_len)%ABUF_NUM;
|
||||
Abuf_len ++;
|
||||
for(int i=0; i<BYTES_PER_SAMPLES/2; i++) {
|
||||
Abuf[64*pp+i] = [self G711Encode_linear_2_u_law:b[i]];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AudioQueueEnqueueBuffer(q, buf, 0, NULL);
|
||||
}
|
||||
|
||||
static void interruptionListener(void * inClientData,
|
||||
UInt32 inInterruptionState)
|
||||
{
|
||||
// 声音中断通知(BEGIN,END)
|
||||
}
|
||||
|
||||
- (void)initAudioSession {
|
||||
//This function has to be called once before calling any other AudioSession functions
|
||||
OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void *)(self));
|
||||
if (error) printf("ERROR INITIALIZING AUDIO SESSION! %d\n", (int)error);
|
||||
else {
|
||||
UInt32 category = kAudioSessionCategory_PlayAndRecord;
|
||||
error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
|
||||
if (error) printf("couldn't set audio category!");
|
||||
|
||||
error = AudioSessionSetActive(true);
|
||||
if (error) printf("AudioSessionSetActive (true) failed");
|
||||
}
|
||||
}
|
||||
|
||||
- (int)AudioRecordStartWithMode:(int)mod {
|
||||
NSLog(@"AudioRecordStartWithMode");
|
||||
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
isRecordAudioStop = NO;
|
||||
|
||||
|
||||
|
||||
|
||||
memset(&dataformat, 0, sizeof(dataformat));
|
||||
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
int channels = 1;
|
||||
Abuf = malloc(64*ABUF_NUM);// malloc(64*ABUF_NUM);
|
||||
BYTES_PER_SAMPLES = 64 * 2 *channels;//buf_samples * 2 * channels;
|
||||
|
||||
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mSampleRate = 8000;//rate;//8000.0;
|
||||
dataformat.mBitsPerChannel = 16;//8;
|
||||
dataformat.mChannelsPerFrame = 1;
|
||||
dataformat.mFramesPerPacket = 1;
|
||||
dataformat.mBytesPerFrame = (dataformat.mBitsPerChannel / 8) * dataformat.mChannelsPerFrame;
|
||||
dataformat.mBytesPerPacket = dataformat.mBytesPerFrame * dataformat.mFramesPerPacket;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||
|
||||
|
||||
unsigned int err;
|
||||
err = AudioQueueNewInput(&dataformat, Buffer_callback, (__bridge void *)(self), NULL, NULL, 0, &queue);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueNewInput2 error:%d",err);
|
||||
return -1;
|
||||
}
|
||||
NSLog(@"4");
|
||||
//软件解码
|
||||
UInt32 val = kAudioQueueHardwareCodecPolicy_PreferSoftware;
|
||||
OSStatus ignorableError;
|
||||
ignorableError = AudioQueueSetProperty(queue, kAudioQueueProperty_HardwareCodecPolicy, &val, sizeof(UInt32));
|
||||
if (ignorableError)
|
||||
{
|
||||
NSLog(@"set software codec error:%d", ignorableError);
|
||||
}
|
||||
NSLog(@"5");
|
||||
for (int i=0; i<NUM_BUFFERS; i++) {
|
||||
err = AudioQueueAllocateBuffer(queue, BYTES_PER_SAMPLES, &buffers[i]);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueAllcateBuffer error");
|
||||
return -2;
|
||||
}
|
||||
AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL);
|
||||
}
|
||||
//for (int i=0; i<NUM_BUFFERS; i++) {
|
||||
//makeSilent(buffers[i]);
|
||||
|
||||
//}
|
||||
|
||||
|
||||
AudioQueueParameterValue gain = 1;
|
||||
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, gain);
|
||||
|
||||
NSLog(@"6");
|
||||
err = AudioQueueStart(queue, NULL);
|
||||
|
||||
NSLog(@"7");
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueStart error");
|
||||
return -3;
|
||||
} else {
|
||||
NSLog(@"AudioQueueStart");
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
- (int)AudioStartWithRate:(int)rate setChannels:(int)channels setSamples:(int)samples setBuf_samples:(int)buf_samples setVersion:(int)v {
|
||||
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
//[_audio_process WebRtcProcess_Init];
|
||||
#if 1
|
||||
|
||||
memset(&dataformat, 0, sizeof(dataformat));
|
||||
/*UInt32 size = sizeof(dataformat.mSampleRate);
|
||||
AudioSessionGetProperty( kAudioSessionProperty_CurrentHardwareSampleRate,
|
||||
&size,
|
||||
&dataformat.mSampleRate);
|
||||
|
||||
size = sizeof(dataformat.mChannelsPerFrame);
|
||||
AudioSessionGetProperty( kAudioSessionProperty_CurrentHardwareInputNumberChannels,
|
||||
&size,
|
||||
&dataformat.mChannelsPerFrame);
|
||||
*/
|
||||
//[self initAudioSession];
|
||||
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
Abuf = malloc(64*ABUF_NUM);// malloc(64*ABUF_NUM);
|
||||
BYTES_PER_SAMPLES = 4*64 * 2 *channels;//buf_samples * 2 * channels;
|
||||
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mSampleRate = 8000;//rate;//8000.0;
|
||||
dataformat.mBitsPerChannel = 16;//8;
|
||||
dataformat.mChannelsPerFrame = 1;
|
||||
dataformat.mFramesPerPacket = 1;
|
||||
dataformat.mBytesPerFrame = (dataformat.mBitsPerChannel / 8) * dataformat.mChannelsPerFrame;
|
||||
dataformat.mBytesPerPacket = dataformat.mBytesPerFrame * dataformat.mFramesPerPacket;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||
/*dataformat.mSampleRate = rate;
|
||||
dataformat.mFormatID = kAudioFormatLinearPCM;
|
||||
dataformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||
dataformat.mBytesPerPacket = BYTES_PER_SAMPLES;
|
||||
dataformat.mFramesPerPacket = buf_samples;
|
||||
dataformat.mBytesPerFrame = 2*channels;
|
||||
dataformat.mChannelsPerFrame = channels;
|
||||
dataformat.mBitsPerChannel = 16; */
|
||||
|
||||
NSLog(@"aoutinit:%d:%d:%d:%d", rate, channels, samples, buf_samples);
|
||||
unsigned int err;
|
||||
err = AudioQueueNewInput(&dataformat, Buffer_callback, (__bridge void *)(self), NULL, NULL, 0, &queue);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueNewInput2 error:%d",err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_BUFFERS; i++) {
|
||||
//AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL);
|
||||
err = AudioQueueAllocateBuffer(queue, RECORD_FRAME_BUF, &buffers[i]);//320+160 16000 320000/480 =66.67 320/100 30 480 10*2= 160*3=480 1
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueAllcateBuffer error");
|
||||
return -2;
|
||||
}
|
||||
|
||||
}
|
||||
for (int i=0; i<NUM_BUFFERS; i++) {
|
||||
makeSilent(buffers[i]);
|
||||
AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL);
|
||||
}
|
||||
|
||||
AudioQueueParameterValue gain = 1;
|
||||
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, gain);
|
||||
//AudioQueueStart(queue, NULL);
|
||||
err = AudioQueueStart(queue, NULL);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueStart error");
|
||||
return -3;
|
||||
} else {
|
||||
NSLog(@"AudioQueueStart");
|
||||
}
|
||||
NSLog(@"aoutinit:%d:%d:%d:%d", rate, channels, samples, buf_samples);
|
||||
return 0;
|
||||
/*[self setupFormat];
|
||||
[self setupBuffers];
|
||||
AudioQueueNewInput(&dataformat, Buffer_callback, self, NULL, NULL, 0, &queue);
|
||||
[self setupMetering];
|
||||
return 0;*/
|
||||
#else
|
||||
//initAudioSession();
|
||||
initAudioStreams(audioUnit);
|
||||
//startAudioUnit(audioUnit);
|
||||
#endif
|
||||
}
|
||||
|
||||
//把缓冲区置空
|
||||
static void makeSilent(AudioQueueBufferRef buffer)
|
||||
{
|
||||
for (int i=0; i < buffer->mAudioDataBytesCapacity; i++) {
|
||||
buffer->mAudioDataByteSize = buffer->mAudioDataBytesCapacity;
|
||||
UInt8 *samples = (UInt8 *)buffer->mAudioData;
|
||||
samples[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupBuffers {
|
||||
for (NSInteger i = 0; i < NUM_BUFFERS; i++) {
|
||||
//AudioQueueAllocateBuffer(queue, 735, &buffers[i]);
|
||||
//AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL);
|
||||
int err = AudioQueueAllocateBuffer(queue, BYTES_PER_SAMPLES, &buffers[i]);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueueAllcateBuffer error:%d",err);
|
||||
return ;
|
||||
}
|
||||
[self audioQueueInputWithQueue:queue queueBuffer:buffers[i]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupMetering {
|
||||
levels = (AudioQueueLevelMeterState *)calloc(sizeof(AudioQueueLevelMeterState), dataformat.mChannelsPerFrame);
|
||||
UInt32 trueValue = true;
|
||||
AudioQueueSetProperty(queue, kAudioQueueProperty_EnableLevelMetering, &trueValue, sizeof(UInt32));
|
||||
}
|
||||
|
||||
- (void)AudioEnd {
|
||||
|
||||
NSLog(@"AudioEnd ...");
|
||||
Abuf_p = 0;
|
||||
Abuf_len = 0;
|
||||
//unsigned int err = AudioQueueStop(queue, NULL); //什么为null就不崩溃呢?
|
||||
isRecordAudioStop = YES;
|
||||
unsigned int err = AudioQueueStop(queue, TRUE);
|
||||
for (NSInteger i = 0; i < NUM_BUFFERS; i++) {
|
||||
AudioQueueFreeBuffer(queue, buffers[i]);
|
||||
}
|
||||
AudioQueueDispose(queue, TRUE);
|
||||
free(Abuf);
|
||||
if (err) {
|
||||
NSLog(@"AudioQueue2End error");
|
||||
}
|
||||
//[_audio_process WebRtcProcess_Free];
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================================================================
|
||||
//以下属于底层,没事不要乱动
|
||||
int initAudioSession() {
|
||||
audioUnit = (AudioUnit*)malloc(sizeof(AudioUnit));
|
||||
|
||||
if(AudioSessionInitialize(NULL, NULL, NULL, NULL) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(AudioSessionSetActive(true) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
|
||||
if(AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
|
||||
sizeof(UInt32), &sessionCategory) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Float32 bufferSizeInSec = 0.02f;
|
||||
if(AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration,
|
||||
sizeof(Float32), &bufferSizeInSec) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
UInt32 overrideCategory = 1;
|
||||
if(AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
|
||||
sizeof(UInt32), &overrideCategory) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// There are many properties you might want to provide callback functions for:
|
||||
// kAudioSessionProperty_AudioRouteChange
|
||||
// kAudioSessionProperty_OverrideCategoryEnableBluetoothInput
|
||||
// etc.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)initAudioStreams {
|
||||
//return initAudioStreams(NULL);
|
||||
initAudioSession();
|
||||
initAudioStreams(audioUnit);
|
||||
startAudioUnit(audioUnit);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
int initAudioStreams(AudioUnit *audioUnit) {
|
||||
#if 1
|
||||
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
|
||||
if(AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
|
||||
sizeof(UInt32), &audioCategory) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
UInt32 overrideCategory = 1;
|
||||
if(AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
|
||||
sizeof(UInt32), &overrideCategory) != noErr) {
|
||||
// Less serious error, but you may want to handle it and bail here
|
||||
}
|
||||
|
||||
AudioComponentDescription componentDescription;
|
||||
componentDescription.componentType = kAudioUnitType_Output;
|
||||
componentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
|
||||
componentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
componentDescription.componentFlags = 0;
|
||||
componentDescription.componentFlagsMask = 0;
|
||||
AudioComponent component = AudioComponentFindNext(NULL, &componentDescription);
|
||||
if(AudioComponentInstanceNew(component, audioUnit) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
UInt32 enable = 1;
|
||||
if(AudioUnitSetProperty(*audioUnit, kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input, 1, &enable, sizeof(UInt32)) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
AURenderCallbackStruct callbackStruct;
|
||||
callbackStruct.inputProc = renderCallback; // Render function
|
||||
callbackStruct.inputProcRefCon = NULL;
|
||||
if(AudioUnitSetProperty(*audioUnit, kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Input, 0, &callbackStruct,
|
||||
sizeof(AURenderCallbackStruct)) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioStreamBasicDescription streamDescription;
|
||||
// You might want to replace this with a different value, but keep in mind that the
|
||||
// iPhone does not support all sample rates. 8kHz, 22kHz, and 44.1kHz should all work.
|
||||
streamDescription.mSampleRate = 16000;//44100;
|
||||
// Yes, I know you probably want floating point samples, but the iPhone isn't going
|
||||
// to give you floating point data. You'll need to make the conversion by hand from
|
||||
// linear PCM <-> float.
|
||||
streamDescription.mFormatID = kAudioFormatLinearPCM;
|
||||
// This part is important!
|
||||
streamDescription.mFormatFlags = kAudioFormatFlagIsSignedInteger |
|
||||
kAudioFormatFlagsNativeEndian |
|
||||
kAudioFormatFlagIsPacked;
|
||||
// Not sure if the iPhone supports recording >16-bit audio, but I doubt it.
|
||||
streamDescription.mBitsPerChannel = 16;
|
||||
// 1 sample per frame, will always be 2 as long as 16-bit samples are being used
|
||||
streamDescription.mBytesPerFrame = 2;
|
||||
// Record in mono. Use 2 for stereo, though I don't think the iPhone does true stereo recording
|
||||
streamDescription.mChannelsPerFrame = 1;
|
||||
streamDescription.mBytesPerPacket = streamDescription.mBytesPerFrame *
|
||||
streamDescription.mChannelsPerFrame;
|
||||
// Always should be set to 1
|
||||
streamDescription.mFramesPerPacket = 1;
|
||||
// Always set to 0, just to be sure
|
||||
streamDescription.mReserved = 0;
|
||||
|
||||
// Set up input stream with above properties
|
||||
|
||||
if(AudioUnitSetProperty(*audioUnit, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &streamDescription, sizeof(streamDescription)) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Ditto for the output stream, which we will be sending the processed audio to
|
||||
|
||||
if(AudioUnitSetProperty(*audioUnit, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Output, 1, &streamDescription, sizeof(streamDescription)) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
OSStatus result = -1;
|
||||
|
||||
// Create Voice Processing Audio Unit
|
||||
AudioComponentDescription desc;
|
||||
AudioComponent comp;
|
||||
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
|
||||
comp = AudioComponentFindNext(NULL, &desc);
|
||||
if (NULL == comp) {
|
||||
NSLog(@"Could not find audio component for Audio Unit");
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = AudioComponentInstanceNew(comp, &_auVoiceProcessing);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not create Audio Unit instance (result=%d)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set preferred hardware sample rate to 16 kHz
|
||||
NSError* error = nil;
|
||||
AVAudioSession* session = [AVAudioSession sharedInstance];
|
||||
Float64 preferredSampleRate = 16000.0;
|
||||
[session setPreferredSampleRate:preferredSampleRate
|
||||
error:&error];
|
||||
if (error != nil) {
|
||||
const char* errorString = [[error localizedDescription] UTF8String];
|
||||
NSLog(@"Could not set preferred sample rate: %s", errorString);
|
||||
}
|
||||
error = nil;
|
||||
error = nil;
|
||||
// Make the setMode:error: and setCategory:error: calls only if necessary.
|
||||
// Non-obviously, setting them to the value they already have will clear
|
||||
// transient properties (such as PortOverride) that some other component may
|
||||
// have set up.
|
||||
if (session.mode != AVAudioSessionModeVoiceChat) {
|
||||
[session setMode:AVAudioSessionModeVoiceChat error:&error];
|
||||
if (error != nil) {
|
||||
const char* errorString = [[error localizedDescription] UTF8String];
|
||||
NSLog(@"Could not set mode: %s", errorString);
|
||||
}
|
||||
}
|
||||
error = nil;
|
||||
if (session.category != AVAudioSessionCategoryPlayAndRecord) {
|
||||
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
|
||||
if (error != nil) {
|
||||
const char* errorString = [[error localizedDescription] UTF8String];
|
||||
NSLog(@"Could not set category: %s", errorString);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Setup Voice Processing Audio Unit
|
||||
|
||||
// Note: For Signal Processing AU element 0 is output bus, element 1 is
|
||||
// input bus for global scope element is irrelevant (always use
|
||||
// element 0)
|
||||
|
||||
// Enable IO on both elements
|
||||
|
||||
// todo: Below we just log and continue upon error. We might want
|
||||
// to close AU and return error for some cases.
|
||||
// todo: Log info about setup.
|
||||
|
||||
UInt32 enableIO = 1;
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input,
|
||||
1, // input bus
|
||||
&enableIO,
|
||||
sizeof(enableIO));
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not enable IO on input (result=%d)", result);
|
||||
}
|
||||
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Output,
|
||||
0, // output bus
|
||||
&enableIO,
|
||||
sizeof(enableIO));
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not enable IO on output (result=%d)", (int)result);
|
||||
}
|
||||
|
||||
// Disable AU buffer allocation for the recorder, we allocate our own
|
||||
UInt32 flag = 0;
|
||||
result = AudioUnitSetProperty(
|
||||
_auVoiceProcessing, kAudioUnitProperty_ShouldAllocateBuffer,
|
||||
kAudioUnitScope_Output, 1, &flag, sizeof(flag));
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not disable AU buffer allocation (result=%d)", result);
|
||||
// Should work anyway
|
||||
}
|
||||
|
||||
// Set recording callback
|
||||
AURenderCallbackStruct auCbS;
|
||||
memset(&auCbS, 0, sizeof(auCbS));
|
||||
auCbS.inputProc = renderCallback;
|
||||
auCbS.inputProcRefCon = NULL;//this;
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioOutputUnitProperty_SetInputCallback,
|
||||
kAudioUnitScope_Global, 1,
|
||||
&auCbS, sizeof(auCbS));
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not set record callback for Audio Unit (result=%d)",result);
|
||||
}
|
||||
|
||||
// Set playout callback
|
||||
memset(&auCbS, 0, sizeof(auCbS));
|
||||
auCbS.inputProc = PlayoutProcess;
|
||||
auCbS.inputProcRefCon = NULL;//this;
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&auCbS, sizeof(auCbS));
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not set play callback for Audio Unit (result=%d)", result);
|
||||
}
|
||||
|
||||
// Get stream format for out/0
|
||||
AudioStreamBasicDescription playoutDesc;
|
||||
UInt32 size = sizeof(playoutDesc);
|
||||
result = AudioUnitGetProperty(_auVoiceProcessing,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Output, 0, &playoutDesc,
|
||||
&size);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not get stream format Audio Unit out/0 (result=%d)", result);
|
||||
}
|
||||
NSLog(@"Audio Unit playout opened in sampling rate %f", playoutDesc.mSampleRate);
|
||||
|
||||
playoutDesc.mSampleRate = preferredSampleRate;
|
||||
|
||||
_adbSampFreq = 16000;
|
||||
// Set the audio device buffer sampling rate,
|
||||
// we assume we get the same for play and record
|
||||
//暂时不
|
||||
// Set stream format for in/0 (use same sampling frequency as for out/0)
|
||||
playoutDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger
|
||||
| kLinearPCMFormatFlagIsPacked
|
||||
| kLinearPCMFormatFlagIsNonInterleaved;
|
||||
playoutDesc.mBytesPerPacket = 2;
|
||||
playoutDesc.mFramesPerPacket = 1;
|
||||
playoutDesc.mBytesPerFrame = 2;
|
||||
playoutDesc.mChannelsPerFrame = 1;
|
||||
playoutDesc.mBitsPerChannel = 16;
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &playoutDesc, size);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not set stream format Audio Unit in/0 (result=%d)", result);
|
||||
}
|
||||
|
||||
// Get stream format for in/1
|
||||
AudioStreamBasicDescription recordingDesc;
|
||||
size = sizeof(recordingDesc);
|
||||
result = AudioUnitGetProperty(_auVoiceProcessing,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 1, &recordingDesc,
|
||||
&size);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not get stream format Audio Unit in/1 (result=%d)", result);
|
||||
}
|
||||
NSLog(@"Audio Unit recording opened in sampling rate %f", recordingDesc.mSampleRate);
|
||||
|
||||
recordingDesc.mSampleRate = preferredSampleRate;
|
||||
|
||||
// Set stream format for out/1 (use same sampling frequency as for in/1)
|
||||
recordingDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger
|
||||
| kLinearPCMFormatFlagIsPacked
|
||||
| kLinearPCMFormatFlagIsNonInterleaved;
|
||||
|
||||
recordingDesc.mBytesPerPacket = 2;
|
||||
recordingDesc.mFramesPerPacket = 1;
|
||||
recordingDesc.mBytesPerFrame = 2;
|
||||
recordingDesc.mChannelsPerFrame = 1;
|
||||
recordingDesc.mBitsPerChannel = 16;
|
||||
result = AudioUnitSetProperty(_auVoiceProcessing,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Output, 1, &recordingDesc,
|
||||
size);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not set stream format Audio Unit out/1 (result=%d)", result);
|
||||
}
|
||||
|
||||
// Initialize here already to be able to get/set stream properties.
|
||||
result = AudioUnitInitialize(_auVoiceProcessing);
|
||||
if (0 != result) {
|
||||
NSLog(@"Could not init Audio Unit (result=%d)", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int startAudioUnit(AudioUnit *audioUnit) {
|
||||
if(AudioUnitInitialize(*audioUnit) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(AudioOutputUnitStart(*audioUnit) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
OSStatus renderCallback(void *userData, AudioUnitRenderActionFlags *actionFlags,
|
||||
const AudioTimeStamp *audioTimeStamp, UInt32 busNumber,
|
||||
UInt32 numFrames, AudioBufferList *buffers) {
|
||||
|
||||
// Get data from mic
|
||||
OSStatus status = AudioUnitRender(*audioUnit, actionFlags, audioTimeStamp,
|
||||
1, numFrames, buffers);
|
||||
if(status != noErr) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//if(convertedSampleBuffer == NULL) {
|
||||
// Lazy initialization of this buffer is necessary because we don't
|
||||
// know the frame count until the first callback
|
||||
//convertedSampleBuffer = (float*)malloc(sizeof(float) * numFrames);
|
||||
//}
|
||||
|
||||
SInt16 *inputFrames = (SInt16*)(buffers->mBuffers->mData);
|
||||
|
||||
// If your DSP code can use integers, then don't bother converting to
|
||||
// floats here, as it just wastes CPU. However, most DSP algorithms rely
|
||||
// on floating point, and this is especially true if you are porting a
|
||||
// VST/AU to iOS.
|
||||
for(int i = 0; i < numFrames; i++) {
|
||||
// convertedSampleBuffer[i] = (float)inputFrames[i] / 32768.0f;
|
||||
}
|
||||
|
||||
// Now we have floating point sample data from the render callback! We
|
||||
// can send it along for further processing, for example:
|
||||
// plugin->processReplacing(convertedSampleBuffer, NULL, sampleFrames);
|
||||
|
||||
// Assuming that you have processed in place, we can now write the
|
||||
// floating point data back to the input buffer.
|
||||
for(int i = 0; i < numFrames; i++) {
|
||||
// Note that we multiply by 32767 here, NOT 32768. This is to avoid
|
||||
// overflow errors (and thus clipping).
|
||||
//inputFrames[i] = (SInt16)(convertedSampleBuffer[i] * 32767.0f);
|
||||
}
|
||||
|
||||
NSLog(@"renderCallback numFrames = %d", (unsigned int)numFrames);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
OSStatus PlayoutProcess(void *inRefCon,
|
||||
AudioUnitRenderActionFlags *ioActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber,
|
||||
UInt32 inNumberFrames,
|
||||
AudioBufferList *ioData) {
|
||||
//AudioDeviceIOS* ptrThis = static_cast<AudioDeviceIOS*>(inRefCon);
|
||||
|
||||
//return ptrThis->PlayoutProcessImpl(inNumberFrames, ioData);
|
||||
NSLog(@"PlayoutProcess ...");
|
||||
return noErr;
|
||||
}
|
||||
|
||||
int stopProcessingAudio(AudioUnit *audioUnit) {
|
||||
if(AudioOutputUnitStop(*audioUnit) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(AudioUnitUninitialize(*audioUnit) != noErr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
*audioUnit = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@ -1,101 +0,0 @@
|
||||
//
|
||||
// talk_Class.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-11-15.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//#import "myPlayer.h"
|
||||
#import "playAudio.h"
|
||||
#import "recordAudio.h"
|
||||
#import "IframeInfo.h"
|
||||
//#import "recordAndplayAudio.h"
|
||||
//#import "g722_interface.h"
|
||||
|
||||
|
||||
#define ABUF_NUM 100
|
||||
#define POS_iframe_index 63
|
||||
#define POS_alen 65
|
||||
#define POS_blen 73
|
||||
#define POS_bag_index 71
|
||||
#define POS_bag_num 69
|
||||
#define POS_data 77
|
||||
#define FIRSTINDEX 1
|
||||
|
||||
|
||||
@interface talk_Class : NSObject{
|
||||
NSTimer *timer;
|
||||
NSData *connect_data;
|
||||
NSString *remoteEquid;
|
||||
NSString *remoteIp;
|
||||
int remotePort;
|
||||
IframeInfo *iframe;
|
||||
//NSString *groupIp;
|
||||
|
||||
//BOOL isShort;
|
||||
playAudio *audio;
|
||||
recordAudio *arecord;
|
||||
//recordAndplayAudio *recordAndPaly;
|
||||
//int status;//0:初始状态 1:等待监视 2:等待呼叫 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSString *groupIp;
|
||||
@property (nonatomic, retain) playAudio *audio;
|
||||
@property (nonatomic, retain) recordAudio *arecord;
|
||||
@property (nonatomic, retain) IframeInfo *iframe;
|
||||
@property int status;//0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中
|
||||
@property int Version;
|
||||
@property BOOL isShort;
|
||||
@property (nonatomic) int vedioCodecMode; //1: 8130 2: h264视频编码
|
||||
@property (nonatomic) int audioEquMode;
|
||||
@property (nonatomic) long connect_reg_time;
|
||||
@property (nonatomic) long talkOnTime;
|
||||
//@property BOOL isAudioInit;
|
||||
|
||||
- (void)status_ini;
|
||||
- (void)status_ini_onMain;
|
||||
|
||||
- (void)connect_rec;
|
||||
- (void)watch;
|
||||
- (void)watchByServer;
|
||||
- (void)watchSucc:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
- (void)watchEnd;
|
||||
- (void)talkOn;
|
||||
- (void)talkEnd;
|
||||
- (void)talkOnByRemote;
|
||||
- (void)getImgData:(Byte *)bb len:(int)l;
|
||||
- (void)getAVData:(Byte *)bb;
|
||||
- (void)getAVData:(Byte *)bb length:(int)blen;
|
||||
- (void)openDoor:(NSString *)pwd;
|
||||
- (void) showplayer;
|
||||
- (void)NSAsk:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;
|
||||
//-(void)RecvNSReply:(NSData *)data fromHost:(NSString *)host fromPort:(NSString *)port;
|
||||
//-(void)getdadong:(NSData *)data fromHost:(NSString *)host fromPort:(NSString *)port;
|
||||
- (void)RecvNSReply:(NSData *)data fromHost:(NSString *)host fromPort:(int)port;
|
||||
- (void)getdadong:(NSData *)data fromHost:(NSString *)host fromPort:(int)port;
|
||||
- (void)WatchCallAnswer:(NSData *)data fromHost:(NSString *)host;
|
||||
- (void)BeCall:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port;//收到呼叫
|
||||
- (void)talkOnRec:(Byte *)bb;
|
||||
- (void)NSToServer;
|
||||
//- (void)getH264AVData:(Byte *)bb length:(int)blen;
|
||||
- (void)getAVData:(Byte *)bb withLength:(unsigned long)blen;
|
||||
|
||||
- (void)audioStartWithMode:(int)mod;
|
||||
- (void)audioEnd;
|
||||
|
||||
- (BOOL)isVideoPlaying;
|
||||
- (NSString *)getRemoteEqu;
|
||||
- (void)SetRemoteEqu:(NSString *)equid;
|
||||
- (void)addHead:(NSString *)head toByte:(Byte *)bb;
|
||||
- (void)addEquid:(NSString *)equid addIp:(NSString *)ip toByte:(Byte *)bb at:(int)pos;
|
||||
- (NSString *)getIpv6FromBtye:(Byte *)bb At:(int)pos;
|
||||
- (NSString *)getIpFromBtye:(Byte *)bb At:(int)pos;
|
||||
- (int)getPortFromBtye:(Byte *)bb At:(int)pos;
|
||||
- (NSString *)getRemoteIp;
|
||||
- (void)SetRemoteIp:(NSString *)ip;
|
||||
- (int)getRemotePort;
|
||||
- (void)SetRemotePort:(int)port;
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,40 +0,0 @@
|
||||
//
|
||||
// udp_data_class.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-10-31.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "udp_data_class.h"
|
||||
#import "AsyncUdpSocket.h"
|
||||
#import "sysInfo.h"
|
||||
|
||||
#define BUFNUM 100
|
||||
|
||||
@interface UdpHelper : NSObject
|
||||
@property (nonatomic, retain)AsyncUdpSocket *udp;
|
||||
@property (nonatomic, retain) sysInfo* sysinfo;
|
||||
@property (nonatomic, retain)NSTimer *timer;
|
||||
//发送udp线程
|
||||
@property BOOL udp_send_tag;
|
||||
@property (nonatomic, retain)NSCondition *udp_send_Condition;
|
||||
@property (nonatomic, retain)NSCondition *udp_open_Condition;
|
||||
@property int udp_send_time;
|
||||
@property (nonatomic, retain)NSMutableArray *udp_datas;
|
||||
@property (nonatomic, retain)udp_data_class *udp_list;
|
||||
@property long udp_last_report_time;
|
||||
@property long udp_last_replay_time;
|
||||
@property BOOL online;
|
||||
|
||||
- (void)Open;
|
||||
- (void)Resume;
|
||||
- (void)sendDataInMain:(Byte *)rr length:(int)len toHost:(NSString *)host toPort:(int)port;
|
||||
- (void)senddataInThr:(NSData *)data toHost:(NSString *)host toPort:(int)port at:(int)second setTag:(int)tag;
|
||||
- (int)stopSend:(NSString *)host rr6:(int)r6 rr8:(int)r8;
|
||||
- (int)stopSend:(NSString *)host rr6:(int)r6 rr8:(int)r8 Port:(int)port;
|
||||
- (int)ChgSendIp:(NSString *)host rr6:(int)r6 rr8:(int)r8 Port:(int)port;
|
||||
- (int)stopSendDadong;
|
||||
@end
|
||||
@ -1,742 +0,0 @@
|
||||
//
|
||||
// udp_data_class.m
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-10-31.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UdpHelper.h"
|
||||
#import "Sformat.h"
|
||||
#import "Pub.h"
|
||||
#import "Msg.h"
|
||||
|
||||
@interface UdpHelper (){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@implementation UdpHelper{
|
||||
|
||||
}
|
||||
|
||||
- (void)Open{
|
||||
_sysinfo = [Pub getApp].sysinfo;
|
||||
_udp = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||
//NSError *err = nil;
|
||||
//[_udp bindToPort:8366 error:&err];
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
[self udp_send_thr_begin];
|
||||
_timer = [NSTimer scheduledTimerWithTimeInterval:1
|
||||
target:self selector:@selector(HeartBeat)
|
||||
userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)Resume{
|
||||
|
||||
_udp = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
}
|
||||
- (void)udp_send_thr_begin
|
||||
{
|
||||
_udp_datas = [[NSMutableArray alloc] init];
|
||||
udp_data_class *list;
|
||||
// _udp_list = [[udp_data_class alloc] init];
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
list = [[udp_data_class alloc] init];
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas addObject:list];
|
||||
}
|
||||
// 没有任何意义 只是为了条件无限循环
|
||||
_udp_send_tag = YES;
|
||||
// 记录子线程发送的次数
|
||||
_udp_send_time = 0;
|
||||
// 创建一个子线程
|
||||
[NSThread detachNewThreadSelector:@selector(udp_send_thr) toTarget:self withObject:nil];
|
||||
|
||||
}
|
||||
|
||||
//upd 线程
|
||||
- (void)udp_send_thr{
|
||||
while(_udp_send_tag){
|
||||
// 如果线程发送的次数小于等于0 不发送等待
|
||||
while (_udp_send_time <= 0) {
|
||||
@try
|
||||
{
|
||||
[_udp_send_Condition wait];
|
||||
sleep(1);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
}
|
||||
//[NSThread sleepForTimeInterval:0.01];
|
||||
//NSLog(@"线程等待");
|
||||
}
|
||||
[_udp_send_Condition lock];
|
||||
//事件
|
||||
// 有事件发送
|
||||
BOOL hasDataSend = YES;
|
||||
while (hasDataSend) {
|
||||
@try
|
||||
{
|
||||
// 如果有事件发送 立马改变状态
|
||||
hasDataSend = FALSE;
|
||||
// 遍历子线程 创建的队列里面的对象
|
||||
for(int i=0; i<BUFNUM; i++) {
|
||||
// 取到创建的队列里面的对象
|
||||
_udp_list = [_udp_datas objectAtIndex:i];
|
||||
//NSLog(@"send to i=%d, port = %d, _udp_datas.count = %lu", i, _udp_list.port, (unsigned long)_udp_datas.count);
|
||||
// isUsed为yes 说明有向服务器发送数据
|
||||
if (_udp_list.isUsed) {
|
||||
NSLog(@"hasDataSend:i=%d", i);
|
||||
//发送时间超时判断
|
||||
if(_udp_list.sendtimes < _udp_list.sendtimesneed) {
|
||||
hasDataSend = YES;
|
||||
_udp_list.sendtimes ++;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:_udp_list];
|
||||
[self performSelectorOnMainThread:@selector(sendDataInMain) withObject:nil waitUntilDone:YES];
|
||||
}
|
||||
else { //发送数据到服务器,超时 处理 无法连接
|
||||
_udp_list.sendtimes = 0;
|
||||
_udp_list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:_udp_list];
|
||||
|
||||
Byte *bb = (Byte *)[_udp_list.data bytes];
|
||||
switch (bb[6]) {
|
||||
|
||||
case 150:{//通话
|
||||
if(bb[8]==1) {
|
||||
|
||||
|
||||
}
|
||||
else if(bb[8]==10) {
|
||||
NSLog(@"开锁失败");
|
||||
[[Pub getApp] OpenDoorFail:[Pub getEquidFrombb:bb at:9]];
|
||||
}
|
||||
else if(bb[8]==30) {
|
||||
NSLog(@"停止通话失败");
|
||||
//[talk_class status_ini_onMain];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 152: {//监视
|
||||
if(bb[8]==1) {
|
||||
NSLog(@"监视失败");
|
||||
if([Pub getApp].callOut){
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
[[Pub getApp].callOut UIClose];
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
//在主页开锁
|
||||
[[Pub getApp] OpenDoorFail:[Pub getEquidFrombb:bb at:9]];
|
||||
}
|
||||
|
||||
}
|
||||
else if(bb[8]==10) {
|
||||
NSLog(@"开锁失败");
|
||||
[[Pub getApp] playSoundWith:SoundError];
|
||||
[[Pub getApp] OpenDoorFail:[Pub getEquidFrombb:bb at:9]];
|
||||
}
|
||||
else if(bb[8]==30) {
|
||||
NSLog(@"停止监视失败");
|
||||
//[talk_class status_ini_onMain];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
} @catch (NSException * e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//[self performSelectorOnMainThread:@selector(refData) withObject:nil waitUntilDone:YES];
|
||||
//事件完
|
||||
_udp_send_time--;
|
||||
[_udp_send_Condition unlock];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)HeartBeat{
|
||||
//NSLog(@"HeartBeat");
|
||||
if ((YES == [_udp isClosed]) ) {
|
||||
_udp = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||
//NSError *err = nil;
|
||||
//[_udp bindToPort:8366 error:&err];
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
@try
|
||||
{
|
||||
if (![_sysinfo.username isEqualToString:@""]) {
|
||||
if ([_sysinfo.token isEqualToString:@""]) return;
|
||||
//NSLog(@"%d,%ld,%d",_online,([Sformat timestamp]-_udp_last_report_time)/1000,sysinfo.reporttime);
|
||||
if (_online==NO || (([Sformat timestamp]-_udp_last_report_time)/1000 > _sysinfo.reporttime)) {//心跳包时间 如果没有收到_udp回应 则继续发
|
||||
_udp_last_report_time = [Sformat timestamp];
|
||||
Byte bb[110];
|
||||
/*
|
||||
memset(bb, 0, 101);
|
||||
[Pub addHead:@"XXXCID" toByte:bb];
|
||||
bb[6] = 4;
|
||||
bb[7] = 1;
|
||||
[Pub addEquid:@"P18682150237" toByte:bb at:8];
|
||||
// [Pub addEquid:_sysinfo.equid toByte:bb at:8];
|
||||
bb[20] = 0;
|
||||
[Pub addMac:[Pub getMac] toByte:bb at:28];
|
||||
[Pub addInt:0 toByte:bb at:34];
|
||||
[Pub addEquid:[Pub getLocalIP] toByte:bb at:38];
|
||||
//与协议区别
|
||||
[Pub addGKB:@"token" toByte:bb at:50];
|
||||
int len = [Pub addGKB:_sysinfo.token toByte:bb at:60];
|
||||
[Pub addInt:len toByte:bb at:43];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:60+len];
|
||||
|
||||
//NSLog(@"HeartBeat: length = %ld , %@", data.length, [Sformat Hex:data]);
|
||||
self.sysinfo.server_wan = @"192.168.254.23";//测试葛工地址
|
||||
self.sysinfo.server_port = 8366;
|
||||
NSLog(@"HeartBeat: 服务器=%@:%d; 本地端口 = %d ",self.sysinfo.server_wan,self.sysinfo.server_port, _udp.localPort);]
|
||||
*/
|
||||
memset(bb, 0, 101);
|
||||
[Pub addHead:@"XXXCID" toByte:bb];
|
||||
bb[6] = 4;
|
||||
bb[7] = 1;
|
||||
[Pub addEquid:@"P18682150237" toByte:bb at:8];
|
||||
// [Pub addEquid:_sysinfo.equid toByte:bb at:8];
|
||||
bb[20] = 0;
|
||||
[Pub addMac:@"02:00:00:00:00:00" toByte:bb at:28];
|
||||
// [Pub addMac:[Pub getMac] toByte:bb at:28];
|
||||
[Pub addInt:0 toByte:bb at:34];
|
||||
[Pub addEquid:@"192.168.9.7" toByte:bb at:38];
|
||||
// [Pub addEquid:[Pub getLocalIP] toByte:bb at:38];
|
||||
//与协议区别
|
||||
[Pub addGKB:@"token" toByte:bb at:50];
|
||||
int len = [Pub addGKB:@"b989fa15f75c2ac02718b7c9bb64f80e" toByte:bb at:60];
|
||||
// int len = [Pub addGKB:_sysinfo.token toByte:bb at:60];
|
||||
|
||||
[Pub addInt:len toByte:bb at:43];
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:60+len];
|
||||
|
||||
//打印数据
|
||||
NSMutableString *str = [[NSMutableString alloc] init];
|
||||
for (int i = 0; i < sizeof(bb); i++) {
|
||||
[str appendFormat:@"%@", [NSString stringWithFormat:@"%d ", bb[i]]];
|
||||
}
|
||||
NSLog(@"\n%@", str);
|
||||
|
||||
/*
|
||||
storeDataInByteArray(bb, @"XXXCID", 0);//包头
|
||||
storeDataInByteArray(bb, @(4), 6);//命令4
|
||||
storeDataInByteArray(bb, @(1), 7);//命令类型1
|
||||
storeDataInByteArray(bb, @"P18682150237", 8);//用户名
|
||||
storeDataInByteArray(bb, @(0), 20);
|
||||
storeDataInByteArray(bb, @(0), 28);//Mac地址
|
||||
storeDataInByteArray(bb, @"0.0.0.0", 38);//IP地址
|
||||
storeDataInByteArray(bb, @"token", 50);//Token
|
||||
storeDataInByteArray(bb, @"34237b42ae0ef7eb8fa6c1adf3ccfabb", 60);//Token值
|
||||
storeDataInByteArray(bb, @(32), 43);//Token值length
|
||||
|
||||
NSMutableString *str = [[NSMutableString alloc] init];
|
||||
for (int i = 0; i < sizeof(bb); i++) {
|
||||
[str appendFormat:@"%@", [NSString stringWithFormat:@"%d ", bb[i]]];
|
||||
}
|
||||
NSLog(@"\n%@", str);
|
||||
|
||||
NSData *data = [[NSData alloc] initWithBytes:bb length:60+32];
|
||||
*/
|
||||
|
||||
[_udp sendData:data toHost:@"192.168.254.23" port:8366 withTimeout:-1 tag:0];
|
||||
|
||||
// if([Pub getApp].p2ptest){
|
||||
// [_udp sendData:data toHost:@"47.107.109.110" port:self.sysinfo.server_port withTimeout:-1 tag:0];
|
||||
// }
|
||||
//[_udp sendData:data toHost:self.sysinfo.server_wan port:self.sysinfo.server_port withTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
if (_online == YES && ([Sformat timestamp] - _udp_last_replay_time )/1000 > 3*_sysinfo.reporttime) {
|
||||
//[Msg alert:@"离线"];
|
||||
_online = NO;
|
||||
}
|
||||
}
|
||||
|
||||
} @catch (NSException * ex) {
|
||||
NSLog(@"心跳包错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void storeDataInByteArray(Byte a[], id data, NSUInteger index) {
|
||||
// if (index >= sizeof(a)) {
|
||||
// NSLog(@"索引超出数组容量。");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if ([data isKindOfClass:[NSString class]]) {
|
||||
NSString *stringValue = (NSString *)data;
|
||||
const char *utf8String = [stringValue UTF8String];
|
||||
NSUInteger stringLength = [stringValue lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
memcpy(a + index, utf8String, stringLength);
|
||||
} else if ([data isKindOfClass:[NSNumber class]]) {
|
||||
NSNumber *numberValue = (NSNumber *)data;
|
||||
a[index] = [numberValue unsignedCharValue];
|
||||
} else {
|
||||
NSLog(@"不支持的数据类型。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)sendDataInMain
|
||||
{
|
||||
//BOOL res =
|
||||
NSLog(@"sendDataInMain remoteip=%@;port=%d",_udp_list.toHost,_udp_list.port);
|
||||
//NSLog(@"sendDataInMain %@",[Sformat Hex:_udp_list.data]);
|
||||
//NSLog(@"sendDataInMain: 本地端口 = %d ", _udp.localPort);
|
||||
[_udp sendData:_udp_list.data
|
||||
toHost:_udp_list.toHost
|
||||
port:_udp_list.port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
//NSLog(@"数据长度:%lu",(unsigned long)_udp_list.data.length);
|
||||
//NSLog(@"%@:%d", _udp_list.toHost, _udp_list.port);
|
||||
return YES;
|
||||
}
|
||||
- (void)senddataInThr:(NSData *)data toHost:(NSString *)host toPort:(int)port at:(int)second setTag:(int)tag
|
||||
{
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
udp_data_class *list = [_udp_datas objectAtIndex:i];
|
||||
if (!list.isUsed) {
|
||||
NSLog(@"i=%d",i);
|
||||
list.isUsed = YES;
|
||||
list.sendtimes = 0;
|
||||
list.sendtimesneed = second;
|
||||
list.data = data;
|
||||
list.toHost = host;
|
||||
list.port = port;
|
||||
//list.byport = port;
|
||||
list.tag = tag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSLog(@"time=%d", _udp_send_time);
|
||||
//if (udp_send_time<=0) {
|
||||
[_udp_send_Condition lock];
|
||||
_udp_send_time++;
|
||||
[_udp_send_Condition signal];
|
||||
[_udp_send_Condition unlock];
|
||||
//}
|
||||
}
|
||||
- (void)sendDataInMain:(Byte *)rr length:(int)len toHost:(NSString *)host toPort:(int)port
|
||||
{
|
||||
NSData *data = [[NSData alloc] initWithBytes:rr length:len];
|
||||
NSArray *aa = [[NSArray alloc] initWithObjects:data, host, [[NSString alloc] initWithFormat:@"%d", port], nil];
|
||||
//[self performSelectorOnMainThread:@selector(sendDataInMain:) withObject:aa waitUntilDone:YES];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
//NSLog(@"8302--%lu,%@:%d",(unsigned long)data.length,host,port);
|
||||
[_udp sendData:data
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
});
|
||||
}
|
||||
- (void)sendDataInMain:(NSArray *)a
|
||||
{
|
||||
NSData *data = (NSData *)[a objectAtIndex:0];
|
||||
NSString *host = (NSString *)[a objectAtIndex:1];
|
||||
int port = [(NSString *)[a objectAtIndex:2] intValue];
|
||||
//NSLog(@"8302--%lu,%@:%d",(unsigned long)data.length,host,port);
|
||||
[_udp sendData:data
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
}
|
||||
|
||||
//收到推送接听对讲页面
|
||||
- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock
|
||||
didReceiveData:(NSData *)data
|
||||
withTag:(long)tag
|
||||
fromHost:(NSString *)host
|
||||
port:(UInt16)port
|
||||
{
|
||||
@try{
|
||||
Byte *bb = (Byte *)[data bytes];
|
||||
NSData *data1 = [[NSData alloc] initWithBytes:bb length:60+32];
|
||||
data = data1;
|
||||
if(data.length==1){
|
||||
if(bb[0]==0x30||bb[0]==0x31){
|
||||
NSLog(@"p2p打洞");
|
||||
if([Pub getApp].p2ptest)
|
||||
[[Pub getApp].p2ptest GotDadong:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
return YES;
|
||||
}
|
||||
if (bb[6] == 4) {
|
||||
if(bb[7]==2){
|
||||
NSLog(@"心跳包反馈");
|
||||
//[[Pub getApp] playSoundWith:SoundOK];
|
||||
//if(_online == NO)[Msg alert:@"上线"];
|
||||
_online = YES;
|
||||
_udp_last_replay_time = [Sformat timestamp];
|
||||
}
|
||||
else if(bb[7]==3){
|
||||
[Msg alert:@"您已在其他设备登录"];
|
||||
//warnning
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
// //[Msg Alert:self Msg:ret];
|
||||
// [[Pub getApp] LogOut];
|
||||
// [Pub getApp].login = [[Login alloc] initWithNibName:@"Login" bundle:nil];
|
||||
// [Pub getApp].main = nil;
|
||||
// [Pub getApp].window.rootViewController = [Pub getApp].login ;
|
||||
// [[Pub getApp].window makeKeyAndVisible];
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (bb[6] == 150) {
|
||||
// if( [Pub getApp].main == nil ){
|
||||
// [_udp receiveWithTimeout:-1 tag:0];
|
||||
// return YES;
|
||||
// }
|
||||
if( [Pub getApp].isBack){
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
return YES;
|
||||
}
|
||||
//[[Pub getApp].main alert:@"呼叫"];
|
||||
if([Sformat timestamp] - [Pub getApp].sysinfo.launchtime < 2000 ){
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
return YES;
|
||||
}
|
||||
//NSLog(@"对讲命令:%d",bb[6]&0xff);
|
||||
switch (bb[8]&0xff) {
|
||||
NSLog(@"被呼叫2");
|
||||
case 1:
|
||||
//被叫
|
||||
[[Pub getApp].talk BeCall:bb Len:data.length Formip:host fromport:port];
|
||||
break;
|
||||
|
||||
case 6:{//接听
|
||||
if((bb[7]&0x3)==2){//被叫 接听反馈
|
||||
NSLog(@"接听反馈");
|
||||
[self stopSend:@"" rr6:150 rr8:6];
|
||||
[[Pub getApp].talk talkOnRec:bb];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
case 8:{//音视频数据
|
||||
//NSLog(@"音视频数据");
|
||||
[[Pub getApp].talk getAVData:bb withLength:data.length];
|
||||
}
|
||||
break;
|
||||
case 9:{//保持连接
|
||||
if((bb[7]&0x3)==1){//对方保持连接
|
||||
//NSLog(@"对方保持连接");
|
||||
bb[7] = 2;
|
||||
[[Pub getApp].udp.udp sendData:[[NSData alloc] initWithBytes:bb length:100]
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[Pub getApp].talk.connect_reg_time = [Sformat timestamp];
|
||||
}
|
||||
else{
|
||||
//NSLog(@"保持连接反馈");
|
||||
[Pub getApp].talk.connect_reg_time = [Sformat timestamp];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:{//开门反馈
|
||||
if((bb[7]&0x3)==2){
|
||||
NSLog(@"开门成功");
|
||||
if([self stopSend:@"" rr6:150 rr8:10]>-1){
|
||||
[[Pub getApp] OpenDoorSucc:[Pub getEquidFrombb:bb at:9]];
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
if([self stopSend:@"" rr6:150 rr8:10]>-1){
|
||||
[[Pub getApp] OpenDoorFail:[Pub getEquidFrombb:bb at:9]];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 30:{//对讲结束
|
||||
if((bb[7]&0x3)==1){//对方结束对讲
|
||||
NSLog(@"对方结束对讲");
|
||||
bb[7] = 2;
|
||||
[[Pub getApp].udp.udp sendData:[[NSData alloc] initWithBytes:bb length:100]
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[[Pub getApp].talk status_ini];
|
||||
if([Pub getApp].callOut){
|
||||
[[Pub getApp].callOut UIClose];
|
||||
}
|
||||
}
|
||||
else{//结束对讲反馈
|
||||
NSLog(@"结束对讲反馈");
|
||||
[self stopSend:@"" rr6:150 rr8:30];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 140:{//p2p测试
|
||||
if([Pub getApp].p2ptest)
|
||||
[[Pub getApp].p2ptest GotMyPortInServer:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
break;
|
||||
case 141:{//p2p测试
|
||||
if([Pub getApp].p2ptest)
|
||||
[[Pub getApp].p2ptest GotRemoteIp:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
break;
|
||||
case 142:{//p2p测试
|
||||
NSLog(@"p2p被叫");
|
||||
if([Pub getApp].p2ptest)
|
||||
[[Pub getApp].p2ptest GotCall:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
break;
|
||||
case 144:
|
||||
case 143:{//p2p测试 NSAsk
|
||||
NSLog(@"p2pNSAskNSAsk");
|
||||
if([Pub getApp].p2ptest)
|
||||
[[Pub getApp].p2ptest GotNSAsk:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(bb[6] == 152){
|
||||
|
||||
switch (bb[8]&0xff) {
|
||||
case 2://被叫
|
||||
NSLog(@"对方忙");
|
||||
[self stopSend:@"" rr6:152 rr8:1];
|
||||
if([Pub getApp].callOut){
|
||||
[[Pub getApp].callOut UIClose];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:{//监视成功
|
||||
NSLog(@"监视成功");
|
||||
[self stopSend:@"" rr6:152 rr8:1];
|
||||
if([Pub getApp].callOut){
|
||||
[[Pub getApp].talk watchSucc:bb Len:data.length Formip:host fromport:port];
|
||||
}
|
||||
else if([Pub getApp].main){
|
||||
// [[Pub getApp].main OpendoorGo];
|
||||
[[Pub getApp].main OpenDoorStep2];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
case 8:{//音视频数据
|
||||
//NSLog(@"音视频数据");
|
||||
[[Pub getApp].talk getAVData:bb withLength:data.length];
|
||||
}
|
||||
break;
|
||||
case 9:{//保持连接
|
||||
if((bb[7]&0x3)==1){//对方保持连接
|
||||
//NSLog(@"对方保持连接");
|
||||
bb[7] = 2;
|
||||
[[Pub getApp].udp.udp sendData:[[NSData alloc] initWithBytes:bb length:100]
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[Pub getApp].talk.connect_reg_time = [Sformat timestamp];
|
||||
}else{
|
||||
//NSLog(@"保持连接反馈");
|
||||
[Pub getApp].talk.connect_reg_time = [Sformat timestamp];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:{//开门反馈
|
||||
if((bb[7]&0x3)==2){
|
||||
NSLog(@"开门成功");
|
||||
if([self stopSend:@"" rr6:152 rr8:10]>-1){
|
||||
[[Pub getApp] OpenDoorSucc:[Pub getEquidFrombb:bb at:9]];
|
||||
|
||||
|
||||
}
|
||||
}else{
|
||||
if([self stopSend:@"" rr6:152 rr8:10]>-1){
|
||||
[[Pub getApp] OpenDoorFail:[Pub getEquidFrombb:bb at:9]];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 30:{//监视结束
|
||||
if((bb[7]&0x3)==1){//对方结束监视
|
||||
NSLog(@"对方结束监视");
|
||||
bb[7] = 2;
|
||||
[[Pub getApp].udp.udp sendData:[[NSData alloc] initWithBytes:bb length:100]
|
||||
toHost:host
|
||||
port:port
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
[[Pub getApp].talk status_ini];
|
||||
if([Pub getApp].callOut){
|
||||
[[Pub getApp].callOut UIClose];
|
||||
}
|
||||
}
|
||||
else{//结束监视反馈
|
||||
NSLog(@"结束监视反馈");
|
||||
[self stopSend:@"" rr6:150 rr8:30];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} @catch (NSException * ex) {
|
||||
NSLog(@"心跳包错误");
|
||||
}
|
||||
|
||||
|
||||
[_udp receiveWithTimeout:-1 tag:0];
|
||||
return YES;
|
||||
}
|
||||
- (int)stopSend:(NSString *)host rr6:(int)r6 rr8:(int)r8
|
||||
{
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
udp_data_class *list = [[udp_data_class alloc] init];
|
||||
list = [_udp_datas objectAtIndex:i];
|
||||
if (list.isUsed) {
|
||||
|
||||
if( ([host isEqualToString:@""])|([list.toHost isEqualToString:host])) {
|
||||
Byte *bb=(Byte *)[list.data bytes];
|
||||
if (r8 == -1) {
|
||||
if (bb[6]==r6) {
|
||||
NSLog(@"clear");
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((bb[6]==r6)&(bb[8]==r8)) {
|
||||
NSLog(@"clear");
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
- (int)ChgSendIp:(NSString *)host rr6:(int)r6 rr8:(int)r8 Port:(int)port
|
||||
{
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
udp_data_class *list = [[udp_data_class alloc] init];
|
||||
list = [_udp_datas objectAtIndex:i];
|
||||
if (list.isUsed) {
|
||||
Byte *bb=(Byte *)[list.data bytes];
|
||||
if ((bb[6]==r6)&(bb[8]==r8)) {
|
||||
list.toHost = host;
|
||||
list.port = port;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
- (int)stopSendDadong
|
||||
{
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
udp_data_class *list = [[udp_data_class alloc] init];
|
||||
list = [_udp_datas objectAtIndex:i];
|
||||
if (list.isUsed) {
|
||||
Byte *bb=(Byte *)[list.data bytes];
|
||||
if (list.data.length==1) {
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
- (int)stopSend:(NSString *)host rr6:(int)r6 rr8:(int)r8 Port:(int)port
|
||||
{
|
||||
|
||||
for (int i=0; i<BUFNUM; i++) {
|
||||
udp_data_class *list = [[udp_data_class alloc] init];
|
||||
list = [_udp_datas objectAtIndex:i];
|
||||
if (list.isUsed) {
|
||||
if(list.port !=port)continue;
|
||||
if( ([host isEqualToString:@""])|([list.toHost isEqualToString:host])) {
|
||||
Byte *bb=(Byte *)[list.data bytes];
|
||||
if (r8 == -1) {
|
||||
if (bb[6]==r6) {
|
||||
NSLog(@"clear");
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((bb[6]==r6)&(bb[8]==r8)) {
|
||||
NSLog(@"clear");
|
||||
list.isUsed = FALSE;
|
||||
[_udp_datas replaceObjectAtIndex:i withObject:list];
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
@end
|
||||
@ -1,21 +0,0 @@
|
||||
//
|
||||
// udp_data_class.h
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-10-31.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface udp_data_class : NSObject
|
||||
@property (nonatomic,assign) BOOL isUsed;
|
||||
@property (nonatomic,retain) NSData *data;
|
||||
@property (nonatomic,strong) NSString *toHost;
|
||||
@property (nonatomic,assign) int tag;
|
||||
@property (nonatomic,assign) int port;
|
||||
@property (nonatomic,assign) int byport;
|
||||
@property (nonatomic,assign) int sendtimes;
|
||||
@property (nonatomic,assign) int sendtimesneed;
|
||||
@property (nonatomic,assign) int res;
|
||||
@end
|
||||
@ -1,21 +0,0 @@
|
||||
//
|
||||
// udp_data_class.m
|
||||
// myhome
|
||||
//
|
||||
// Created by user on 12-10-31.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "udp_data_class.h"
|
||||
|
||||
@implementation udp_data_class
|
||||
@synthesize isUsed;
|
||||
@synthesize data;
|
||||
@synthesize toHost;
|
||||
@synthesize tag;
|
||||
@synthesize port;
|
||||
@synthesize byport;
|
||||
@synthesize sendtimes;
|
||||
@synthesize sendtimesneed;
|
||||
@synthesize res;
|
||||
@end
|
||||
@ -1,86 +0,0 @@
|
||||
//
|
||||
// sysInfo.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 15/10/31.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#ifndef Talk_UI_h
|
||||
#define Talk_UI_h
|
||||
|
||||
#define kIs_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
|
||||
#define kIs_iPhoneX ScreenWidth >=375.0f && ScreenHeight >=812.0f&& kIs_iphone
|
||||
|
||||
#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)
|
||||
#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)
|
||||
|
||||
//#define KstatusHeight (20.0)
|
||||
//#define KnavigationHeight (44.0)
|
||||
//#define KstatusAndNavHeight (64.0)
|
||||
#define TabBarHeight (49.0)
|
||||
|
||||
#define KScreenWidth (ScreenWidth)
|
||||
//#define KScreenHeight (ScreenHeight - KstatusHeight- KnavigationHeight)
|
||||
#define kBottomSafeHeight (CGFloat)(kIs_iPhoneX?(34.0):(0))
|
||||
|
||||
#define KScreenOriginX 0
|
||||
#define KScreenOriginY (KstatusHeight)
|
||||
|
||||
|
||||
#endif
|
||||
typedef NS_ENUM(NSInteger, UIPosition) {
|
||||
UIAabsolute = 0,
|
||||
UIRelative = 1,
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, UIPositionInParent) {
|
||||
UITopLeft = 0,
|
||||
UITopMid = 1,
|
||||
UITopRight = 2,
|
||||
UIMidLeft = 3,
|
||||
UICenter = 4,
|
||||
UIMidRight = 5,
|
||||
UIBottomLeft = 6,
|
||||
UIBottomMid = 7,
|
||||
UIBottomRight = 8,
|
||||
};
|
||||
typedef NS_ENUM(NSInteger, UIPositionByView) {
|
||||
TopAlignLeft = 0,
|
||||
TopAlignCenter = 1,
|
||||
TopAlignRight = 2,
|
||||
RightAlignTop = 3,
|
||||
RightAlignCenter = 4,
|
||||
RightAlignBottom = 5,
|
||||
BottomAlignLeft = 6,
|
||||
BottomAlignCenter = 7,
|
||||
BottomAlignRight = 8,
|
||||
LeftAlignTop = 9,
|
||||
LeftAlignCenter = 10,
|
||||
LeftAlignBottom = 11,
|
||||
|
||||
};
|
||||
|
||||
@interface UI : NSObject
|
||||
|
||||
+ (CGFloat)getScreenWidth;
|
||||
+ (CGFloat)getScreenHeight;
|
||||
+ (void)SetRView:(UIView *) view Top:(NSString *) t Right:(NSString *) r Bottom:(NSString *) b Left:(NSString *) l;
|
||||
+ (void)setFrame:(UIView *) view Width:(NSString *) w Height:(NSString *) h Left:(NSString *) x Top:(NSString *) y;
|
||||
+ (void)setFrameInView:(UIView *) view Width:(NSString *) w Height:(NSString *) h TranslateX:(NSString *) x TranslateY:(NSString *) y InView:(UIView *) parent Position:(UIPositionInParent)pos;
|
||||
+ (void)setFrameByView:(UIView *) view Width:(NSString *) w Height:(NSString *) h TranslateX:(NSString *) x TranslateY:(NSString *) y ByView:(UIView *) brother Position:(UIPositionByView)pos;
|
||||
+ (void)chgMargin:(UIView *) view Css:(NSString *) css;
|
||||
+ (void)setCornerRadius:(UIView *) view;
|
||||
+ (void)setGradientBorder:(UIView *)view withColor:(NSInteger)color;
|
||||
+ (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize;
|
||||
+ (UILabel *)NewLabel:(NSString *) text Color:(UIColor *)color Size:(CGFloat)size Align:(NSTextAlignment) align;
|
||||
+ (UIColor *)colorWithHex:(NSInteger)hexValue;
|
||||
+ (UIColor *)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue;
|
||||
+ (CGFloat)getNavHeight;
|
||||
+ (CGFloat)getStatuHeight;
|
||||
+ (CGFloat)getStatuAndStatuHeight;
|
||||
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;
|
||||
@end
|
||||
@ -1,356 +0,0 @@
|
||||
//
|
||||
// sysInfo.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 15/10/31.
|
||||
//
|
||||
//
|
||||
|
||||
#import "UI.h"
|
||||
#import <math.h>
|
||||
#import "Pub.h"
|
||||
|
||||
@interface UI ()
|
||||
|
||||
@end
|
||||
@implementation UI{
|
||||
|
||||
}
|
||||
|
||||
+ (CGFloat)getScreenWidth{
|
||||
CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
return screenRect.size.width;
|
||||
}
|
||||
+ (CGFloat)getScreenHeight{
|
||||
CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
return screenRect.size.height;
|
||||
}
|
||||
|
||||
+ (void)SetRView:(UIView *) view Top:(NSString *) t Right:(NSString *) r Bottom:(NSString *) b Left:(NSString *) l{
|
||||
CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
CGFloat t1 = [UI String2Float:t ULen:screenRect.size.height];
|
||||
CGFloat r1 = [UI String2Float:r ULen:screenRect.size.width];
|
||||
CGFloat b1 = [UI String2Float:b ULen:screenRect.size.height];
|
||||
CGFloat l1 = [UI String2Float:l ULen:screenRect.size.width];
|
||||
|
||||
CGFloat w1 = screenRect.size.width - l1 - r1;
|
||||
CGFloat h1 = screenRect.size.height - t1 - b1;
|
||||
CGFloat x1 = l1;
|
||||
CGFloat y1 = t1;
|
||||
|
||||
//NSLog(@"SetRView:%f,%f,%f,%f",x1, y1, w1, h1);
|
||||
view.frame = CGRectMake(x1, y1, w1, h1);
|
||||
}
|
||||
|
||||
+ (CGFloat)String2Float:(NSString *) str ULen:(CGFloat) l{
|
||||
CGFloat v = 0;
|
||||
//判断宽度是值还是百分比
|
||||
if([str containsString:@"%"]){
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"%" withString:@""] floatValue];
|
||||
v = v * l/100;
|
||||
}
|
||||
else if([str containsString:@"v"]){
|
||||
CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
if([str containsString:@"vw"]){
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"vw" withString:@""] floatValue];
|
||||
v = v * screenRect.size.width/100;
|
||||
}
|
||||
else if([str containsString:@"vh"]){
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"vw" withString:@""] floatValue];
|
||||
v = v * screenRect.size.height/100;
|
||||
}
|
||||
else if([str containsString:@"vmin"]){
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"vw" withString:@""] floatValue];
|
||||
v = v * MIN(screenRect.size.width, screenRect.size.height) /100;
|
||||
}
|
||||
else if([str containsString:@"vmax"]){
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"vw" withString:@""] floatValue];
|
||||
v = v * MAX(screenRect.size.width, screenRect.size.height) /100;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
v = [[str stringByReplacingOccurrencesOfString:@"dp" withString:@""] floatValue];
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
+ (void)setFrame:(UIView *) view Width:(NSString *) w Height:(NSString *) h Left:(NSString *) x Top:(NSString *) y{
|
||||
CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
CGFloat w1 = [UI String2Float:w ULen:screenRect.size.width];
|
||||
CGFloat h1 = [UI String2Float:h ULen:screenRect.size.height];
|
||||
CGFloat x1 = [UI String2Float:x ULen:screenRect.size.width];
|
||||
CGFloat y1 = [UI String2Float:y ULen:screenRect.size.height];
|
||||
|
||||
//NSLog(@"setFrame:%f,%f,%f,%f",x1, y1, w1, h1);
|
||||
view.frame = CGRectMake(x1, y1, w1, h1);
|
||||
}
|
||||
+ (void)setFrameInView:(UIView *) view Width:(NSString *) w Height:(NSString *) h TranslateX:(NSString *) x TranslateY:(NSString *) y InView:(UIView *) parent Position:(UIPositionInParent)pos{
|
||||
if(!parent)parent = (UIView *)[view nextResponder];
|
||||
CGFloat w1 = [UI String2Float:w ULen:parent.frame.size.width];
|
||||
CGFloat h1 = [UI String2Float:h ULen:parent.frame.size.height];
|
||||
CGFloat x1 = [UI String2Float:x ULen:parent.frame.size.width];
|
||||
CGFloat y1 = [UI String2Float:y ULen:parent.frame.size.height];
|
||||
|
||||
|
||||
switch (pos) {
|
||||
case UITopLeft:
|
||||
//y1 = y1;
|
||||
//x1 = x1;
|
||||
break;
|
||||
case UITopMid:
|
||||
//y1 = y1;
|
||||
x1 += (parent.frame.size.width - w1)/2;
|
||||
break;
|
||||
case UITopRight:
|
||||
//y1 = y1;
|
||||
x1 = parent.frame.size.width - w1 - x1;
|
||||
break;
|
||||
case UIMidLeft:
|
||||
y1 += (parent.frame.size.height - h1)/2;
|
||||
//x1 = x1;
|
||||
break;
|
||||
case UICenter:
|
||||
y1 += (parent.frame.size.height - h1)/2;
|
||||
x1 += (parent.frame.size.width - w1)/2;
|
||||
break;
|
||||
case UIMidRight:
|
||||
y1 += (parent.frame.size.height - h1)/2;
|
||||
x1 = parent.frame.size.width - w1 - x1;
|
||||
break;
|
||||
case UIBottomLeft:
|
||||
y1 = parent.frame.size.height - h1 - y1;
|
||||
//x1 = x1;
|
||||
break;
|
||||
case UIBottomMid:
|
||||
y1 = parent.frame.size.height - h1 - y1;
|
||||
x1 += (parent.frame.size.width - w1)/2;
|
||||
break;
|
||||
case UIBottomRight:
|
||||
y1 = parent.frame.size.height - h1 - y1;
|
||||
x1 = parent.frame.size.width - w1 - x1;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
//NSLog(@"setFrameInView:%f,%f,%f,%f",x1, y1, w1, h1);
|
||||
view.frame = CGRectMake(x1, y1, w1, h1);
|
||||
}
|
||||
|
||||
+ (void)setFrameByView:(UIView *) view Width:(NSString *) w Height:(NSString *) h TranslateX:(NSString *) x TranslateY:(NSString *) y ByView:(UIView *) brother Position:(UIPositionByView)pos{
|
||||
UIView * parent = (UIView *)[view nextResponder];
|
||||
CGFloat w1 = [UI String2Float:w ULen:parent.frame.size.width];
|
||||
CGFloat h1 = [UI String2Float:h ULen:parent.frame.size.height];
|
||||
CGFloat x1 = [UI String2Float:x ULen:parent.frame.size.width];
|
||||
CGFloat y1 = [UI String2Float:y ULen:parent.frame.size.height];
|
||||
|
||||
switch (pos) {
|
||||
case TopAlignLeft:
|
||||
y1 = brother.frame.origin.y - h1 - y1;
|
||||
x1 += brother.frame.origin.x;
|
||||
break;
|
||||
case TopAlignCenter:
|
||||
y1 = brother.frame.origin.y - h1 - y1;
|
||||
x1 += brother.frame.origin.x + (brother.frame.size.width - w1)/2 ;
|
||||
break;
|
||||
case TopAlignRight:
|
||||
y1 = brother.frame.origin.y - h1 - y1;
|
||||
x1 += brother.frame.size.width + brother.frame.origin.x - w1;
|
||||
break;
|
||||
case RightAlignTop:
|
||||
x1 += brother.frame.size.width + brother.frame.origin.x ;
|
||||
y1 += brother.frame.origin.y;
|
||||
break;
|
||||
case RightAlignCenter:
|
||||
x1 += brother.frame.size.width + brother.frame.origin.x ;
|
||||
y1 += brother.frame.origin.y + (brother.frame.size.height - h1)/2 ;
|
||||
break;
|
||||
case RightAlignBottom:
|
||||
x1 += brother.frame.size.width + brother.frame.origin.x ;
|
||||
y1 += brother.frame.size.height + brother.frame.origin.y - h1;
|
||||
break;
|
||||
case BottomAlignLeft:
|
||||
y1 += brother.frame.size.height + brother.frame.origin.y;
|
||||
x1 += brother.frame.origin.x;
|
||||
break;
|
||||
case BottomAlignCenter:
|
||||
y1 += brother.frame.size.height + brother.frame.origin.y;
|
||||
x1 += brother.frame.origin.x + (brother.frame.size.width - w1)/2 ;
|
||||
break;
|
||||
case BottomAlignRight:
|
||||
y1 += brother.frame.size.height + brother.frame.origin.y;
|
||||
x1 += brother.frame.size.width + brother.frame.origin.x - w1;
|
||||
break;
|
||||
case LeftAlignTop:
|
||||
x1 = brother.frame.origin.x - w1 - x1;
|
||||
y1 += brother.frame.origin.y;
|
||||
break;
|
||||
case LeftAlignCenter:
|
||||
x1 += brother.frame.origin.x - w1 - x1;
|
||||
y1 += brother.frame.origin.y + (brother.frame.size.height - h1)/2 ;
|
||||
break;
|
||||
case LeftAlignBottom:
|
||||
x1 += brother.frame.origin.x - w1 - x1;
|
||||
y1 += brother.frame.size.height + brother.frame.origin.y - h1;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
//NSLog(@"setFrameInView:%f,%f,%f,%f",x1, y1, w1, h1);
|
||||
view.frame = CGRectMake(x1, y1, w1, h1);
|
||||
}
|
||||
/**不能对最上层控件使用*/
|
||||
+ (void)chgMargin:(UIView *) view Css:(NSString *) css{
|
||||
UIView * parent = (UIView *)[view nextResponder];
|
||||
CGFloat w1 = view.frame.size.width;
|
||||
CGFloat h1 = view.frame.size.height;
|
||||
CGFloat x1 = view.frame.origin.x;
|
||||
CGFloat y1 = view.frame.origin.y;
|
||||
NSArray *array = [css componentsSeparatedByString:@" "];
|
||||
if(array.count>0){//上
|
||||
CGFloat minus = [UI String2Float:array[0] ULen:parent.frame.size.height];
|
||||
if(minus < h1){
|
||||
y1 += minus;
|
||||
h1 -= minus;
|
||||
}
|
||||
}
|
||||
if(array.count>1){//右
|
||||
CGFloat minus = [UI String2Float:array[1] ULen:parent.frame.size.width];
|
||||
if(minus < w1){
|
||||
w1 -= minus;
|
||||
//y1不变
|
||||
}
|
||||
}
|
||||
if(array.count>2){//下
|
||||
CGFloat minus = [UI String2Float:array[2] ULen:parent.frame.size.height];
|
||||
if(minus < h1){
|
||||
//x1不变;
|
||||
h1 -= minus;
|
||||
}
|
||||
}
|
||||
if(array.count>3){//左
|
||||
CGFloat minus = [UI String2Float:array[3] ULen:parent.frame.size.width];
|
||||
if(minus < w1){
|
||||
x1 += minus;
|
||||
w1 -= minus;
|
||||
}
|
||||
}
|
||||
view.frame = CGRectMake(x1, y1, w1, h1);
|
||||
}
|
||||
|
||||
+ (void)setCornerRadius:(UIView *) view{
|
||||
CGFloat w1 = view.frame.size.width;
|
||||
CGFloat h1 = view.frame.size.height;
|
||||
//NSLog(@"setCornerRadius: %f,%f", w1, h1);
|
||||
[view.layer setCornerRadius:MIN(w1,h1)/2]; //设置矩形四个圆角半径
|
||||
}
|
||||
|
||||
+ (void)setGradientBorder:(UIView *)view withColor:(NSInteger)color{
|
||||
view.backgroundColor = [UI colorWithHex:color alpha:0.5] ;
|
||||
|
||||
|
||||
CAGradientLayer *layer1 = [[CAGradientLayer alloc] init];
|
||||
layer1.frame = view.bounds;
|
||||
layer1.colors = @[(__bridge id)[UI colorWithHex:color].CGColor,(__bridge id)[UI colorWithHex:0xffffff].CGColor];
|
||||
layer1.startPoint = CGPointMake(0.3, 0.3);
|
||||
layer1.endPoint = CGPointMake(1, 1);
|
||||
[layer1 setCornerRadius:MIN(view.frame.size.width,view.frame.size.height)/2];
|
||||
|
||||
|
||||
CAShapeLayer *layer2 = [[CAShapeLayer alloc] init];
|
||||
layer2.lineWidth = 0;
|
||||
//maskLayer.path = [UIBezierPath bezierPathWithRect:self.openView.bounds].CGPath;
|
||||
|
||||
CGPoint center = CGPointMake(view.frame.size.width * 0.5, view.frame.size.height * 0.5);
|
||||
CGFloat radius = view.frame.size.height * 0.44;
|
||||
layer2.path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:0 endAngle:M_PI * 2 clockwise:YES].CGPath;
|
||||
|
||||
layer2.fillColor = [UI colorWithHex:color].CGColor;
|
||||
layer2.strokeColor = nil;
|
||||
|
||||
|
||||
|
||||
[view.layer addSublayer:layer1];
|
||||
[view.layer addSublayer:layer2];
|
||||
}
|
||||
|
||||
|
||||
+ (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
|
||||
{
|
||||
UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
|
||||
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
|
||||
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return reSizeImage;
|
||||
}
|
||||
+ (UILabel *)NewLabel:(NSString *) text Color:(UIColor *)color Size:(CGFloat)size Align:(NSTextAlignment) align{
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
label.font = [UIFont systemFontOfSize:size];
|
||||
label.textColor = color;
|
||||
label.textAlignment = align;
|
||||
label.text = NSLocalizedString(text, nil);
|
||||
return label;
|
||||
}
|
||||
|
||||
+ (CGFloat)getNavHeight{
|
||||
@try
|
||||
{
|
||||
if([@"MainTabBar" isEqualToString:NSStringFromClass([[Pub getApp].window.rootViewController class])]){
|
||||
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
|
||||
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
|
||||
return nav.navigationBar.frame.size.height;
|
||||
}
|
||||
} @catch (NSException * e) {
|
||||
|
||||
}
|
||||
|
||||
return 44.;
|
||||
}
|
||||
//颜色处理
|
||||
+ (UIColor *)colorWithHex:(NSInteger)hexValue
|
||||
{
|
||||
return [self colorWithHex:hexValue alpha:1.0];
|
||||
}
|
||||
|
||||
+ (UIColor *)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue
|
||||
{
|
||||
return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0
|
||||
green:((float)((hexValue & 0xFF00) >> 8)) / 255.0
|
||||
blue:((float)(hexValue & 0xFF)) / 255.0
|
||||
alpha:alphaValue];
|
||||
}
|
||||
|
||||
|
||||
+ (CGFloat)getStatuHeight{
|
||||
if(@available(ios 13.0,*)){
|
||||
NSSet *set = [UIApplication sharedApplication].connectedScenes;
|
||||
UIWindowScene * windowScene = [set anyObject];
|
||||
UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
|
||||
return statusBarManager.statusBarFrame.size.height;
|
||||
|
||||
}
|
||||
else{
|
||||
return [UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+ (CGFloat)getStatuAndStatuHeight{
|
||||
return [self getStatuHeight]+[self getNavHeight];
|
||||
}
|
||||
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
|
||||
{
|
||||
CGRect rect = CGRectMake(0, 0, size.width, size.height);
|
||||
UIGraphicsBeginImageContext(rect.size);
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetFillColorWithColor(context,color.CGColor);
|
||||
CGContextFillRect(context, rect);
|
||||
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return img;
|
||||
}
|
||||
@end
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
//
|
||||
// sysInfo.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 15/10/31.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <sqlite3.h>
|
||||
//#import "ServicesModel.h"
|
||||
|
||||
@interface sysInfo : NSObject
|
||||
|
||||
@property sqlite3 *db;
|
||||
@property (nonatomic,copy) NSString *token;
|
||||
@property (nonatomic,copy) NSString *pushkitToken;
|
||||
@property (nonatomic,copy) NSString *equid;
|
||||
@property (nonatomic,copy) NSString *equip;
|
||||
@property (nonatomic,copy) NSString *equmac;
|
||||
@property (nonatomic,assign) long launchtime;
|
||||
@property (nonatomic,assign) int port;
|
||||
@property (nonatomic,copy) NSString *server;//url
|
||||
@property (nonatomic,strong) NSString * server_wan;
|
||||
@property (nonatomic,assign) int server_port;
|
||||
@property (nonatomic,assign) int equ_server;
|
||||
@property (nonatomic,assign) int code_mode;
|
||||
@property (nonatomic,assign) int user;
|
||||
@property (nonatomic,copy) NSString *lasttime;
|
||||
@property (nonatomic,assign) int maxid;
|
||||
@property (nonatomic,assign) int _areaid;
|
||||
@property (nonatomic,copy) NSString *areaname;
|
||||
@property (nonatomic,assign) int reporttime;
|
||||
@property (nonatomic,assign) long smscodetime;
|
||||
@property (nonatomic,copy) NSString *tserver;
|
||||
@property (nonatomic,copy) NSString *tserver_wan;
|
||||
@property (nonatomic,copy) NSString *tserver_lan;
|
||||
@property (nonatomic,copy) NSString *areaid;
|
||||
@property (nonatomic,copy) NSString *username;
|
||||
@property (nonatomic,assign) int subequid;
|
||||
@property (nonatomic,copy) NSString *sysver;
|
||||
|
||||
@property (nonatomic, strong) NSString *reftime; //
|
||||
@property (nonatomic, strong) NSString *span; //
|
||||
@property (nonatomic, strong) NSString *services; //服务开通
|
||||
|
||||
@property (nonatomic,assign) int sandbox;
|
||||
@property (nonatomic,assign) int push;
|
||||
@property (nonatomic,assign) int HF;
|
||||
- (void)readSystemInfo;
|
||||
- (Boolean)initDB;
|
||||
- (void)sqlexe:(NSString *)sql;
|
||||
- (void)setSystemInfo:(NSString *)key WithValue:(NSString *)value;
|
||||
- (void)SaveRecord:(long)time Type:(NSString *)type Equ:(NSString *)equid Img:(NSString *)img Note:(NSString *)note;
|
||||
- (NSMutableArray *)readRecord:(NSString *)no;
|
||||
- (void)delRecord:(NSString *)condition;
|
||||
@end
|
||||
@ -1,225 +0,0 @@
|
||||
//
|
||||
// sysInfo.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 15/10/31.
|
||||
//
|
||||
//
|
||||
|
||||
#import "sysInfo.h"
|
||||
#import "Opendoor.h"
|
||||
|
||||
@interface sysInfo ()
|
||||
|
||||
@end
|
||||
@implementation sysInfo{
|
||||
|
||||
}
|
||||
|
||||
@synthesize db = db;
|
||||
|
||||
- (Boolean)initDB{
|
||||
//打开数据库
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //获取应用程序生成一个私有目录/Users/apple/Library/Application Support/iPhone Simulator/4.3/Applications/550AF26D-174B-42E6-881B-B7499FAA32B7/Documents
|
||||
NSString *documentsDirectory = [paths objectAtIndex:0]; //
|
||||
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"linetsql.sqlite"];
|
||||
|
||||
if (sqlite3_open([path UTF8String], &db) != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
NSLog(@"数据库打开失败");
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
NSLog(@"数据库打开成功");
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sqlexe:(NSString *)sql
|
||||
{
|
||||
char *err;
|
||||
int ret = sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err);
|
||||
|
||||
NSLog(@"数据库操作结果!%d",ret);
|
||||
if ( ret!= SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
NSLog(@"数据库操作数据失败!%@",[NSString stringWithUTF8String:err]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)readSystemInfo
|
||||
{
|
||||
self.equid = @"";
|
||||
self.username = @"";
|
||||
self.server_wan = @"8.129.71.206";
|
||||
self.server_port = 8367;
|
||||
self.port = 8366;
|
||||
self.equip = @"0.0.0.0";
|
||||
self.reporttime = 15;
|
||||
self.smscodetime = 0;
|
||||
self.pushkitToken = @"";
|
||||
self.push = 1;
|
||||
self.HF = 0;
|
||||
self.sandbox = 0;
|
||||
|
||||
NSString *sql = @"SELECT * FROM linet_sysinfo";
|
||||
sqlite3_stmt * statement;
|
||||
|
||||
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
||||
NSLog(@"sqlite3_prepare_v2 OK");
|
||||
while(sqlite3_step(statement) == SQLITE_ROW) {
|
||||
NSString *key = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0) ];
|
||||
if( [@"equid" isEqualToString: key]){
|
||||
self.equid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
}
|
||||
else if([@"push" isEqualToString: key]){
|
||||
self.push = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] intValue];
|
||||
}
|
||||
else if([@"HF" isEqualToString: key]){
|
||||
self.HF = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] intValue];
|
||||
}
|
||||
|
||||
// else if( [@"equip" isEqualToString: key]){
|
||||
// self.equip = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
// }
|
||||
// else if([@"equmac" isEqualToString: key]){
|
||||
// self.equmac = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
// }
|
||||
// else if([@"port" isEqualToString: key]){
|
||||
// self.port = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] intValue];
|
||||
// }
|
||||
// else if([@"server" isEqualToString: key]){
|
||||
// self.server = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
// }
|
||||
// else if([@"server_wan" isEqualToString: key]){
|
||||
// self.server_wan = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
// }
|
||||
// else if([@"server_port" isEqualToString: key]){
|
||||
// self.server_port = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] intValue];
|
||||
// }
|
||||
else if([@"lasttime" isEqualToString: key]){
|
||||
self.lasttime = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
}
|
||||
else if([@"username" isEqualToString: key]){
|
||||
self.username = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
}
|
||||
else if([@"token" isEqualToString: key]){
|
||||
self.token = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
|
||||
}
|
||||
else if([@"smscodetime" isEqualToString: key]){
|
||||
self.smscodetime = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] longLongValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
//没有linet_sysinfo,初始化数据库
|
||||
|
||||
NSLog(@"sysinfo不存在,创建表并初始化数据库");
|
||||
//创建系统参数表
|
||||
sql=@"DROP TABLE if exists linet_sysinfo";
|
||||
NSLog(@"drop");
|
||||
[self sqlexe:sql];
|
||||
|
||||
sql =@"create table linet_sysinfo(pname string primary key,pvalue string)";
|
||||
[self sqlexe:sql];
|
||||
|
||||
sql =@"create table record(no integer PRIMARY KEY AUTOINCREMENT,stime long,type string,username string,equid string,name string,img string,note string)";
|
||||
[self sqlexe:sql];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (void)SaveRecord:(long)time Type:(NSString *)type Equ:(NSString *)equid Img:(NSString *)img Note:(NSString *)note{
|
||||
NSString *name = [Opendoor EquNameById:equid];
|
||||
NSString *sql = [[NSString alloc] initWithFormat: @"insert into record(stime,type,username,equid,name,img,note) values (%ld,'%@','%@','%@','%@','%@','%@')",time,type,self.username,equid,name,img,note] ;
|
||||
NSLog(sql);
|
||||
[self sqlexe:sql];
|
||||
}
|
||||
- (NSMutableArray *)readRecord:(NSString *)no{
|
||||
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:0];
|
||||
NSString *sql;
|
||||
if(no){
|
||||
sql = [[NSString alloc] initWithFormat:@"SELECT no,stime,type,equid,name,img,note FROM record where username='%@' and no<%@ order by no desc limit 0,20",self.username,no] ;
|
||||
}
|
||||
else{
|
||||
sql = [[NSString alloc] initWithFormat:@"SELECT no,stime,type,equid,name,img,note FROM record where username='%@' order by no desc limit 0,20",self.username] ;
|
||||
}
|
||||
//sql = @"SELECT no,stime,type,equid,name,img,note FROM record order by no desc" ;
|
||||
NSLog(sql);
|
||||
sqlite3_stmt * statement;
|
||||
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
||||
NSLog(@"sqlite3_prepare_v2 OK");
|
||||
while(sqlite3_step(statement) == SQLITE_ROW) {
|
||||
|
||||
NSDictionary *dic = [[NSDictionary alloc] initWithObjects:@[
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5) ],
|
||||
[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 6) ]
|
||||
]
|
||||
forKeys:@[@"no",@"stime",@"type",@"equid",@"name",@"img",@"note"]];
|
||||
|
||||
// for (id key in dic) {
|
||||
// id value=[dic objectForKey:key];
|
||||
// NSLog(@"readRecord:%@:%@",key,value);
|
||||
//
|
||||
// }
|
||||
[ret addObject:dic];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
- (void)delRecord:(NSString *)condition{
|
||||
NSString *sql = [[NSString alloc] initWithFormat:@"select img FROM record where username='%@' and type='截图' %@",self.username,condition] ;
|
||||
sqlite3_stmt * statement;
|
||||
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
||||
NSLog(@"sqlite3_prepare_v2 OK");
|
||||
while(sqlite3_step(statement) == SQLITE_ROW) {
|
||||
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
|
||||
NSString *imageFilePath = [path stringByAppendingPathComponent:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0) ]];
|
||||
[[NSFileManager defaultManager] removeItemAtPath:imageFilePath error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
sql = [[NSString alloc] initWithFormat:@"delete FROM record where username='%@' %@",self.username,condition] ;
|
||||
NSLog(sql);
|
||||
[self sqlexe:sql];
|
||||
}
|
||||
- (void)setSystemInfo:(NSString *)key WithValue:(NSString *)value
|
||||
{
|
||||
|
||||
NSString *sql = [[NSString alloc] initWithFormat: @"SELECT * FROM linet_sysinfo where pname='%@'",key] ;
|
||||
sqlite3_stmt * statement;
|
||||
|
||||
int ret = sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil);
|
||||
if(ret == SQLITE_OK) {
|
||||
if(sqlite3_step(statement) == SQLITE_ROW) {
|
||||
sql = [[NSString alloc] initWithFormat: @"update linet_sysinfo set pvalue='%@' where pname='%@'",value,key] ;
|
||||
}
|
||||
else{
|
||||
sql = [[NSString alloc] initWithFormat: @"insert into linet_sysinfo(pname,pvalue) values('%@','%@')",key,value] ;
|
||||
}
|
||||
NSLog(@"%@",sql);
|
||||
[self sqlexe:sql];
|
||||
|
||||
}
|
||||
else{
|
||||
NSLog(@"setSystemInfo 失败:%d",ret);
|
||||
}
|
||||
|
||||
// NSString *sql = [[NSString alloc] initWithFormat:@"update linet_sysinfo set equid='%@',equip='%@',equmac='%@',port=%d,server='%@',server_wan='%@',server_lan='%@',equ_server=%d,code_mode=%d,subequid=%d",sysinfo.equid,sysinfo.equip,sysinfo.equmac,sysinfo.port,sysinfo.server,sysinfo.server_wan,sysinfo.server_lan,sysinfo.equ_server,sysinfo.code_mode,sysinfo.subequid];
|
||||
// NSLog(@"%@",sql);
|
||||
// [self sqlexe:sql];
|
||||
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface Opendoor : BaseViewController
|
||||
|
||||
+ (void)refEqulist:(void (^)(void)) handler;
|
||||
+ (NSArray *)getEqulist;
|
||||
+ (NSString *)EquNameById:(NSString *)equid;
|
||||
- (void)OpenDoorStep1:(NSString *)pwd;
|
||||
- (void)OpenDoorStep2;
|
||||
- (void)OpenDoorEnd;
|
||||
//- (void)OpendoorGo;
|
||||
//- (void)OpenEnd:(NSString *)msg;
|
||||
//- (void)alert:(NSString *)msg;
|
||||
|
||||
@end
|
||||
|
||||
@ -1,413 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Opendoor.h"
|
||||
#import "UI.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Msg.h"
|
||||
#import "Pub.h"
|
||||
#import "sysInfo.h"
|
||||
#import "Call.h"
|
||||
#import "EquAdd.h"
|
||||
#import "EquConfig.h"
|
||||
#import "P2pTest.h"
|
||||
#import "Sformat.h"
|
||||
|
||||
@interface Opendoor ()
|
||||
|
||||
@property (nonatomic, strong)UIView *rview,*headView,*topView,*bottomView,*openView,*openBgView;
|
||||
@property (nonatomic, strong)UILabel *titleLabel;
|
||||
@property (nonatomic, strong)UIImageView *rightImage,*watchImage,*openImage,*wave1Image,*wave2Image,*wave3Image;
|
||||
@property (nonatomic, strong)UIButton *selequButton;
|
||||
@property (nonatomic, strong)UIAlertController *openAlert;
|
||||
@property NSArray *equlist;
|
||||
@property int selIndex;
|
||||
@property NSString *pwd;
|
||||
|
||||
@property long p2p_click_times;
|
||||
@property long p2p_click_time;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Opendoor
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
[self setNavTitle:@"手机开门"];
|
||||
[self setNavRight:@"setting" action:@selector(ConfigEqu) ];
|
||||
[self setNavLeft:@"blank" action:@selector(P2ptest) ];
|
||||
[self setupViews];
|
||||
[self setUI];
|
||||
[Opendoor refEqulist:nil];
|
||||
self.p2p_click_time = 0;
|
||||
}
|
||||
- (void)setupViews
|
||||
{
|
||||
|
||||
|
||||
[self.view addSubview:self.rview];
|
||||
//[self.rview addSubview:self.headView];
|
||||
[self.rview addSubview:self.topView];
|
||||
[self.rview addSubview:self.bottomView];
|
||||
|
||||
|
||||
//[self.headView addSubview:self.titleLabel];
|
||||
//[self.headView addSubview:self.rightImage];
|
||||
|
||||
|
||||
[self.topView addSubview:self.selequButton];
|
||||
[self.topView addSubview:self.watchImage];
|
||||
[self.topView addSubview:self.wave1Image];
|
||||
[self.topView addSubview:self.wave2Image];
|
||||
[self.topView addSubview:self.wave3Image];
|
||||
|
||||
|
||||
[self.bottomView addSubview:self.openView];
|
||||
[self.openView addSubview:self.openBgView];
|
||||
[self.openView addSubview:self.openImage];
|
||||
|
||||
|
||||
[self.watchImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Watch)]];
|
||||
[self.selequButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelEqu)]];
|
||||
[self.openView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OpenDoor)]];
|
||||
}
|
||||
- (void)setUI{
|
||||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||||
|
||||
|
||||
//[UI setFrameInView:self.headView Width:@"100vw" Height:@"70" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UITopMid];
|
||||
[UI setFrameInView:self.topView Width:@"100vw" Height:@"55vh" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UITopMid];
|
||||
[UI setFrameInView:self.bottomView Width:@"100vw" Height:@"45vh" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UIBottomMid];
|
||||
[UI chgMargin:self.topView Css:[[NSString alloc] initWithFormat:@"%f 0 0 0",[UI getStatuAndStatuHeight]]];
|
||||
|
||||
|
||||
|
||||
//[UI setFrameInView:self.titleLabel Width:@"100vw" Height:@"50" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UIBottomMid];
|
||||
//[UI chgMargin:self.titleLabel Css:@"0 50 0 50"];
|
||||
//[UI setFrameInView:self.rightImage Width:@"20" Height:@"20" TranslateX:@"15" TranslateY:@"15" InView:nil Position:UIBottomRight];
|
||||
|
||||
[UI setFrameInView:self.selequButton Width:@"70vw" Height:@"50" TranslateX:@"0" TranslateY:@"30%" InView:nil Position:UITopMid];
|
||||
[UI chgMargin:self.selequButton Css:@"0 55 0 0"];
|
||||
[UI setFrameByView:self.watchImage Width:@"50" Height:@"50" TranslateX:@"5" TranslateY:@"0" ByView:self.selequButton Position:RightAlignCenter];
|
||||
|
||||
|
||||
[UI setFrameInView:self.wave1Image Width:@"122vw" Height:@"66" TranslateX:@"0" TranslateY:@"-6" InView:nil Position:UIBottomMid];
|
||||
[UI setFrameInView:self.wave2Image Width:@"112vw" Height:@"68" TranslateX:@"8vw" TranslateY:@"-4" InView:nil Position:UIBottomMid];
|
||||
[UI setFrameInView:self.wave3Image Width:@"104vw" Height:@"70" TranslateX:@"0" TranslateY:@"-2" InView:nil Position:UIBottomMid];
|
||||
|
||||
|
||||
[UI setFrameInView:self.openView Width:@"35vw" Height:@"35vw" TranslateX:@"0" TranslateY:@"-20%" InView:nil Position:UICenter];
|
||||
[UI setFrameInView:self.openBgView Width:@"35vw" Height:@"35vw" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
[UI setFrameInView:self.openImage Width:@"35%" Height:@"35%" TranslateX:@"0" TranslateY:@"0" InView:nil Position:UICenter];
|
||||
|
||||
//设置圆角
|
||||
[UI setCornerRadius:self.openView];
|
||||
[UI setCornerRadius:self.openBgView];
|
||||
[UI setGradientBorder:self.openBgView withColor:0x378fe8];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)SelEqu{
|
||||
if([self hasEqu]==NO)return;
|
||||
[Msg Select:self SourceView:self.selequButton Title:@"选择设备" Options:self.equlist SelectedHandler:^(int index) {
|
||||
if(index>0){
|
||||
self.selIndex = index;
|
||||
[_selequButton setTitle:[self.equlist[index] valueForKey:@"name"] forState:UIControlStateNormal];
|
||||
}
|
||||
}];
|
||||
}
|
||||
- (BOOL)hasEqu{
|
||||
BOOL ret = YES;
|
||||
if(self.selIndex==-2){
|
||||
ret = NO;
|
||||
//
|
||||
[self alert:@"正在获取设备,请稍候"];
|
||||
}
|
||||
else if(self.selIndex==-1){
|
||||
ret = NO;
|
||||
////是否添加设备
|
||||
[Msg MessageBox:self Msg:@"您尚未添加设备,是否立即添加?" SelectedHandler:^(int index) {
|
||||
|
||||
EquAdd *equadd = [[EquAdd alloc] init];
|
||||
[self.navigationController pushViewController:equadd animated:YES];
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
- (void)Watch{
|
||||
if([self hasEqu]==NO)return;
|
||||
[Pub getApp].callOut = [[Call alloc] init];
|
||||
[Pub getApp].callOut.CallTag = @"WATCH";
|
||||
[[Pub getApp].talk SetRemoteEqu:[self.equlist[self.selIndex] valueForKey:@"equid"]];
|
||||
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[Pub getApp].callOut];
|
||||
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
[[Pub getApp].window.rootViewController presentViewController:nav animated:YES completion:nil];
|
||||
}
|
||||
- (void)ConfigEqu{
|
||||
NSLog(@"ConfigEqu");
|
||||
if([self hasEqu]==NO)return;
|
||||
EquConfig *equconfig = [[EquConfig alloc] init];
|
||||
equconfig.equid = [self.equlist[self.selIndex] valueForKey:@"equid"];
|
||||
[self.navigationController pushViewController:equconfig animated:YES];
|
||||
}
|
||||
- (void)P2ptest{
|
||||
if([Sformat timestamp] - self.p2p_click_time<=1000){
|
||||
self.p2p_click_times ++;
|
||||
}
|
||||
else{
|
||||
self.p2p_click_times = 0;
|
||||
}
|
||||
self.p2p_click_time = [Sformat timestamp];
|
||||
if(self.p2p_click_times>5){
|
||||
[Pub getApp].p2ptest = [[P2pTest alloc] init];
|
||||
[self.navigationController pushViewController:[Pub getApp].p2ptest animated:YES];
|
||||
}
|
||||
|
||||
}
|
||||
- (void)OpenDoor{
|
||||
if([self hasEqu]==NO)return;
|
||||
|
||||
[[Pub getApp].talk SetRemoteEqu:[self.equlist[self.selIndex] valueForKey:@"equid"]];
|
||||
self.openAlert = [Msg OpendoorByPwd:self SelectedHandler:^(int index) {
|
||||
[self alert:@"请输入6位数字密码"];
|
||||
}];
|
||||
|
||||
|
||||
|
||||
}
|
||||
- (void)OpenDoorStep1:(NSString *)pwd{
|
||||
if(self.openAlert){
|
||||
[self.openAlert dismissViewControllerAnimated:YES completion:nil];
|
||||
//[[Pub getApp].talk openDoor:pwd];
|
||||
self.pwd = pwd;
|
||||
[[Pub getApp].talk watchByServer];
|
||||
|
||||
CABasicAnimation* rotationAnimation;
|
||||
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
||||
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * 1 * 1 ];
|
||||
rotationAnimation.duration = 1;
|
||||
rotationAnimation.cumulative = YES;
|
||||
rotationAnimation.repeatCount = 15.0;
|
||||
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
|
||||
|
||||
self.openBgView.hidden = NO;
|
||||
[self.openBgView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)OpenDoorStep2{
|
||||
[[Pub getApp].talk openDoor:self.pwd];
|
||||
}
|
||||
- (void)OpenDoorEnd{
|
||||
NSLog(@"OpenDoorEnd11");
|
||||
dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||||
//[self.openBgView.layer removeAllAnimations];
|
||||
[self.openBgView.layer removeAnimationForKey:@"transform.rotation.z"];
|
||||
self.openBgView.hidden = YES;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
+ (void)refEqulist:(void (^)(void)) handler{
|
||||
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
|
||||
if(tab){
|
||||
BaseNavigationController *nav = tab.viewControllers[1] ;
|
||||
Opendoor *opendoor = nav.childViewControllers[0];
|
||||
if(opendoor){
|
||||
opendoor.selIndex = -2;//未获取到设备
|
||||
[HttpManager EquList:[Pub getSysInfo].username Token:[Pub getSysInfo].token HttpResultHandler:^(NSDictionary *json) {
|
||||
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
|
||||
opendoor.equlist = [json objectForKey:@"data"];
|
||||
NSLog(@"设备数:%lu",(unsigned long)opendoor.equlist.count);
|
||||
if(opendoor.equlist.count>0){
|
||||
opendoor.selIndex = 0;
|
||||
[opendoor.selequButton setTitle:[opendoor.equlist[0] valueForKey:@"name"] forState:UIControlStateNormal];
|
||||
}
|
||||
else{
|
||||
opendoor.selIndex = -1;//没有设备
|
||||
[opendoor.selequButton setTitle:@"无设备" forState:UIControlStateNormal];
|
||||
}
|
||||
if(handler){
|
||||
handler();
|
||||
}
|
||||
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+ (NSArray *)getEqulist{
|
||||
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
|
||||
if(tab){
|
||||
BaseNavigationController *nav = tab.viewControllers[1] ;
|
||||
Opendoor *opendoor = nav.childViewControllers[0];
|
||||
if(opendoor){
|
||||
return opendoor.equlist;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSString *)EquNameById:(NSString *)equid{
|
||||
NSArray *list = [Opendoor getEqulist];
|
||||
if(list){
|
||||
for(int i=0;i<list.count;i++){
|
||||
if([equid isEqualToString:[list[i] valueForKey:@"equid"]]){
|
||||
return [list[i] valueForKey:@"name"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return equid;
|
||||
}
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark Property Accessors
|
||||
- (UIView *)rview
|
||||
{
|
||||
if (!_rview) {
|
||||
_rview = [[UIView alloc] init];
|
||||
_rview.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||||
}
|
||||
return _rview;
|
||||
}
|
||||
//- (UIView *)headView
|
||||
//{
|
||||
// if (!_headView) {
|
||||
// _headView = [[UIView alloc] init];
|
||||
// _headView.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] ;
|
||||
// }
|
||||
// return _headView;
|
||||
//}
|
||||
- (UIView *)topView
|
||||
{
|
||||
if (!_topView) {
|
||||
_topView = [[UIView alloc] init];
|
||||
_topView.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] ;
|
||||
}
|
||||
return _topView;
|
||||
}
|
||||
- (UIView *)bottomView
|
||||
{
|
||||
if (!_bottomView) {
|
||||
_bottomView = [[UIView alloc] init];
|
||||
_bottomView.backgroundColor = [UIColor whiteColor] ;
|
||||
}
|
||||
return _bottomView;
|
||||
}
|
||||
- (UILabel *)titleLabel
|
||||
{
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:18.0f];
|
||||
_titleLabel.textColor = [UIColor whiteColor];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_titleLabel.text = NSLocalizedString(@"手机开门", nil);
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UIImageView *)rightImage
|
||||
{
|
||||
if (!_rightImage) {
|
||||
_rightImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"setting"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
}
|
||||
return _rightImage;
|
||||
}
|
||||
|
||||
- (UIButton *)selequButton
|
||||
{
|
||||
if (!_selequButton) {
|
||||
_selequButton = [[UIButton alloc] init];
|
||||
[_selequButton setTitle:@"正在获取设备" forState:UIControlStateNormal];
|
||||
[_selequButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[_selequButton setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted];
|
||||
//_selequButton.backgroundColor = [UIColor colorWithRed:255/255. green:44/255. blue:44/255. alpha:0];
|
||||
[_selequButton.layer setMasksToBounds:YES];
|
||||
[_selequButton.layer setCornerRadius:25.0]; //设置矩形四个圆角半径
|
||||
//边框宽度
|
||||
[_selequButton.layer setBorderWidth:1.5];
|
||||
_selequButton.layer.borderColor = [UIColor whiteColor].CGColor;
|
||||
|
||||
}
|
||||
return _selequButton;
|
||||
}
|
||||
- (UIImageView *)watchImage
|
||||
{
|
||||
if (!_watchImage) {
|
||||
_watchImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"watch"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
[_watchImage setUserInteractionEnabled:YES];
|
||||
}
|
||||
return _watchImage;
|
||||
}
|
||||
- (UIImageView *)wave1Image
|
||||
{
|
||||
if (!_wave1Image) {
|
||||
_wave1Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wave1"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
}
|
||||
return _wave1Image;
|
||||
}
|
||||
- (UIImageView *)wave2Image
|
||||
{
|
||||
if (!_wave2Image) {
|
||||
_wave2Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wave2"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
}
|
||||
return _wave2Image;
|
||||
}
|
||||
- (UIImageView *)wave3Image
|
||||
{
|
||||
if (!_wave3Image) {
|
||||
_wave3Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wave3"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
}
|
||||
return _wave3Image;
|
||||
}
|
||||
- (UIView *)openView
|
||||
{
|
||||
if (!_openView) {
|
||||
_openView = [[UIView alloc] init];
|
||||
_openView.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] ;
|
||||
|
||||
|
||||
|
||||
}
|
||||
return _openView;
|
||||
}
|
||||
- (UIView *)openBgView
|
||||
{
|
||||
if (!_openBgView) {
|
||||
_openBgView = [[UIView alloc] init];
|
||||
_openBgView.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] ;
|
||||
_openBgView.hidden = YES;
|
||||
|
||||
|
||||
}
|
||||
return _openBgView;
|
||||
}
|
||||
- (UIImageView *)openImage
|
||||
{
|
||||
if (!_openImage) {
|
||||
_openImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock2"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)];
|
||||
}
|
||||
return _openImage;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,17 +0,0 @@
|
||||
//
|
||||
// RingCall.h
|
||||
// VoIPTest
|
||||
//
|
||||
// Created by Tg W on 17/2/21.
|
||||
// Copyright © 2017年 oopsr. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface RingCall : NSObject
|
||||
+ (instancetype)sharedMCCall;
|
||||
- (void)regsionPush;
|
||||
- (void)onCancelRing;
|
||||
- (void)onCallRing:(NSString *)CallerName;
|
||||
@end
|
||||
@ -1,89 +0,0 @@
|
||||
//
|
||||
// RingCall.m
|
||||
// VoIPTest
|
||||
//
|
||||
// Created by Tg W on 17/2/21.
|
||||
// Copyright © 2017年 oopsr. All rights reserved.
|
||||
//
|
||||
#import "RingCall.h"
|
||||
#import "VideoTalkManager.h"
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
|
||||
@interface RingCall ()<VideoCallbackDelegate>{
|
||||
UILocalNotification *callNotification;
|
||||
UNNotificationRequest *request;//ios 10
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation RingCall
|
||||
+ (instancetype)sharedMCCall {
|
||||
|
||||
static RingCall *callInstane;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
if (callInstane == nil) {
|
||||
callInstane = [[RingCall alloc] init];
|
||||
[[VideoTalkManager sharedClinet] setDelegate:callInstane];
|
||||
}
|
||||
});
|
||||
return callInstane;
|
||||
}
|
||||
|
||||
- (void)regsionPush {
|
||||
//iOS 10
|
||||
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
||||
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||||
if (!error) {
|
||||
NSLog(@"request authorization succeeded!");
|
||||
}
|
||||
}];
|
||||
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
||||
NSLog(@"%@",settings);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark-VideoCallbackDelegate
|
||||
//铃声呼叫
|
||||
- (void)onCallRing:(NSString *)CallerName {
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
|
||||
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
|
||||
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
|
||||
content.body =[NSString localizedUserNotificationStringForKey:[NSString
|
||||
stringWithFormat:@"%@", CallerName] arguments:nil];;
|
||||
UNNotificationSound *customSound = [UNNotificationSound soundNamed:@"voip_call.caf"];
|
||||
content.sound = customSound;
|
||||
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
|
||||
triggerWithTimeInterval:1 repeats:NO];
|
||||
request = [UNNotificationRequest requestWithIdentifier:@"Voip_Push"
|
||||
content:content trigger:trigger];
|
||||
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
||||
|
||||
}];
|
||||
}else {
|
||||
|
||||
callNotification = [[UILocalNotification alloc] init];
|
||||
callNotification.alertBody = [NSString
|
||||
stringWithFormat:@"%@", CallerName];
|
||||
//@"邀请你进行通话。。。。"];
|
||||
|
||||
callNotification.soundName = @"voip_call.caf";
|
||||
[[UIApplication sharedApplication]
|
||||
presentLocalNotificationNow:callNotification];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)onCancelRing {
|
||||
//取消通知栏
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
|
||||
NSMutableArray *arraylist = [[NSMutableArray alloc]init];
|
||||
[arraylist addObject:@"Voip_Push"];
|
||||
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:arraylist];
|
||||
}else {
|
||||
[[UIApplication sharedApplication] cancelLocalNotification:callNotification];
|
||||
}
|
||||
|
||||
}
|
||||
@end
|
||||
@ -1,41 +0,0 @@
|
||||
//
|
||||
// VideoTalkManager.h
|
||||
// VoIPTest
|
||||
//
|
||||
// Created by Tg W on 17/2/21.
|
||||
// Copyright © 2017年 oopsr. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@protocol VideoCallbackDelegate <NSObject>
|
||||
|
||||
/**
|
||||
* 当APP收到呼叫、处于后台时调用、用来处理通知栏类型和铃声。
|
||||
*
|
||||
* @param name 呼叫者的名字
|
||||
*/
|
||||
- (void)onCallRing:(NSString*)name;
|
||||
/**
|
||||
* 呼叫取消调用、取消通知栏
|
||||
*/
|
||||
- (void)onCancelRing;
|
||||
/**
|
||||
* APP收到呼叫、从后台回到前台时或者APP就在前台会调用、用于弹出呼叫界面。
|
||||
*
|
||||
* @param aSession 会话实体
|
||||
* @param Callername 呼叫者名字
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@interface VideoTalkManager : NSObject
|
||||
|
||||
+ (VideoTalkManager *)sharedClinet;
|
||||
|
||||
- (void)initWithSever;
|
||||
|
||||
- (void)setDelegate:(id<VideoCallbackDelegate>)delegate;
|
||||
|
||||
@end
|
||||
@ -1,131 +0,0 @@
|
||||
//
|
||||
// VideoTalkManager.m
|
||||
// VoIPTest
|
||||
//
|
||||
// Created by Tg W on 17/2/21.
|
||||
// Copyright © 2017年 oopsr. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VideoTalkManager.h"
|
||||
#import <PushKit/PushKit.h>
|
||||
#import "RingCall.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "Pub.h"
|
||||
#import "HttpManager.h"
|
||||
/**************注意事项******
|
||||
1、证书制作是否完成
|
||||
2、APP bundle identity是否替换成自己的
|
||||
3、测试推送时确保推送的设备token跟上传的设备token一致
|
||||
*************/
|
||||
@interface VideoTalkManager ()<PKPushRegistryDelegate>{
|
||||
|
||||
NSString *token;
|
||||
AppDelegate *app;
|
||||
}
|
||||
|
||||
@property (nonatomic,strong)id<VideoCallbackDelegate>mydelegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation VideoTalkManager
|
||||
|
||||
static VideoTalkManager *instance = nil;
|
||||
|
||||
+ (VideoTalkManager *)sharedClinet {
|
||||
|
||||
if (instance == nil) {
|
||||
|
||||
instance = [[super allocWithZone:NULL] init];
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
-(void)initWithSever {
|
||||
NSLog(@"initWithSever");
|
||||
//voip delegate
|
||||
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
|
||||
PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
||||
pushRegistry.delegate = self;
|
||||
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
|
||||
|
||||
//ios10注册本地通知
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
|
||||
|
||||
[[RingCall sharedMCCall] regsionPush];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<VideoCallbackDelegate>)delegate {
|
||||
|
||||
self.mydelegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -pushkitDelegate
|
||||
|
||||
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
|
||||
NSLog(@"didUpdatePushCredentials");
|
||||
if([credentials.token length] == 0) {
|
||||
NSLog(@"voip token NULL");
|
||||
return;
|
||||
}
|
||||
//应用启动获取token,并上传服务器
|
||||
NSLog(@"didUpdatePushCredentials:%@",credentials.token);
|
||||
token = [[[[credentials.token description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
|
||||
stringByReplacingOccurrencesOfString:@">" withString:@""]
|
||||
stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
//token上传服务器
|
||||
//[self uploadToken];
|
||||
[Pub getApp].sysinfo.pushkitToken = token;
|
||||
NSLog(@"didUpdatePushCredentials:%@",[Pub getApp].sysinfo.pushkitToken);
|
||||
// [HttpManager postPushkitToken:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token PushkitToken:token HttpResultHandler:^(NSDictionary *json) {
|
||||
// NSLog(@"上传token成功");
|
||||
// }];
|
||||
//[app uploadTokenWithToken:token];
|
||||
//app.pushkitToken = [NSString stringWithFormat:@"%@", token];
|
||||
//NSLog(@"get pushkit token:%@", token);
|
||||
}
|
||||
|
||||
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type{
|
||||
NSLog(@"didReceiveIncomingPushWithPayload");
|
||||
#if 1
|
||||
BOOL isCalling = false;
|
||||
switch ([UIApplication sharedApplication].applicationState) {
|
||||
case UIApplicationStateActive: {
|
||||
//isCalling = false;
|
||||
//[app onCallRing:@"jjfj"];
|
||||
isCalling = true;
|
||||
}
|
||||
break;
|
||||
case UIApplicationStateInactive: {
|
||||
//isCalling = false;
|
||||
isCalling = true;
|
||||
}
|
||||
break;
|
||||
case UIApplicationStateBackground: {
|
||||
isCalling = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
isCalling = true;
|
||||
break;
|
||||
}
|
||||
NSDictionary *dic = [payload.dictionaryPayload objectForKey:@"aps"];
|
||||
NSString *info = [dic objectForKey:@"alert"];
|
||||
if (isCalling){
|
||||
//本地通知,实现响铃效果
|
||||
//NSLog(@"%@", [dic objectForKey:@"alert"]);
|
||||
[self.mydelegate onCallRing:info];
|
||||
}
|
||||
else {
|
||||
[[RingCall sharedMCCall] onCallRing:info];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface BaseNavigationController : UINavigationController
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BaseNavigationController.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UIView+AutoLayout.h"
|
||||
#import "UI.h"
|
||||
|
||||
|
||||
|
||||
@interface BaseNavigationController ()
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BaseNavigationController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
//[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
//self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
|
||||
self.navigationBar.barTintColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];//#378fe8
|
||||
self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
||||
if (self.viewControllers.count > 0) {
|
||||
//第二级则隐藏底部Tab
|
||||
viewController.hidesBottomBarWhenPushed = YES;
|
||||
|
||||
|
||||
}
|
||||
[super pushViewController:viewController animated:animated];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@ -1,24 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface BasePageViewController : UIPageViewController
|
||||
|
||||
@property (nonatomic, strong)UIImage *navLeftImg;
|
||||
@property (nonatomic, strong)UIImage *navRightImg;
|
||||
@property (nonatomic, strong)UILabel *navMidLabel;
|
||||
@property (nonatomic, strong)UILabel *toastLabel;
|
||||
@property (nonatomic, strong)NSTimer *timer_hide_toast;
|
||||
- (void) setNavTitle:(NSString *)title;
|
||||
- (void)alert:(NSString *)msg;
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action;
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action;
|
||||
- (void)pageBack;
|
||||
@end
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BasePageViewController.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UIView+AutoLayout.h"
|
||||
#import "UI.h"
|
||||
#import "Pub.h"
|
||||
|
||||
|
||||
|
||||
@interface BasePageViewController ()
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BasePageViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[UI SetRView:self.view Top:0 Right:0 Bottom:0 Left:0];
|
||||
self.view.backgroundColor= [UI colorWithHex:0xffffff];
|
||||
int w = [UI getScreenWidth];
|
||||
int navh = [UI getNavHeight];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
self.navMidLabel = [UI NewLabel:@"" Color:[UIColor whiteColor] Size:18. Align:NSTextAlignmentCenter];
|
||||
self.navMidLabel.frame = CGRectMake(navh, 0, w-2*navh, navh);
|
||||
self.navigationItem.titleView = self.navMidLabel;
|
||||
if (self.navigationController.viewControllers.count>1) {
|
||||
[self setNavBack];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setNavTitle:(NSString *)title{
|
||||
self.navMidLabel.text = title;
|
||||
}
|
||||
|
||||
- (void)setNavBack{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:@"back"] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:@selector(pageBack)];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navRightImg){
|
||||
self.navRightImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navRightImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.rightBarButtonItem = item;
|
||||
}
|
||||
- (void)pageBack{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
- (void)toastLabel:(NSString *)msg{
|
||||
|
||||
}
|
||||
- (void)alert:(NSString *)msg{
|
||||
if([Pub getApp].activeTextField){[[Pub getApp].activeTextField resignFirstResponder];}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.toastLabel) {
|
||||
self.toastLabel = [[UILabel alloc] init];
|
||||
self.toastLabel.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:0.5];
|
||||
//_titleLabel.numberOfLines = 0;
|
||||
self.toastLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
self.toastLabel.textColor = [UIColor whiteColor];
|
||||
self.toastLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
[self.toastLabel.layer setMasksToBounds:YES];
|
||||
[self.toastLabel.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
|
||||
//[self.toastLabel.layer setBorderWidth:1.0];
|
||||
//self.toastLabel.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
//self.toastLabel.hidden = true;
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
}
|
||||
[self.view addSubview:self.toastLabel];
|
||||
[UI setFrameInView:self.toastLabel Width:@"50%" Height:@"30" TranslateX:0 TranslateY:@"10vh" InView:nil Position:UIBottomMid];
|
||||
|
||||
self.toastLabel.text = NSLocalizedString(msg, nil);
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
if(self.timer_hide_toast){
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
}
|
||||
self.timer_hide_toast = [NSTimer scheduledTimerWithTimeInterval:1.5
|
||||
target:self selector:@selector(alert_cancel)
|
||||
userInfo:nil repeats:YES];
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
- (void)alert_cancel{
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
|
||||
// CATransition *anim = [CATransition animation];
|
||||
// anim.duration = 1;
|
||||
// anim.type = kCATransitionFade;
|
||||
// [self.toastLabel.layer addAnimation:anim forKey:nil];
|
||||
|
||||
[UIView animateWithDuration:.3 animations: ^{
|
||||
self.toastLabel.layer.opacity = 0.;
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,23 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface BaseTableViewController : UITableViewController
|
||||
|
||||
@property (nonatomic, strong)UIImage *navLeftImg;
|
||||
@property (nonatomic, strong)UIImage *navRightImg;
|
||||
@property (nonatomic, strong)UILabel *navMidLabel;
|
||||
@property (nonatomic, strong)UILabel *toastLabel;
|
||||
@property (nonatomic, strong)NSTimer *timer_hide_toast;
|
||||
- (void) setNavTitle:(NSString *)title;
|
||||
- (void)alert:(NSString *)msg;
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action;
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action;
|
||||
@end
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BaseTableViewController.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UIView+AutoLayout.h"
|
||||
#import "UI.h"
|
||||
|
||||
|
||||
|
||||
@interface BaseTableViewController ()
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BaseTableViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[UI SetRView:self.view Top:0 Right:0 Bottom:0 Left:0];
|
||||
int w = [UI getScreenWidth];
|
||||
int navh = [UI getNavHeight];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
self.navMidLabel = [UI NewLabel:@"" Color:[UIColor whiteColor] Size:18. Align:NSTextAlignmentCenter];
|
||||
self.navMidLabel.frame = CGRectMake(navh, 0, w-2*navh, navh);
|
||||
self.navigationItem.titleView = self.navMidLabel;
|
||||
if (self.navigationController.viewControllers.count>1) {
|
||||
[self setNavBack];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setNavTitle:(NSString *)title{
|
||||
self.navMidLabel.text = title;
|
||||
}
|
||||
|
||||
- (void)setNavBack{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:@"back"] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:@selector(pageBack)];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navRightImg){
|
||||
self.navRightImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navRightImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.rightBarButtonItem = item;
|
||||
}
|
||||
- (void)pageBack{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
- (void)toastLabel:(NSString *)msg{
|
||||
|
||||
}
|
||||
- (void)alert:(NSString *)msg{
|
||||
if (!self.toastLabel) {
|
||||
self.toastLabel = [[UILabel alloc] init];
|
||||
self.toastLabel.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:0.5];
|
||||
//_titleLabel.numberOfLines = 0;
|
||||
self.toastLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
self.toastLabel.textColor = [UIColor whiteColor];
|
||||
self.toastLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
[self.toastLabel.layer setMasksToBounds:YES];
|
||||
[self.toastLabel.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
|
||||
//[self.toastLabel.layer setBorderWidth:1.0];
|
||||
//self.toastLabel.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
//self.toastLabel.hidden = true;
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
}
|
||||
[self.view addSubview:self.toastLabel];
|
||||
[UI setFrameInView:self.toastLabel Width:@"50%" Height:@"30" TranslateX:0 TranslateY:@"10vh" InView:nil Position:UIBottomMid];
|
||||
|
||||
self.toastLabel.text = NSLocalizedString(msg, nil);
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
if(self.timer_hide_toast){
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
}
|
||||
self.timer_hide_toast = [NSTimer scheduledTimerWithTimeInterval:1.5
|
||||
target:self selector:@selector(alert_cancel)
|
||||
userInfo:nil repeats:YES];
|
||||
}
|
||||
- (void)alert_cancel{
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
|
||||
// CATransition *anim = [CATransition animation];
|
||||
// anim.duration = 1;
|
||||
// anim.type = kCATransitionFade;
|
||||
// [self.toastLabel.layer addAnimation:anim forKey:nil];
|
||||
|
||||
[UIView animateWithDuration:.3 animations: ^{
|
||||
self.toastLabel.layer.opacity = 0.;
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,24 +0,0 @@
|
||||
//
|
||||
// FirstViewController.h
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface BaseViewController : UIViewController
|
||||
|
||||
@property (nonatomic, strong)UIImage *navLeftImg;
|
||||
@property (nonatomic, strong)UIImage *navRightImg;
|
||||
@property (nonatomic, strong)UILabel *navMidLabel;
|
||||
@property (nonatomic, strong)UILabel *toastLabel;
|
||||
@property (nonatomic, strong)NSTimer *timer_hide_toast;
|
||||
- (void) setNavTitle:(NSString *)title;
|
||||
- (void)alert:(NSString *)msg;
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action;
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action;
|
||||
- (void)pageBack;
|
||||
@end
|
||||
|
||||
@ -1,141 +0,0 @@
|
||||
//
|
||||
// FirstViewController.m
|
||||
// Talk
|
||||
//
|
||||
// Created by xuzs on 22/10/11.
|
||||
// Copyright (c) 2022年 xuzs. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import "HKHTextField.h"
|
||||
//#import "MainTabBar.h"
|
||||
#import "UIView+AutoLayout.h"
|
||||
#import "UI.h"
|
||||
#import "Pub.h"
|
||||
|
||||
|
||||
|
||||
@interface BaseViewController ()
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BaseViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
//https://juejin.cn/post/7049648953255526430
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 15.0) {
|
||||
UINavigationBarAppearance *apearance = [[UINavigationBarAppearance alloc] init];
|
||||
//apearance.configureWithOpaqueBackground;
|
||||
apearance.backgroundEffect = nil;
|
||||
apearance.backgroundImage = [UI imageWithColor:[UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] size:CGSizeMake(1.0, 1.0)];
|
||||
apearance.shadowColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];
|
||||
apearance.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];
|
||||
self.navigationController.navigationBar.standardAppearance = apearance;
|
||||
self.navigationController.navigationBar.scrollEdgeAppearance = apearance;
|
||||
}
|
||||
|
||||
|
||||
[UI SetRView:self.view Top:0 Right:0 Bottom:0 Left:0];
|
||||
self.view.backgroundColor= [UI colorWithHex:0xffffff];
|
||||
int w = [UI getScreenWidth];
|
||||
int navh = [UI getNavHeight];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
self.navMidLabel = [UI NewLabel:@"" Color:[UIColor whiteColor] Size:18. Align:NSTextAlignmentCenter];
|
||||
self.navMidLabel.frame = CGRectMake(navh, 0, w-2*navh, navh);
|
||||
self.navigationItem.titleView = self.navMidLabel;
|
||||
if (self.navigationController.viewControllers.count>1) {
|
||||
[self setNavBack];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setNavTitle:(NSString *)title{
|
||||
self.navMidLabel.text = title;
|
||||
}
|
||||
|
||||
- (void)setNavBack{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:@"back"] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:@selector(pageBack)];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavLeft:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navLeftImg){
|
||||
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.leftBarButtonItem = item;
|
||||
}
|
||||
- (void)setNavRight:(NSString *)imgname action:(SEL)action{
|
||||
if(!self.navRightImg){
|
||||
self.navRightImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
|
||||
}
|
||||
|
||||
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navRightImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
|
||||
[item setTintColor:[UIColor whiteColor]];
|
||||
self.navigationItem.rightBarButtonItem = item;
|
||||
}
|
||||
- (void)pageBack{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
- (void)toastLabel:(NSString *)msg{
|
||||
|
||||
}
|
||||
- (void)alert:(NSString *)msg{
|
||||
if([Pub getApp].activeTextField){[[Pub getApp].activeTextField resignFirstResponder];}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.toastLabel) {
|
||||
self.toastLabel = [[UILabel alloc] init];
|
||||
self.toastLabel.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:0.5];
|
||||
//_titleLabel.numberOfLines = 0;
|
||||
self.toastLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
self.toastLabel.textColor = [UIColor whiteColor];
|
||||
self.toastLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
[self.toastLabel.layer setMasksToBounds:YES];
|
||||
[self.toastLabel.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
|
||||
//[self.toastLabel.layer setBorderWidth:1.0];
|
||||
//self.toastLabel.layer.borderColor=[UIColor grayColor].CGColor;
|
||||
//self.toastLabel.hidden = true;
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
}
|
||||
[self.view addSubview:self.toastLabel];
|
||||
[UI setFrameInView:self.toastLabel Width:@"50%" Height:@"30" TranslateX:0 TranslateY:@"10vh" InView:nil Position:UIBottomMid];
|
||||
|
||||
self.toastLabel.text = NSLocalizedString(msg, nil);
|
||||
self.toastLabel.layer.opacity = 1.;
|
||||
if(self.timer_hide_toast){
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
}
|
||||
self.timer_hide_toast = [NSTimer scheduledTimerWithTimeInterval:1.5
|
||||
target:self selector:@selector(alert_cancel)
|
||||
userInfo:nil repeats:YES];
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
- (void)alert_cancel{
|
||||
[self.timer_hide_toast invalidate];
|
||||
self.timer_hide_toast = nil;
|
||||
self.toastLabel.text = NSLocalizedString(@"", nil);
|
||||
|
||||
// CATransition *anim = [CATransition animation];
|
||||
// anim.duration = 1;
|
||||
// anim.type = kCATransitionFade;
|
||||
// [self.toastLabel.layer addAnimation:anim forKey:nil];
|
||||
|
||||
[UIView animateWithDuration:.3 animations: ^{
|
||||
self.toastLabel.layer.opacity = 0.;
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,15 +0,0 @@
|
||||
//
|
||||
// HKHTextField.h
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/9/19.
|
||||
//
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface HKHTextField : UITextField
|
||||
|
||||
-(void) setMaxLength:(int)maxLen;
|
||||
|
||||
@end
|
||||
@ -1,101 +0,0 @@
|
||||
//
|
||||
// HKHTextField.m
|
||||
// myhome
|
||||
//
|
||||
// Created by hkh on 16/9/19.
|
||||
//
|
||||
//
|
||||
|
||||
#import "HKHTextField.h"
|
||||
#import "Pub.h"
|
||||
|
||||
@interface HKHTextField()
|
||||
|
||||
@property (nonatomic) int maxLength; // 可以输入的最大长度.默认值是 INT32_MAX
|
||||
@property (nonatomic) BOOL exitOnKeyReturn; // 键盘的 return/done ..etc 按下,是否隐藏键盘。 默认是 true
|
||||
@end
|
||||
|
||||
@implementation HKHTextField
|
||||
|
||||
// called by code
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self customeInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// call when init from storyboard/xib/nib file
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self customeInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// called by code
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self customeInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// 自定义属性的初始化
|
||||
-(void) customeInit {
|
||||
_maxLength = INT32_MAX;
|
||||
_exitOnKeyReturn = true;
|
||||
// return 按下,键盘隐藏
|
||||
[self addTarget:self action:@selector(onEndOnExit) forControlEvents:UIControlEventEditingDidEndOnExit];
|
||||
[self addTarget:self action:@selector(onEditingDidBegin) forControlEvents:UIControlEventEditingDidBegin];
|
||||
}
|
||||
|
||||
-(void) setMaxLength:(int)maxLen {
|
||||
_maxLength = maxLen;
|
||||
// UITextField的最大长度
|
||||
[self addTarget:self action:@selector(textDidChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
}
|
||||
|
||||
/**
|
||||
* when textfiled's text did changed, and not end editing, this action will be call.
|
||||
* At this moment, wo can check the length.
|
||||
**/
|
||||
-(void) textDidChanged:(UITextField*)tf {
|
||||
if(tf.text.length > _maxLength) {
|
||||
tf.text = [tf.text substringToIndex:_maxLength-1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* enable/disable the software keyboard hide function when user tap the keyboard return key
|
||||
*
|
||||
**/
|
||||
-(void) setExitOnKeyReturn:(BOOL)exit {
|
||||
if (exit && self.exitOnKeyReturn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exit) {
|
||||
[self customeInit];
|
||||
} else {
|
||||
_exitOnKeyReturn = false;
|
||||
[self removeTarget:self action:@selector(textDidChanged:) forControlEvents:UIControlEventEditingDidEndOnExit];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) onEditingDidBegin {
|
||||
NSLog(@"onEditingDidBegin");
|
||||
[Pub getApp].activeTextField = self;
|
||||
}
|
||||
-(void) onEndOnExit {
|
||||
[self resignFirstResponder];
|
||||
[Pub getApp].activeTextField = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -84,75 +84,51 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverFillRemaining(
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: 1.sw,
|
||||
height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
topWidget(),
|
||||
// partSectionWidget(),
|
||||
Expanded(child: bottomWidget())
|
||||
],
|
||||
),
|
||||
),
|
||||
Obx(() => Visibility(
|
||||
visible: state.iSClosedUnlockSuccessfulPopup.value,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
state.iSClosedUnlockSuccessfulPopup.value = false;
|
||||
},
|
||||
child: Container(
|
||||
width: 1.sw,
|
||||
height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: _unlockSuccessWidget(),
|
||||
),
|
||||
),
|
||||
))
|
||||
],
|
||||
return ListView(
|
||||
children: [
|
||||
Stack(children: [
|
||||
Container(
|
||||
width: 1.sw,
|
||||
height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
topWidget(),
|
||||
Expanded(child: Obx(() => bottomWidget())),
|
||||
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// children: [
|
||||
// bottomWidget(),
|
||||
// Container(
|
||||
// width: 1.sw,
|
||||
// height: 200,
|
||||
// color: Colors.white,
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => Visibility(
|
||||
visible: state.iSClosedUnlockSuccessfulPopup.value,
|
||||
// visible: true,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
state.iSClosedUnlockSuccessfulPopup.value = false;
|
||||
},
|
||||
child: Container(
|
||||
width: 1.sw,
|
||||
height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: _unlockSuccessWidget()),
|
||||
),
|
||||
))
|
||||
]),
|
||||
],
|
||||
);
|
||||
|
||||
// return ListView(
|
||||
// children: [
|
||||
// Stack(children: [
|
||||
// Container(
|
||||
// width: 1.sw,
|
||||
// height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
// color: Colors.white,
|
||||
// child: Column(
|
||||
// children: [
|
||||
// topWidget(),
|
||||
// Expanded(child: partSectionWidget()),
|
||||
// // Expanded(child: Obx(() => bottomWidget())),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// Obx(() => Visibility(
|
||||
// visible: state.iSClosedUnlockSuccessfulPopup.value,
|
||||
// // visible: true,
|
||||
// child: GestureDetector(
|
||||
// onTap: () {
|
||||
// state.iSClosedUnlockSuccessfulPopup.value = false;
|
||||
// },
|
||||
// child: Container(
|
||||
// width: 1.sw,
|
||||
// height: 1.sh - ScreenUtil().statusBarHeight * 2,
|
||||
// color: Colors.black.withOpacity(0.3),
|
||||
// child: _unlockSuccessWidget()),
|
||||
// ),
|
||||
// ))
|
||||
// ]),
|
||||
// ],
|
||||
// );
|
||||
}
|
||||
|
||||
Widget topWidget() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user