diff --git a/star_lock/android/app/build.gradle b/star_lock/android/app/build.gradle
index f2aea2f4..b8265947 100644
--- a/star_lock/android/app/build.gradle
+++ b/star_lock/android/app/build.gradle
@@ -8,7 +8,8 @@ if (localPropertiesFile.exists()) {
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
- throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
+ // throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
+ throw new Exception("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
@@ -29,6 +30,12 @@ android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
+ lintOptions{
+ checkReleaseBuilds false
+ abortOnError false
+ }
+
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
diff --git a/star_lock/android/app/src/profile/AndroidManifest.xml b/star_lock/android/app/src/profile/AndroidManifest.xml
index 90a3ec8b..8effd092 100644
--- a/star_lock/android/app/src/profile/AndroidManifest.xml
+++ b/star_lock/android/app/src/profile/AndroidManifest.xml
@@ -9,4 +9,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/star_lock/android/build.gradle b/star_lock/android/build.gradle
index eeb73c04..571c17ca 100644
--- a/star_lock/android/build.gradle
+++ b/star_lock/android/build.gradle
@@ -3,6 +3,8 @@ buildscript {
repositories {
google()
mavenCentral()
+ mavenCentral()
+ mavenLocal()
}
dependencies {
diff --git a/star_lock/ios/Podfile b/star_lock/ios/Podfile
index 2b973e42..7c55adff 100644
--- a/star_lock/ios/Podfile
+++ b/star_lock/ios/Podfile
@@ -32,6 +32,11 @@ target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
+# Plugin Pods
+source 'https://github.com/CocoaPods/Specs.git'
+source 'https://github.com/aliyun/aliyun-specs.git'
+pod 'AlicloudPush', '~> 1.9.9'
+
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
diff --git a/star_lock/ios/Podfile.lock b/star_lock/ios/Podfile.lock
index 2ddd0a42..12c4a1f2 100644
--- a/star_lock/ios/Podfile.lock
+++ b/star_lock/ios/Podfile.lock
@@ -1,6 +1,21 @@
PODS:
- aj_captcha_flutter (0.0.1):
- Flutter
+ - AlicloudPush (1.9.9.8):
+ - AlicloudSender
+ - AlicloudUT
+ - AlicloudUtils
+ - AlicloudSender (1.0.0.3):
+ - AlicloudUTDID
+ - EMASRest
+ - AlicloudUT (5.2.0.16):
+ - AlicloudUTDID
+ - AlicloudUTDID (1.5.0.94)
+ - AlicloudUtils (1.4.1):
+ - AlicloudUTDID
+ - aliyun_push (0.0.1):
+ - AlicloudPush
+ - Flutter
- AMap3DMap (9.7.0):
- AMapFoundation (>= 1.8.0)
- amap_flutter_location (0.0.1):
@@ -16,6 +31,7 @@ PODS:
- Flutter
- device_info_plus (0.0.1):
- Flutter
+ - EMASRest (11.1.1.2)
- Flutter (1.0.0)
- flutter_native_contact_picker (0.0.1):
- Flutter
@@ -44,7 +60,7 @@ PODS:
- FlutterMacOS
- permission_handler_apple (9.1.1):
- Flutter
- - Protobuf (3.24.2)
+ - Protobuf (3.24.4)
- reactive_ble_mobile (0.0.1):
- Flutter
- Protobuf (~> 3.5)
@@ -55,7 +71,7 @@ PODS:
- sqflite (0.0.3):
- Flutter
- FMDB (>= 2.7.5)
- - SwiftProtobuf (1.22.1)
+ - SwiftProtobuf (1.24.0)
- Toast (4.0.0)
- url_launcher_ios (0.0.1):
- Flutter
@@ -64,6 +80,8 @@ PODS:
DEPENDENCIES:
- aj_captcha_flutter (from `.symlinks/plugins/aj_captcha_flutter/ios`)
+ - AlicloudPush (~> 1.9.9)
+ - aliyun_push (from `.symlinks/plugins/aliyun_push/ios`)
- amap_flutter_location (from `.symlinks/plugins/amap_flutter_location/ios`)
- amap_flutter_map (from `.symlinks/plugins/amap_flutter_map/ios`)
- camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`)
@@ -84,7 +102,14 @@ DEPENDENCIES:
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)
SPEC REPOS:
- trunk:
+ https://github.com/aliyun/aliyun-specs.git:
+ - AlicloudPush
+ - AlicloudSender
+ - AlicloudUT
+ - AlicloudUTDID
+ - AlicloudUtils
+ - EMASRest
+ https://github.com/CocoaPods/Specs.git:
- AMap3DMap
- AMapFoundation
- AMapLocation
@@ -97,6 +122,8 @@ SPEC REPOS:
EXTERNAL SOURCES:
aj_captcha_flutter:
:path: ".symlinks/plugins/aj_captcha_flutter/ios"
+ aliyun_push:
+ :path: ".symlinks/plugins/aliyun_push/ios"
amap_flutter_location:
:path: ".symlinks/plugins/amap_flutter_location/ios"
amap_flutter_map:
@@ -136,6 +163,12 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
aj_captcha_flutter: dd7af1aa064bdd621ae335b819bab07309c3c023
+ AlicloudPush: 88529c9b796e4ece0601de0867b30359f55b61f7
+ AlicloudSender: 1f468b6bd962a099ffc19d45e3608b0fe98f259d
+ AlicloudUT: 6d1cf30d57d096b7e9bb4b069dd0ba6ad59a3338
+ AlicloudUTDID: 7323c443dcdf9a73e2224dc6ce51703671d7a765
+ AlicloudUtils: 873a76615bebcee8b1996f20820d366e433c3eab
+ aliyun_push: e92c2a8ca91b134bfabf7631816cce5f36e04a44
AMap3DMap: dce25dd3e51e6b92109caa7d0c97fc6055830fb3
amap_flutter_location: 44ff5beb64f42e0bf5feb402fe299dac0013af6f
amap_flutter_map: 979e54d227cedac6c7504a2151bfbf3bcf96760a
@@ -143,6 +176,7 @@ SPEC CHECKSUMS:
AMapLocation: 5248aec2455ebb5d104b367813c946430a2ee033
camera_avfoundation: 3125e8cd1a4387f6f31c6c63abb8a55892a9eeeb
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
+ EMASRest: 8df6f87836767a9415ad5cc4af739bc9d215b475
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_native_contact_picker: bd430ba0fbf82768bb50c2c52a69a65759a8f907
fluttertoast: fafc4fa4d01a6a9e4f772ecd190ffa525e9e2d9c
@@ -154,15 +188,15 @@ SPEC CHECKSUMS:
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
- Protobuf: de0b7ad27d01105fc191b77b003e74af6dbd2c2c
+ Protobuf: 351e9022fe13a6e2af00e9aefc22077cb88520f8
reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
- SwiftProtobuf: 7773c4e96a99d7b8ab7cda0fc30a883732ff93b1
+ SwiftProtobuf: bcfd2bc231cf9ae552cdc7c4e877bd3b41fe57b1
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a
-PODFILE CHECKSUM: 25020dfb9636b328cc2c56b27dc72344b9af6474
+PODFILE CHECKSUM: 0d47c2846028fdf29a51fec8e73b918bb76aa04e
COCOAPODS: 1.12.1
diff --git a/star_lock/ios/Runner.xcodeproj/project.pbxproj b/star_lock/ios/Runner.xcodeproj/project.pbxproj
index a90477c9..8d5130c6 100644
--- a/star_lock/ios/Runner.xcodeproj/project.pbxproj
+++ b/star_lock/ios/Runner.xcodeproj/project.pbxproj
@@ -10,8 +10,116 @@
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3EF1E85D6F1EE0C0DCF8449F /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09D8B2FA2B26BA5BFF31AB2A /* Pods_Runner.framework */; };
- 82BD91202ADA6FBB0018E523 /* XSFlutterManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 82BD911F2ADA6FBB0018E523 /* XSFlutterManager.m */; };
- 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
+ 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 */; };
+ 82C026992AEB6C050011FE6A /* ic_vd_mic_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026572AEB6C050011FE6A /* ic_vd_mic_on.png */; };
+ 82C0269A2AEB6C050011FE6A /* watch.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026582AEB6C050011FE6A /* watch.png */; };
+ 82C0269B2AEB6C050011FE6A /* call_menu.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026592AEB6C050011FE6A /* call_menu.png */; };
+ 82C0269C2AEB6C050011FE6A /* call_del_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265A2AEB6C050011FE6A /* call_del_on.png */; };
+ 82C0269D2AEB6C050011FE6A /* hangup.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265B2AEB6C050011FE6A /* hangup.png */; };
+ 82C0269E2AEB6C050011FE6A /* save_photo.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265C2AEB6C050011FE6A /* save_photo.png */; };
+ 82C0269F2AEB6C050011FE6A /* show_head_toast_bg.9.PNG in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265D2AEB6C050011FE6A /* show_head_toast_bg.9.PNG */; };
+ 82C026A02AEB6C050011FE6A /* search_bar_edit_normal.9.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265E2AEB6C050011FE6A /* search_bar_edit_normal.9.png */; };
+ 82C026A12AEB6C050011FE6A /* icon_close.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0265F2AEB6C050011FE6A /* icon_close.png */; };
+ 82C026A22AEB6C050011FE6A /* swicth_minus_off.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026602AEB6C050011FE6A /* swicth_minus_off.png */; };
+ 82C026A32AEB6C050011FE6A /* sidebar_background.xml in Resources */ = {isa = PBXBuildFile; fileRef = 82C026612AEB6C050011FE6A /* sidebar_background.xml */; };
+ 82C026A42AEB6C050011FE6A /* hf_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026622AEB6C050011FE6A /* hf_on.png */; };
+ 82C026A52AEB6C050011FE6A /* unlock_on2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026632AEB6C050011FE6A /* unlock_on2.png */; };
+ 82C026A62AEB6C050011FE6A /* vcontacts.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026642AEB6C050011FE6A /* vcontacts.png */; };
+ 82C026A72AEB6C050011FE6A /* zoom.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026652AEB6C050011FE6A /* zoom.png */; };
+ 82C026A82AEB6C050011FE6A /* key.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026662AEB6C050011FE6A /* key.png */; };
+ 82C026A92AEB6C050011FE6A /* lock2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026672AEB6C050011FE6A /* lock2.png */; };
+ 82C026AA2AEB6C050011FE6A /* lock.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026682AEB6C050011FE6A /* lock.png */; };
+ 82C026AB2AEB6C050011FE6A /* vcall.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026692AEB6C050011FE6A /* vcall.png */; };
+ 82C026AC2AEB6C050011FE6A /* spk.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266A2AEB6C050011FE6A /* spk.png */; };
+ 82C026AD2AEB6C050011FE6A /* blank.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266B2AEB6C050011FE6A /* blank.png */; };
+ 82C026AE2AEB6C050011FE6A /* clear.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266C2AEB6C050011FE6A /* clear.png */; };
+ 82C026AF2AEB6C050011FE6A /* rotate.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266D2AEB6C050011FE6A /* rotate.png */; };
+ 82C026B02AEB6C050011FE6A /* call_call_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266E2AEB6C050011FE6A /* call_call_on.png */; };
+ 82C026B12AEB6C050011FE6A /* call_del.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0266F2AEB6C050011FE6A /* call_del.png */; };
+ 82C026B22AEB6C050011FE6A /* swicth_minus_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026702AEB6C050011FE6A /* swicth_minus_on.png */; };
+ 82C026B32AEB6C050011FE6A /* lock_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026712AEB6C050011FE6A /* lock_on.png */; };
+ 82C026B42AEB6C050011FE6A /* vrecord_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026722AEB6C050011FE6A /* vrecord_on.png */; };
+ 82C026B52AEB6C050011FE6A /* search_bar_icon_normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026732AEB6C050011FE6A /* search_bar_icon_normal.png */; };
+ 82C026B62AEB6C050011FE6A /* vrecord.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026742AEB6C050011FE6A /* vrecord.png */; };
+ 82C026B72AEB6C050011FE6A /* swicth_off.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026752AEB6C050011FE6A /* swicth_off.png */; };
+ 82C026B82AEB6C050011FE6A /* test.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 82C026762AEB6C050011FE6A /* test.jpg */; };
+ 82C026B92AEB6C050011FE6A /* back3.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026772AEB6C050011FE6A /* back3.png */; };
+ 82C026BA2AEB6C050011FE6A /* logo3.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026782AEB6C050011FE6A /* logo3.png */; };
+ 82C026BB2AEB6C050011FE6A /* menu.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026792AEB6C050011FE6A /* menu.png */; };
+ 82C026BC2AEB6C050011FE6A /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267A2AEB6C050011FE6A /* logo.png */; };
+ 82C026BD2AEB6C050011FE6A /* logo2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267B2AEB6C050011FE6A /* logo2.png */; };
+ 82C026BE2AEB6C050011FE6A /* vcontacts2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267C2AEB6C050011FE6A /* vcontacts2.png */; };
+ 82C026BF2AEB6C050011FE6A /* swicth_add_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267D2AEB6C050011FE6A /* swicth_add_on.png */; };
+ 82C026C02AEB6C050011FE6A /* add2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267E2AEB6C050011FE6A /* add2.png */; };
+ 82C026C12AEB6C050011FE6A /* swicth_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0267F2AEB6C050011FE6A /* swicth_on.png */; };
+ 82C026C22AEB6C050011FE6A /* shop_loading.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026802AEB6C050011FE6A /* shop_loading.png */; };
+ 82C026C32AEB6C050011FE6A /* call_menu_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026812AEB6C050011FE6A /* call_menu_on.png */; };
+ 82C026C42AEB6C050011FE6A /* vcall_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026822AEB6C050011FE6A /* vcall_on.png */; };
+ 82C026C52AEB6C050011FE6A /* wave1.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026832AEB6C050011FE6A /* wave1.png */; };
+ 82C026C62AEB6C050011FE6A /* ic_launcher.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026842AEB6C050011FE6A /* ic_launcher.png */; };
+ 82C026C72AEB6C050011FE6A /* key_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026852AEB6C050011FE6A /* key_on.png */; };
+ 82C026C82AEB6C050011FE6A /* hf.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026862AEB6C050011FE6A /* hf.png */; };
+ 82C026C92AEB6C050011FE6A /* wave3.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026872AEB6C050011FE6A /* wave3.png */; };
+ 82C026CA2AEB6C050011FE6A /* wave2.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026882AEB6C050011FE6A /* wave2.png */; };
+ 82C026CB2AEB6C050011FE6A /* ic_vd_mic_off.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026892AEB6C050011FE6A /* ic_vd_mic_off.png */; };
+ 82C026CC2AEB6C050011FE6A /* split3.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268A2AEB6C050011FE6A /* split3.png */; };
+ 82C026CD2AEB6C050011FE6A /* emotionstore_progresscancelbtn.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268B2AEB6C050011FE6A /* emotionstore_progresscancelbtn.png */; };
+ 82C026CE2AEB6C050011FE6A /* split.JPG in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268C2AEB6C050011FE6A /* split.JPG */; };
+ 82C026CF2AEB6C050011FE6A /* swicth_add_off.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268D2AEB6C050011FE6A /* swicth_add_off.png */; };
+ 82C026D02AEB6C050011FE6A /* search_bar_edit_pressed.9.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268E2AEB6C050011FE6A /* search_bar_edit_pressed.9.png */; };
+ 82C026D12AEB6C050011FE6A /* setting.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C0268F2AEB6C050011FE6A /* setting.png */; };
+ 82C026D22AEB6C050011FE6A /* back.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026902AEB6C050011FE6A /* back.png */; };
+ 82C026D32AEB6C050011FE6A /* thumb_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026912AEB6C050011FE6A /* thumb_on.png */; };
+ 82C026D42AEB6C050011FE6A /* split4.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026922AEB6C050011FE6A /* split4.png */; };
+ 82C026D52AEB6C050011FE6A /* thumb.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026932AEB6C050011FE6A /* thumb.png */; };
+ 82C026D62AEB6C050011FE6A /* vcontacts_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026942AEB6C050011FE6A /* vcontacts_on.png */; };
+ 82C026D72AEB6C050011FE6A /* mic.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026952AEB6C050011FE6A /* mic.png */; };
+ 82C026D82AEB6C050011FE6A /* icon_key.png in Resources */ = {isa = PBXBuildFile; fileRef = 82C026962AEB6C050011FE6A /* icon_key.png */; };
+ 82C026D92AEB6C050011FE6A /* bg.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 82C026972AEB6C050011FE6A /* bg.jpg */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
@@ -38,11 +146,153 @@
33BF41252A96174D009D92E2 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; };
- 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
- 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
- 82BD911E2ADA6FBB0018E523 /* XSFlutterManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSFlutterManager.h; sourceTree = ""; };
- 82BD911F2ADA6FBB0018E523 /* XSFlutterManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSFlutterManager.m; sourceTree = ""; };
+ 8297E40E2AE75AC500E886FA /* XSFlutterManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XSFlutterManager.m; sourceTree = ""; };
+ 8297E40F2AE75AC500E886FA /* XSFlutterManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSFlutterManager.h; sourceTree = ""; };
+ 8297E4132AE75BEE00E886FA /* Msg.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Msg.m; sourceTree = ""; };
+ 8297E4142AE75BEE00E886FA /* UI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UI.h; sourceTree = ""; };
+ 8297E4152AE75BEE00E886FA /* HttpManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HttpManager.h; sourceTree = ""; };
+ 8297E4172AE75BEE00E886FA /* udp_data_class.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = udp_data_class.m; sourceTree = ""; };
+ 8297E4182AE75BEE00E886FA /* UdpHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UdpHelper.m; sourceTree = ""; };
+ 8297E4192AE75BEE00E886FA /* udp_data_class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = udp_data_class.h; sourceTree = ""; };
+ 8297E41A2AE75BEE00E886FA /* UdpHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UdpHelper.h; sourceTree = ""; };
+ 8297E41B2AE75BEE00E886FA /* Sformat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sformat.m; sourceTree = ""; };
+ 8297E41C2AE75BEE00E886FA /* Pub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pub.h; sourceTree = ""; };
+ 8297E41D2AE75BEE00E886FA /* sysInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sysInfo.h; sourceTree = ""; };
+ 8297E41E2AE75BEE00E886FA /* Msg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Msg.h; sourceTree = ""; };
+ 8297E41F2AE75BEE00E886FA /* Sformat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sformat.h; sourceTree = ""; };
+ 8297E4202AE75BEE00E886FA /* HttpManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HttpManager.m; sourceTree = ""; };
+ 8297E4212AE75BEE00E886FA /* UI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UI.m; sourceTree = ""; };
+ 8297E4222AE75BEE00E886FA /* sysInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = sysInfo.m; sourceTree = ""; };
+ 8297E4232AE75BEE00E886FA /* Pub.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Pub.m; sourceTree = ""; };
+ 8297E4252AE75BEE00E886FA /* recordAudio.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = recordAudio.m; sourceTree = ""; };
+ 8297E4262AE75BEE00E886FA /* talk_Class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = talk_Class.h; sourceTree = ""; };
+ 8297E4272AE75BEE00E886FA /* IframeInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IframeInfo.h; sourceTree = ""; };
+ 8297E4282AE75BEE00E886FA /* playAudio.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = playAudio.m; sourceTree = ""; };
+ 8297E4292AE75BEE00E886FA /* recordAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recordAudio.h; sourceTree = ""; };
+ 8297E42A2AE75BEE00E886FA /* talk_Class.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = talk_Class.m; sourceTree = ""; };
+ 8297E42B2AE75BEE00E886FA /* playAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = playAudio.h; sourceTree = ""; };
+ 8297E42C2AE75BEE00E886FA /* IframeInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IframeInfo.m; sourceTree = ""; };
+ 8297E42E2AE75BEE00E886FA /* Piano.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Piano.caf; sourceTree = ""; };
+ 8297E42F2AE75BEE00E886FA /* ring1.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = ring1.mp3; sourceTree = ""; };
+ 8297E4302AE75BEE00E886FA /* ok.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = ok.wav; sourceTree = ""; };
+ 8297E4312AE75BEE00E886FA /* notice.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = notice.wav; sourceTree = ""; };
+ 8297E4322AE75BEE00E886FA /* err.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = err.wav; sourceTree = ""; };
+ 8297E4332AE75BEE00E886FA /* alarm.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = alarm.wav; sourceTree = ""; };
+ 8297E4352AE75BEE00E886FA /* VideoTalkManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoTalkManager.h; sourceTree = ""; };
+ 8297E4362AE75BEE00E886FA /* RingCall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RingCall.m; sourceTree = ""; };
+ 8297E4372AE75BEE00E886FA /* RingCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RingCall.h; sourceTree = ""; };
+ 8297E4382AE75BEE00E886FA /* VideoTalkManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoTalkManager.m; sourceTree = ""; };
+ 8297E4392AE75BEE00E886FA /* voip_call.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = voip_call.caf; sourceTree = ""; };
+ 8297E4502AE75D4E00E886FA /* EquList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquList.h; sourceTree = ""; };
+ 8297E4512AE75D4E00E886FA /* EquAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquAdd.h; sourceTree = ""; };
+ 8297E4522AE75D4E00E886FA /* FaceUpload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FaceUpload.h; sourceTree = ""; };
+ 8297E4532AE75D4E00E886FA /* WifiList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WifiList.h; sourceTree = ""; };
+ 8297E4542AE75D4E00E886FA /* FaceSubPage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FaceSubPage.m; sourceTree = ""; };
+ 8297E4552AE75D4E00E886FA /* EquConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquConfig.m; sourceTree = ""; };
+ 8297E4562AE75D4E00E886FA /* OpenPwd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenPwd.m; sourceTree = ""; };
+ 8297E4572AE75D4E00E886FA /* P2pTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = P2pTest.h; sourceTree = ""; };
+ 8297E4582AE75D4E00E886FA /* Web.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Web.m; sourceTree = ""; };
+ 8297E4592AE75D4E00E886FA /* Call.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Call.h; sourceTree = ""; };
+ 8297E45A2AE75D4E00E886FA /* Setting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Setting.m; sourceTree = ""; };
+ 8297E45B2AE75D4E00E886FA /* FaceUpload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FaceUpload.m; sourceTree = ""; };
+ 8297E45C2AE75D4E00E886FA /* EquAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquAdd.m; sourceTree = ""; };
+ 8297E45D2AE75D4E00E886FA /* EquList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EquList.m; sourceTree = ""; };
+ 8297E45E2AE75D4E00E886FA /* FaceSubPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FaceSubPage.h; sourceTree = ""; };
+ 8297E45F2AE75D4E00E886FA /* WifiList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WifiList.m; sourceTree = ""; };
+ 8297E4602AE75D4E00E886FA /* OpenPwd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenPwd.h; sourceTree = ""; };
+ 8297E4612AE75D4E00E886FA /* P2pTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = P2pTest.m; sourceTree = ""; };
+ 8297E4622AE75D4E00E886FA /* EquConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EquConfig.h; sourceTree = ""; };
+ 8297E4632AE75D4E00E886FA /* Setting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Setting.h; sourceTree = ""; };
+ 8297E4642AE75D4E00E886FA /* Call.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Call.m; sourceTree = ""; };
+ 8297E4652AE75D4E00E886FA /* Web.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Web.h; sourceTree = ""; };
+ 8297E4722AE761EB00E886FA /* BaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseViewController.m; sourceTree = ""; };
+ 8297E4732AE761EB00E886FA /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = ""; };
+ 8297E4762AE7635400E886FA /* Opendoor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Opendoor.h; sourceTree = ""; };
+ 8297E4772AE7635400E886FA /* Opendoor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Opendoor.m; sourceTree = ""; };
+ 8297E47A2AE7643100E886FA /* AsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncUdpSocket.m; sourceTree = ""; };
+ 8297E47B2AE7643100E886FA /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncSocket.h; sourceTree = ""; };
+ 8297E47C2AE7643100E886FA /* UIView+AutoLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AutoLayout.m"; sourceTree = ""; };
+ 8297E47D2AE7643100E886FA /* UIView+AutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AutoLayout.h"; sourceTree = ""; };
+ 8297E47E2AE7643100E886FA /* AsyncSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncSocket.m; sourceTree = ""; };
+ 8297E47F2AE7643100E886FA /* AsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncUdpSocket.h; sourceTree = ""; };
+ 8297E4862AE768DE00E886FA /* BaseNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = ""; };
+ 8297E4872AE768DE00E886FA /* BaseNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = ""; };
+ 8297E48C2AE76D0500E886FA /* BaseTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseTableViewController.h; sourceTree = ""; };
+ 8297E48D2AE76D0500E886FA /* BaseTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseTableViewController.m; sourceTree = ""; };
+ 8297E48F2AE76DD500E886FA /* BasePageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasePageViewController.h; sourceTree = ""; };
+ 8297E4902AE76DD500E886FA /* BasePageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BasePageViewController.m; sourceTree = ""; };
+ 8297E4932AE76EC700E886FA /* HKHTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HKHTextField.h; sourceTree = ""; };
+ 8297E4942AE76EC700E886FA /* HKHTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HKHTextField.m; sourceTree = ""; };
+ 8297E4992AE7974700E886FA /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
+ 8297E49A2AE7974700E886FA /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
82BD91212ADA72360018E523 /* CommonDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonDefine.h; sourceTree = ""; };
+ 82C026532AE8AC6D0011FE6A /* AliyunEmasServices-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "AliyunEmasServices-Info.plist"; sourceTree = ""; };
+ 82C026562AEB6C050011FE6A /* add.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = add.png; sourceTree = ""; };
+ 82C026572AEB6C050011FE6A /* ic_vd_mic_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_vd_mic_on.png; sourceTree = ""; };
+ 82C026582AEB6C050011FE6A /* watch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = watch.png; sourceTree = ""; };
+ 82C026592AEB6C050011FE6A /* call_menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = call_menu.png; sourceTree = ""; };
+ 82C0265A2AEB6C050011FE6A /* call_del_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = call_del_on.png; sourceTree = ""; };
+ 82C0265B2AEB6C050011FE6A /* hangup.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = hangup.png; sourceTree = ""; };
+ 82C0265C2AEB6C050011FE6A /* save_photo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = save_photo.png; sourceTree = ""; };
+ 82C0265D2AEB6C050011FE6A /* show_head_toast_bg.9.PNG */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = show_head_toast_bg.9.PNG; sourceTree = ""; };
+ 82C0265E2AEB6C050011FE6A /* search_bar_edit_normal.9.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search_bar_edit_normal.9.png; sourceTree = ""; };
+ 82C0265F2AEB6C050011FE6A /* icon_close.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_close.png; sourceTree = ""; };
+ 82C026602AEB6C050011FE6A /* swicth_minus_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_minus_off.png; sourceTree = ""; };
+ 82C026612AEB6C050011FE6A /* sidebar_background.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sidebar_background.xml; sourceTree = ""; };
+ 82C026622AEB6C050011FE6A /* hf_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = hf_on.png; sourceTree = ""; };
+ 82C026632AEB6C050011FE6A /* unlock_on2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = unlock_on2.png; sourceTree = ""; };
+ 82C026642AEB6C050011FE6A /* vcontacts.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vcontacts.png; sourceTree = ""; };
+ 82C026652AEB6C050011FE6A /* zoom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zoom.png; sourceTree = ""; };
+ 82C026662AEB6C050011FE6A /* key.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = key.png; sourceTree = ""; };
+ 82C026672AEB6C050011FE6A /* lock2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = lock2.png; sourceTree = ""; };
+ 82C026682AEB6C050011FE6A /* lock.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = lock.png; sourceTree = ""; };
+ 82C026692AEB6C050011FE6A /* vcall.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vcall.png; sourceTree = ""; };
+ 82C0266A2AEB6C050011FE6A /* spk.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spk.png; sourceTree = ""; };
+ 82C0266B2AEB6C050011FE6A /* blank.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blank.png; sourceTree = ""; };
+ 82C0266C2AEB6C050011FE6A /* clear.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = clear.png; sourceTree = ""; };
+ 82C0266D2AEB6C050011FE6A /* rotate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rotate.png; sourceTree = ""; };
+ 82C0266E2AEB6C050011FE6A /* call_call_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = call_call_on.png; sourceTree = ""; };
+ 82C0266F2AEB6C050011FE6A /* call_del.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = call_del.png; sourceTree = ""; };
+ 82C026702AEB6C050011FE6A /* swicth_minus_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_minus_on.png; sourceTree = ""; };
+ 82C026712AEB6C050011FE6A /* lock_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = lock_on.png; sourceTree = ""; };
+ 82C026722AEB6C050011FE6A /* vrecord_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vrecord_on.png; sourceTree = ""; };
+ 82C026732AEB6C050011FE6A /* search_bar_icon_normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search_bar_icon_normal.png; sourceTree = ""; };
+ 82C026742AEB6C050011FE6A /* vrecord.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vrecord.png; sourceTree = ""; };
+ 82C026752AEB6C050011FE6A /* swicth_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_off.png; sourceTree = ""; };
+ 82C026762AEB6C050011FE6A /* test.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = test.jpg; sourceTree = ""; };
+ 82C026772AEB6C050011FE6A /* back3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = back3.png; sourceTree = ""; };
+ 82C026782AEB6C050011FE6A /* logo3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo3.png; sourceTree = ""; };
+ 82C026792AEB6C050011FE6A /* menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu.png; sourceTree = ""; };
+ 82C0267A2AEB6C050011FE6A /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; };
+ 82C0267B2AEB6C050011FE6A /* logo2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo2.png; sourceTree = ""; };
+ 82C0267C2AEB6C050011FE6A /* vcontacts2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vcontacts2.png; sourceTree = ""; };
+ 82C0267D2AEB6C050011FE6A /* swicth_add_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_add_on.png; sourceTree = ""; };
+ 82C0267E2AEB6C050011FE6A /* add2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = add2.png; sourceTree = ""; };
+ 82C0267F2AEB6C050011FE6A /* swicth_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_on.png; sourceTree = ""; };
+ 82C026802AEB6C050011FE6A /* shop_loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = shop_loading.png; sourceTree = ""; };
+ 82C026812AEB6C050011FE6A /* call_menu_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = call_menu_on.png; sourceTree = ""; };
+ 82C026822AEB6C050011FE6A /* vcall_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vcall_on.png; sourceTree = ""; };
+ 82C026832AEB6C050011FE6A /* wave1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wave1.png; sourceTree = ""; };
+ 82C026842AEB6C050011FE6A /* ic_launcher.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_launcher.png; sourceTree = ""; };
+ 82C026852AEB6C050011FE6A /* key_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = key_on.png; sourceTree = ""; };
+ 82C026862AEB6C050011FE6A /* hf.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = hf.png; sourceTree = ""; };
+ 82C026872AEB6C050011FE6A /* wave3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wave3.png; sourceTree = ""; };
+ 82C026882AEB6C050011FE6A /* wave2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wave2.png; sourceTree = ""; };
+ 82C026892AEB6C050011FE6A /* ic_vd_mic_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_vd_mic_off.png; sourceTree = ""; };
+ 82C0268A2AEB6C050011FE6A /* split3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = split3.png; sourceTree = ""; };
+ 82C0268B2AEB6C050011FE6A /* emotionstore_progresscancelbtn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = emotionstore_progresscancelbtn.png; sourceTree = ""; };
+ 82C0268C2AEB6C050011FE6A /* split.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = split.JPG; sourceTree = ""; };
+ 82C0268D2AEB6C050011FE6A /* swicth_add_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = swicth_add_off.png; sourceTree = ""; };
+ 82C0268E2AEB6C050011FE6A /* search_bar_edit_pressed.9.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search_bar_edit_pressed.9.png; sourceTree = ""; };
+ 82C0268F2AEB6C050011FE6A /* setting.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = setting.png; sourceTree = ""; };
+ 82C026902AEB6C050011FE6A /* back.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = back.png; sourceTree = ""; };
+ 82C026912AEB6C050011FE6A /* thumb_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = thumb_on.png; sourceTree = ""; };
+ 82C026922AEB6C050011FE6A /* split4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = split4.png; sourceTree = ""; };
+ 82C026932AEB6C050011FE6A /* thumb.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = thumb.png; sourceTree = ""; };
+ 82C026942AEB6C050011FE6A /* vcontacts_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = vcontacts_on.png; sourceTree = ""; };
+ 82C026952AEB6C050011FE6A /* mic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mic.png; sourceTree = ""; };
+ 82C026962AEB6C050011FE6A /* icon_key.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_key.png; sourceTree = ""; };
+ 82C026972AEB6C050011FE6A /* bg.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = bg.jpg; sourceTree = ""; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -78,13 +328,239 @@
path = Pods;
sourceTree = "";
};
- 826570C02ADCDD0200A92776 /* XSController */ = {
+ 8297E4112AE75BEE00E886FA /* XSTalkManager */ = {
isa = PBXGroup;
children = (
- 82BD911E2ADA6FBB0018E523 /* XSFlutterManager.h */,
- 82BD911F2ADA6FBB0018E523 /* XSFlutterManager.m */,
+ 8297E4792AE7643100E886FA /* External */,
+ 8297E4752AE7635400E886FA /* mainPage */,
+ 8297E4712AE761EB00E886FA /* views */,
+ 8297E44F2AE75D4E00E886FA /* NextPage */,
+ 8297E4122AE75BEE00E886FA /* Utils */,
+ 8297E42D2AE75BEE00E886FA /* sound */,
+ 8297E4342AE75BEE00E886FA /* pushkit */,
);
- name = XSController;
+ path = XSTalkManager;
+ sourceTree = "";
+ };
+ 8297E4122AE75BEE00E886FA /* Utils */ = {
+ isa = PBXGroup;
+ children = (
+ 8297E4132AE75BEE00E886FA /* Msg.m */,
+ 8297E4142AE75BEE00E886FA /* UI.h */,
+ 8297E4152AE75BEE00E886FA /* HttpManager.h */,
+ 8297E4162AE75BEE00E886FA /* UDP */,
+ 8297E41B2AE75BEE00E886FA /* Sformat.m */,
+ 8297E41C2AE75BEE00E886FA /* Pub.h */,
+ 8297E41D2AE75BEE00E886FA /* sysInfo.h */,
+ 8297E41E2AE75BEE00E886FA /* Msg.h */,
+ 8297E41F2AE75BEE00E886FA /* Sformat.h */,
+ 8297E4202AE75BEE00E886FA /* HttpManager.m */,
+ 8297E4212AE75BEE00E886FA /* UI.m */,
+ 8297E4222AE75BEE00E886FA /* sysInfo.m */,
+ 8297E4232AE75BEE00E886FA /* Pub.m */,
+ 8297E4242AE75BEE00E886FA /* Talk */,
+ );
+ path = Utils;
+ sourceTree = "";
+ };
+ 8297E4162AE75BEE00E886FA /* UDP */ = {
+ isa = PBXGroup;
+ children = (
+ 8297E4192AE75BEE00E886FA /* udp_data_class.h */,
+ 8297E4172AE75BEE00E886FA /* udp_data_class.m */,
+ 8297E41A2AE75BEE00E886FA /* UdpHelper.h */,
+ 8297E4182AE75BEE00E886FA /* UdpHelper.m */,
+ );
+ path = UDP;
+ sourceTree = "";
+ };
+ 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 = "";
+ };
+ 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 = "";
+ };
+ 8297E4342AE75BEE00E886FA /* pushkit */ = {
+ isa = PBXGroup;
+ children = (
+ 8297E4352AE75BEE00E886FA /* VideoTalkManager.h */,
+ 8297E4362AE75BEE00E886FA /* RingCall.m */,
+ 8297E4372AE75BEE00E886FA /* RingCall.h */,
+ 8297E4382AE75BEE00E886FA /* VideoTalkManager.m */,
+ 8297E4392AE75BEE00E886FA /* voip_call.caf */,
+ );
+ path = pushkit;
+ sourceTree = "";
+ };
+ 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 */,
+ 8297E4592AE75D4E00E886FA /* Call.h */,
+ 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 */,
+ 8297E4642AE75D4E00E886FA /* Call.m */,
+ 8297E4652AE75D4E00E886FA /* Web.h */,
+ );
+ path = NextPage;
+ sourceTree = "";
+ };
+ 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 = "";
+ };
+ 8297E4752AE7635400E886FA /* mainPage */ = {
+ isa = PBXGroup;
+ children = (
+ 8297E4762AE7635400E886FA /* Opendoor.h */,
+ 8297E4772AE7635400E886FA /* Opendoor.m */,
+ );
+ path = mainPage;
+ sourceTree = "";
+ };
+ 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 = "";
+ };
+ 8297E4922AE76EC700E886FA /* TextField */ = {
+ isa = PBXGroup;
+ children = (
+ 8297E4932AE76EC700E886FA /* HKHTextField.h */,
+ 8297E4942AE76EC700E886FA /* HKHTextField.m */,
+ );
+ path = TextField;
+ sourceTree = "";
+ };
+ 82C026552AEB6C050011FE6A /* img */ = {
+ isa = PBXGroup;
+ children = (
+ 82C026562AEB6C050011FE6A /* add.png */,
+ 82C026572AEB6C050011FE6A /* ic_vd_mic_on.png */,
+ 82C026582AEB6C050011FE6A /* watch.png */,
+ 82C026592AEB6C050011FE6A /* call_menu.png */,
+ 82C0265A2AEB6C050011FE6A /* call_del_on.png */,
+ 82C0265B2AEB6C050011FE6A /* hangup.png */,
+ 82C0265C2AEB6C050011FE6A /* save_photo.png */,
+ 82C0265D2AEB6C050011FE6A /* show_head_toast_bg.9.PNG */,
+ 82C0265E2AEB6C050011FE6A /* search_bar_edit_normal.9.png */,
+ 82C0265F2AEB6C050011FE6A /* icon_close.png */,
+ 82C026602AEB6C050011FE6A /* swicth_minus_off.png */,
+ 82C026612AEB6C050011FE6A /* sidebar_background.xml */,
+ 82C026622AEB6C050011FE6A /* hf_on.png */,
+ 82C026632AEB6C050011FE6A /* unlock_on2.png */,
+ 82C026642AEB6C050011FE6A /* vcontacts.png */,
+ 82C026652AEB6C050011FE6A /* zoom.png */,
+ 82C026662AEB6C050011FE6A /* key.png */,
+ 82C026672AEB6C050011FE6A /* lock2.png */,
+ 82C026682AEB6C050011FE6A /* lock.png */,
+ 82C026692AEB6C050011FE6A /* vcall.png */,
+ 82C0266A2AEB6C050011FE6A /* spk.png */,
+ 82C0266B2AEB6C050011FE6A /* blank.png */,
+ 82C0266C2AEB6C050011FE6A /* clear.png */,
+ 82C0266D2AEB6C050011FE6A /* rotate.png */,
+ 82C0266E2AEB6C050011FE6A /* call_call_on.png */,
+ 82C0266F2AEB6C050011FE6A /* call_del.png */,
+ 82C026702AEB6C050011FE6A /* swicth_minus_on.png */,
+ 82C026712AEB6C050011FE6A /* lock_on.png */,
+ 82C026722AEB6C050011FE6A /* vrecord_on.png */,
+ 82C026732AEB6C050011FE6A /* search_bar_icon_normal.png */,
+ 82C026742AEB6C050011FE6A /* vrecord.png */,
+ 82C026752AEB6C050011FE6A /* swicth_off.png */,
+ 82C026762AEB6C050011FE6A /* test.jpg */,
+ 82C026772AEB6C050011FE6A /* back3.png */,
+ 82C026782AEB6C050011FE6A /* logo3.png */,
+ 82C026792AEB6C050011FE6A /* menu.png */,
+ 82C0267A2AEB6C050011FE6A /* logo.png */,
+ 82C0267B2AEB6C050011FE6A /* logo2.png */,
+ 82C0267C2AEB6C050011FE6A /* vcontacts2.png */,
+ 82C0267D2AEB6C050011FE6A /* swicth_add_on.png */,
+ 82C0267E2AEB6C050011FE6A /* add2.png */,
+ 82C0267F2AEB6C050011FE6A /* swicth_on.png */,
+ 82C026802AEB6C050011FE6A /* shop_loading.png */,
+ 82C026812AEB6C050011FE6A /* call_menu_on.png */,
+ 82C026822AEB6C050011FE6A /* vcall_on.png */,
+ 82C026832AEB6C050011FE6A /* wave1.png */,
+ 82C026842AEB6C050011FE6A /* ic_launcher.png */,
+ 82C026852AEB6C050011FE6A /* key_on.png */,
+ 82C026862AEB6C050011FE6A /* hf.png */,
+ 82C026872AEB6C050011FE6A /* wave3.png */,
+ 82C026882AEB6C050011FE6A /* wave2.png */,
+ 82C026892AEB6C050011FE6A /* ic_vd_mic_off.png */,
+ 82C0268A2AEB6C050011FE6A /* split3.png */,
+ 82C0268B2AEB6C050011FE6A /* emotionstore_progresscancelbtn.png */,
+ 82C0268C2AEB6C050011FE6A /* split.JPG */,
+ 82C0268D2AEB6C050011FE6A /* swicth_add_off.png */,
+ 82C0268E2AEB6C050011FE6A /* search_bar_edit_pressed.9.png */,
+ 82C0268F2AEB6C050011FE6A /* setting.png */,
+ 82C026902AEB6C050011FE6A /* back.png */,
+ 82C026912AEB6C050011FE6A /* thumb_on.png */,
+ 82C026922AEB6C050011FE6A /* split4.png */,
+ 82C026932AEB6C050011FE6A /* thumb.png */,
+ 82C026942AEB6C050011FE6A /* vcontacts_on.png */,
+ 82C026952AEB6C050011FE6A /* mic.png */,
+ 82C026962AEB6C050011FE6A /* icon_key.png */,
+ 82C026972AEB6C050011FE6A /* bg.jpg */,
+ );
+ path = img;
sourceTree = "";
};
9304F75C378DB3447BB2408C /* Frameworks */ = {
@@ -128,10 +604,14 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
- 826570C02ADCDD0200A92776 /* XSController */,
+ 82C026552AEB6C050011FE6A /* img */,
+ 82C026532AE8AC6D0011FE6A /* AliyunEmasServices-Info.plist */,
+ 8297E4992AE7974700E886FA /* AppDelegate.h */,
+ 8297E49A2AE7974700E886FA /* AppDelegate.m */,
+ 8297E40F2AE75AC500E886FA /* XSFlutterManager.h */,
+ 8297E40E2AE75AC500E886FA /* XSFlutterManager.m */,
+ 8297E4112AE75BEE00E886FA /* XSTalkManager */,
33BF41252A96174D009D92E2 /* Runner.entitlements */,
- 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
- 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
@@ -215,10 +695,84 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 82C026A02AEB6C050011FE6A /* search_bar_edit_normal.9.png in Resources */,
+ 82C026A92AEB6C050011FE6A /* lock2.png in Resources */,
+ 82C026AE2AEB6C050011FE6A /* clear.png in Resources */,
+ 82C0269B2AEB6C050011FE6A /* call_menu.png in Resources */,
+ 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 */,
+ 82C026BF2AEB6C050011FE6A /* swicth_add_on.png in Resources */,
+ 82C026A52AEB6C050011FE6A /* unlock_on2.png in Resources */,
+ 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 */,
+ 82C026992AEB6C050011FE6A /* ic_vd_mic_on.png in Resources */,
+ 82C026C12AEB6C050011FE6A /* swicth_on.png in Resources */,
+ 82C026B72AEB6C050011FE6A /* swicth_off.png in Resources */,
+ 82C026D72AEB6C050011FE6A /* mic.png in Resources */,
+ 82C026C32AEB6C050011FE6A /* call_menu_on.png in Resources */,
+ 82C026B02AEB6C050011FE6A /* call_call_on.png in Resources */,
+ 82C026C82AEB6C050011FE6A /* hf.png in Resources */,
+ 82C026BE2AEB6C050011FE6A /* vcontacts2.png in Resources */,
+ 82C026AC2AEB6C050011FE6A /* spk.png in Resources */,
+ 82C026D12AEB6C050011FE6A /* setting.png in Resources */,
+ 82C026D82AEB6C050011FE6A /* icon_key.png in Resources */,
+ 82C026C42AEB6C050011FE6A /* vcall_on.png in Resources */,
+ 82C026982AEB6C050011FE6A /* add.png in Resources */,
+ 82C026D22AEB6C050011FE6A /* back.png in Resources */,
+ 82C0269C2AEB6C050011FE6A /* call_del_on.png in Resources */,
+ 82C026B92AEB6C050011FE6A /* back3.png in Resources */,
+ 82C026C02AEB6C050011FE6A /* add2.png in Resources */,
+ 82C026BB2AEB6C050011FE6A /* menu.png in Resources */,
+ 82C026AA2AEB6C050011FE6A /* lock.png in Resources */,
+ 82C026CC2AEB6C050011FE6A /* split3.png in Resources */,
+ 82C026D92AEB6C050011FE6A /* bg.jpg in Resources */,
+ 82C026B82AEB6C050011FE6A /* test.jpg in Resources */,
+ 82C026B12AEB6C050011FE6A /* call_del.png in Resources */,
+ 82C026B52AEB6C050011FE6A /* search_bar_icon_normal.png in Resources */,
+ 82C026CA2AEB6C050011FE6A /* wave2.png in Resources */,
+ 82C0269D2AEB6C050011FE6A /* hangup.png in Resources */,
+ 82C0269A2AEB6C050011FE6A /* watch.png in Resources */,
+ 82C0269E2AEB6C050011FE6A /* save_photo.png in Resources */,
+ 82C026A62AEB6C050011FE6A /* vcontacts.png in Resources */,
+ 82C026C72AEB6C050011FE6A /* key_on.png in Resources */,
+ 82C026D52AEB6C050011FE6A /* thumb.png in Resources */,
+ 82C026B32AEB6C050011FE6A /* lock_on.png in Resources */,
+ 82C026A32AEB6C050011FE6A /* sidebar_background.xml in Resources */,
+ 82C026CF2AEB6C050011FE6A /* swicth_add_off.png in Resources */,
+ 82C026A22AEB6C050011FE6A /* swicth_minus_off.png in Resources */,
+ 82C026A42AEB6C050011FE6A /* hf_on.png in Resources */,
+ 82C026C92AEB6C050011FE6A /* wave3.png in Resources */,
+ 82C026D02AEB6C050011FE6A /* search_bar_edit_pressed.9.png in Resources */,
+ 82C026A82AEB6C050011FE6A /* key.png in Resources */,
+ 82C026CB2AEB6C050011FE6A /* ic_vd_mic_off.png in Resources */,
+ 82C026CD2AEB6C050011FE6A /* emotionstore_progresscancelbtn.png in Resources */,
+ 82C026D32AEB6C050011FE6A /* thumb_on.png in Resources */,
+ 82C026BC2AEB6C050011FE6A /* logo.png in Resources */,
+ 82C026B42AEB6C050011FE6A /* vrecord_on.png in Resources */,
+ 82C026C52AEB6C050011FE6A /* wave1.png in Resources */,
+ 82C026B62AEB6C050011FE6A /* vrecord.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -261,7 +815,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
+ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n";
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
@@ -276,7 +830,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
+ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
};
D9B107A6B141D5F15BC356F2 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
@@ -302,10 +856,44 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
- 82BD91202ADA6FBB0018E523 /* XSFlutterManager.m in Sources */,
+ 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;
};
@@ -393,15 +981,125 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
- DEVELOPMENT_TEAM = DWNXC92BQ6;
+ DEVELOPMENT_TEAM = 7D53BZAN75;
ENABLE_BITCODE = NO;
+ GCC_NO_COMMON_BLOCKS = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
- PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.lock20231021";
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-ObjC",
+ "-l\"c++\"",
+ "-l\"resolv\"",
+ "-l\"sqlite3\"",
+ "-l\"sqlite3.0\"",
+ "-l\"z\"",
+ "-framework",
+ "\"AMapFoundationKit\"",
+ "-framework",
+ "\"AMapLocationKit\"",
+ "-framework",
+ "\"Accelerate\"",
+ "-framework",
+ "\"AlicloudSender\"",
+ "-framework",
+ "\"AlicloudUtils\"",
+ "-framework",
+ "\"CloudPushSDK\"",
+ "-framework",
+ "\"CoreData\"",
+ "-framework",
+ "\"CoreGraphics\"",
+ "-framework",
+ "\"CoreImage\"",
+ "-framework",
+ "\"CoreLocation\"",
+ "-framework",
+ "\"CoreTelephony\"",
+ "-framework",
+ "\"CoreText\"",
+ "-framework",
+ "\"EMASRest\"",
+ "-framework",
+ "\"ExternalAccessory\"",
+ "-framework",
+ "\"FMDB\"",
+ "-framework",
+ "\"GLKit\"",
+ "-framework",
+ "\"GoogleMaps\"",
+ "-framework",
+ "\"GoogleMapsBase\"",
+ "-framework",
+ "\"GoogleMapsCore\"",
+ "-framework",
+ "\"ImageIO\"",
+ "-framework",
+ "\"MAMapKit\"",
+ "-framework",
+ "\"Metal\"",
+ "-framework",
+ "\"OpenGLES\"",
+ "-framework",
+ "\"Protobuf\"",
+ "-framework",
+ "\"QuartzCore\"",
+ "-framework",
+ "\"Security\"",
+ "-framework",
+ "\"SwiftProtobuf\"",
+ "-framework",
+ "\"SystemConfiguration\"",
+ "-framework",
+ "\"Toast\"",
+ "-framework",
+ "\"UIKit\"",
+ "-framework",
+ "\"UTDID\"",
+ "-framework",
+ "\"UTMini\"",
+ "-framework",
+ "\"aj_captcha_flutter\"",
+ "-framework",
+ "\"amap_flutter_location\"",
+ "-framework",
+ "\"amap_flutter_map\"",
+ "-framework",
+ "\"camera_avfoundation\"",
+ "-framework",
+ "\"device_info_plus\"",
+ "-framework",
+ "\"flutter_native_contact_picker\"",
+ "-framework",
+ "\"fluttertoast\"",
+ "-framework",
+ "\"google_maps_flutter_ios\"",
+ "-framework",
+ "\"image_picker_ios\"",
+ "-framework",
+ "\"network_info_plus\"",
+ "-framework",
+ "\"package_info_plus\"",
+ "-framework",
+ "\"path_provider_foundation\"",
+ "-framework",
+ "\"permission_handler_apple\"",
+ "-framework",
+ "\"reactive_ble_mobile\"",
+ "-framework",
+ "\"shared_preferences_foundation\"",
+ "-framework",
+ "\"sqflite\"",
+ "-framework",
+ "\"url_launcher_ios\"",
+ "-framework",
+ "\"webview_flutter_wkwebview\"",
+ );
+ PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.starLock";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -528,15 +1226,125 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
- DEVELOPMENT_TEAM = DWNXC92BQ6;
+ DEVELOPMENT_TEAM = 7D53BZAN75;
ENABLE_BITCODE = NO;
+ GCC_NO_COMMON_BLOCKS = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
- PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.lock20231021";
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-ObjC",
+ "-l\"c++\"",
+ "-l\"resolv\"",
+ "-l\"sqlite3\"",
+ "-l\"sqlite3.0\"",
+ "-l\"z\"",
+ "-framework",
+ "\"AMapFoundationKit\"",
+ "-framework",
+ "\"AMapLocationKit\"",
+ "-framework",
+ "\"Accelerate\"",
+ "-framework",
+ "\"AlicloudSender\"",
+ "-framework",
+ "\"AlicloudUtils\"",
+ "-framework",
+ "\"CloudPushSDK\"",
+ "-framework",
+ "\"CoreData\"",
+ "-framework",
+ "\"CoreGraphics\"",
+ "-framework",
+ "\"CoreImage\"",
+ "-framework",
+ "\"CoreLocation\"",
+ "-framework",
+ "\"CoreTelephony\"",
+ "-framework",
+ "\"CoreText\"",
+ "-framework",
+ "\"EMASRest\"",
+ "-framework",
+ "\"ExternalAccessory\"",
+ "-framework",
+ "\"FMDB\"",
+ "-framework",
+ "\"GLKit\"",
+ "-framework",
+ "\"GoogleMaps\"",
+ "-framework",
+ "\"GoogleMapsBase\"",
+ "-framework",
+ "\"GoogleMapsCore\"",
+ "-framework",
+ "\"ImageIO\"",
+ "-framework",
+ "\"MAMapKit\"",
+ "-framework",
+ "\"Metal\"",
+ "-framework",
+ "\"OpenGLES\"",
+ "-framework",
+ "\"Protobuf\"",
+ "-framework",
+ "\"QuartzCore\"",
+ "-framework",
+ "\"Security\"",
+ "-framework",
+ "\"SwiftProtobuf\"",
+ "-framework",
+ "\"SystemConfiguration\"",
+ "-framework",
+ "\"Toast\"",
+ "-framework",
+ "\"UIKit\"",
+ "-framework",
+ "\"UTDID\"",
+ "-framework",
+ "\"UTMini\"",
+ "-framework",
+ "\"aj_captcha_flutter\"",
+ "-framework",
+ "\"amap_flutter_location\"",
+ "-framework",
+ "\"amap_flutter_map\"",
+ "-framework",
+ "\"camera_avfoundation\"",
+ "-framework",
+ "\"device_info_plus\"",
+ "-framework",
+ "\"flutter_native_contact_picker\"",
+ "-framework",
+ "\"fluttertoast\"",
+ "-framework",
+ "\"google_maps_flutter_ios\"",
+ "-framework",
+ "\"image_picker_ios\"",
+ "-framework",
+ "\"network_info_plus\"",
+ "-framework",
+ "\"package_info_plus\"",
+ "-framework",
+ "\"path_provider_foundation\"",
+ "-framework",
+ "\"permission_handler_apple\"",
+ "-framework",
+ "\"reactive_ble_mobile\"",
+ "-framework",
+ "\"shared_preferences_foundation\"",
+ "-framework",
+ "\"sqflite\"",
+ "-framework",
+ "\"url_launcher_ios\"",
+ "-framework",
+ "\"webview_flutter_wkwebview\"",
+ );
+ PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.starLock";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -557,15 +1365,125 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
- DEVELOPMENT_TEAM = DWNXC92BQ6;
+ DEVELOPMENT_TEAM = 7D53BZAN75;
ENABLE_BITCODE = NO;
+ GCC_NO_COMMON_BLOCKS = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
- PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.lock20231021";
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-ObjC",
+ "-l\"c++\"",
+ "-l\"resolv\"",
+ "-l\"sqlite3\"",
+ "-l\"sqlite3.0\"",
+ "-l\"z\"",
+ "-framework",
+ "\"AMapFoundationKit\"",
+ "-framework",
+ "\"AMapLocationKit\"",
+ "-framework",
+ "\"Accelerate\"",
+ "-framework",
+ "\"AlicloudSender\"",
+ "-framework",
+ "\"AlicloudUtils\"",
+ "-framework",
+ "\"CloudPushSDK\"",
+ "-framework",
+ "\"CoreData\"",
+ "-framework",
+ "\"CoreGraphics\"",
+ "-framework",
+ "\"CoreImage\"",
+ "-framework",
+ "\"CoreLocation\"",
+ "-framework",
+ "\"CoreTelephony\"",
+ "-framework",
+ "\"CoreText\"",
+ "-framework",
+ "\"EMASRest\"",
+ "-framework",
+ "\"ExternalAccessory\"",
+ "-framework",
+ "\"FMDB\"",
+ "-framework",
+ "\"GLKit\"",
+ "-framework",
+ "\"GoogleMaps\"",
+ "-framework",
+ "\"GoogleMapsBase\"",
+ "-framework",
+ "\"GoogleMapsCore\"",
+ "-framework",
+ "\"ImageIO\"",
+ "-framework",
+ "\"MAMapKit\"",
+ "-framework",
+ "\"Metal\"",
+ "-framework",
+ "\"OpenGLES\"",
+ "-framework",
+ "\"Protobuf\"",
+ "-framework",
+ "\"QuartzCore\"",
+ "-framework",
+ "\"Security\"",
+ "-framework",
+ "\"SwiftProtobuf\"",
+ "-framework",
+ "\"SystemConfiguration\"",
+ "-framework",
+ "\"Toast\"",
+ "-framework",
+ "\"UIKit\"",
+ "-framework",
+ "\"UTDID\"",
+ "-framework",
+ "\"UTMini\"",
+ "-framework",
+ "\"aj_captcha_flutter\"",
+ "-framework",
+ "\"amap_flutter_location\"",
+ "-framework",
+ "\"amap_flutter_map\"",
+ "-framework",
+ "\"camera_avfoundation\"",
+ "-framework",
+ "\"device_info_plus\"",
+ "-framework",
+ "\"flutter_native_contact_picker\"",
+ "-framework",
+ "\"fluttertoast\"",
+ "-framework",
+ "\"google_maps_flutter_ios\"",
+ "-framework",
+ "\"image_picker_ios\"",
+ "-framework",
+ "\"network_info_plus\"",
+ "-framework",
+ "\"package_info_plus\"",
+ "-framework",
+ "\"path_provider_foundation\"",
+ "-framework",
+ "\"permission_handler_apple\"",
+ "-framework",
+ "\"reactive_ble_mobile\"",
+ "-framework",
+ "\"shared_preferences_foundation\"",
+ "-framework",
+ "\"sqflite\"",
+ "-framework",
+ "\"url_launcher_ios\"",
+ "-framework",
+ "\"webview_flutter_wkwebview\"",
+ );
+ PRODUCT_BUNDLE_IDENTIFIER = "cn.star-lock.starLock";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
diff --git a/star_lock/ios/Runner/AliyunEmasServices-Info.plist b/star_lock/ios/Runner/AliyunEmasServices-Info.plist
new file mode 100644
index 00000000..ea7823a7
--- /dev/null
+++ b/star_lock/ios/Runner/AliyunEmasServices-Info.plist
@@ -0,0 +1,86 @@
+
+
+
+
+ config
+
+ emas.appKey
+ 333904046
+ emas.appSecret
+ 3eead09a7fc7416cb4082319aa6f48c6
+ emas.bundleId
+ cn.star-lock.starLock
+ hotfix.idSecret
+ 333904046-2
+ hotfix.rsaSecret
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCS0i6gEzmEoaXFe0gDcur1sdkE2ecWXRay3h+O11F0FmoNfQx+V4i+pt2se+KDAx/GQq8Axj4DnjzE4KT0TeVmrutI1FF4h2Tv5Ge9KT0yuCayiQPW5gkqTDxaehkRDyCzGkwaLkVslN2kFqammWsODTQw2a0/lziMrNpQU8bnjjYbKS1eIQUPM9s6smwN2A4RErAP7X1knsT1tCHoCgfgjZf1nddQSMw4vy9FBpKZDYD1gjdo5+U93VopVLpMqcbOVXbQeUwpArURNnY/dbSkrGsC2TXAfaYa+sVXPchy0pZ7C2wU2/6INkFBpw2QjFQ4uAcNXwoEn5x5iBw4VbnPAgMBAAECggEAfoowLT7kf+9iFIZgVrig0QlrZcb4aEnq2lafFFl3lnoLBX0VW37OGKNwwswzOX9jz1iBxEUYBb5H2ddT1Euev5Vaq/ZyEVOAJ1HQJzR3zlLw50c3y+uPUqlKCyDYod9L65FqrdXbd+4F6Pqsv0HTBtVSehfiPcBzuKrxrfHGqKKWx4C620SxPqtpNaYXaENyqfZ3qyKw+xtWGJtxjQ8DFkeWJ1C8O7ZxJ33SpwpEb9UIJpDtPcaKbwccLn/w5214kYAqE7m5aTmLUTFRYay2Hez1gPUKVirt/QDfEfHRv6xbv5jePl0snXWK0VwgoR3hLDuF9etM3UFLr40eQNICQQKBgQDCBjM7NvscgRCJ7E8vdcfxlebUhooZUewc9gBsTpPMcS8xZXP8desc1smZvokPtIKKwPdECw6rGf1a+sb6dnHMNjWBUbHTxWnYKqVlDDXJkgcSynK+74wRCfzmFamtQmJ1qVATHRVLoVSzmCwn9q+HsGWLAsMXDu5qbL6B91La2QKBgQDBuBHfPo4AwqefsPn5isw0bFYuc5rGSbfRTAlOC09BDJb2E9bz8QiC0A/Ar8i2fx9UbHKj96NYwMGwS49Bu/Behq5v2TnODbA6j5lN4fMbRBaCMs4TINUjG4xGeFehELiFIJvCJ+3z6zRBuXmCkxtso3VM6uVSn8TX1gjBgzxA5wKBgHjJYVVoyfUZyBEE4tr56OpV1qjRxOE0Zdg1sVe7pzkr8SRAM2+kfSSr9j9XJX54cpgsvwJGG/CasmXUHtFHsVpfGPoTwK/EgzsGeYapjkaZOPwSulJxUHI/FIisTcBFxoPXTrlHbr1xhwhzIHIUmXvQbbaXlpohOn1Yi1Tfgl4pAoGAJBdZLRCIgFfDxxq/1+AmH3Y3sDvVkC/X0WSrLyEoSORBk+MqXxR/E3AUH0Ag0u9oNOBnk2jlw/lVnLTXIdYT+Gh7Q1djT6J5PM/YLgx0sJXE48j3X9T0ILBXOCHfoaBt4E+s9UVfLdyaRcx6ePtTVrA1gHka9IPTtqqnwvXiWe0CgYBjmKSq2uBXSzAWMAR5KbUYDzUoqWGGHyRHtX4IqlLYF6paabzJDxPg2QScv9e8+js5Vmbg/G5RUPhYMqJIatAzLQDujaLovLGPXlx2xQXf4Nn0M5AnvKXMF+m8xBY5KnT5SWjI9Uq9QVJMcMl43Nq1V4NSsnB8SIZsGVOgxB9tuw==
+ httpdns.accountId
+ 125761
+ httpdns.secretKey
+ f77f39c6f0e66d7c169aa7e8d87dfe13
+ appmonitor.tlog.rsaSecret
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSlqdpwcdPniL1ahrYfTy47aD8Ay7D7qLyKO5QeXy64V+CQ0UvYwyTtfPRzvlXbwmc2ONjwKHq2B7SRhwHuBwURZNp5Iw1XaGCmqPPMOpL9UnYEIO90x3sFebIRHmXscyRVniGhmmdOXpVaP6BA3RWK1uwH/FBetzom6H+dcNMPQIDAQAB
+ appmonitor.rsaSecret
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSlqdpwcdPniL1ahrYfTy47aD8Ay7D7qLyKO5QeXy64V+CQ0UvYwyTtfPRzvlXbwmc2ONjwKHq2B7SRhwHuBwURZNp5Iw1XaGCmqPPMOpL9UnYEIO90x3sFebIRHmXscyRVniGhmmdOXpVaP6BA3RWK1uwH/FBetzom6H+dcNMPQIDAQAB
+
+ services
+
+ hotfix_service
+
+ status
+ 1
+ version
+ 1.0.0-1
+
+ feedback_service
+
+ status
+ 1
+ version
+ 3.3.11
+
+ tlog_service
+
+ status
+ 1
+ version
+ 1.0.1.2
+
+ httpdns_service
+
+ status
+ 1
+ version
+ 2.1.0
+
+ apm_service
+
+ status
+ 1
+ version
+ 1.1.1
+
+ crashreporter_service
+
+ status
+ 1
+ version
+ 1.2.0
+
+ man_service
+
+ status
+ 0
+ version
+ 1.0.13
+
+ cps_service
+
+ status
+ 1
+ version
+ 2.0.4
+
+
+
+
diff --git a/star_lock/ios/Runner/AppDelegate.h b/star_lock/ios/Runner/AppDelegate.h
index 36e21bbf..d16620c4 100644
--- a/star_lock/ios/Runner/AppDelegate.h
+++ b/star_lock/ios/Runner/AppDelegate.h
@@ -1,6 +1,50 @@
#import
#import
-@interface AppDelegate : FlutterAppDelegate
+#import
+#import
+#import
+#include
+#import
+#import
+
+#import "sysInfo.h"
+#import "UdpHelper.h"
+#import "talk_Class.h"
+#import "Call.h"
+#import "P2pTest.h"
+#import "Opendoor.h"
+#import "HKHTextField.h"
+#import
+
+#define SoundOK 0
+#define SoundNotice 1
+#define SoundError 2
+#define SoundAlarm 3
+#define SoundRing 4
+
+@interface AppDelegate : FlutterAppDelegate
+
+@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
diff --git a/star_lock/ios/Runner/AppDelegate.m b/star_lock/ios/Runner/AppDelegate.m
index 9156fe49..75342698 100644
--- a/star_lock/ios/Runner/AppDelegate.m
+++ b/star_lock/ios/Runner/AppDelegate.m
@@ -1,16 +1,291 @@
#import "AppDelegate.h"
-#import "GeneratedPluginRegistrant.h"
-#import "XSFlutterManager.h"
-#import "CommonDefine.h"
-@implementation AppDelegate
+#import "GeneratedPluginRegistrant.h"
+#import "CommonDefine.h"
+#import "XSFlutterManager.h"
+
+#import "Sformat.h"
+#import "Pub.h"
+#import "Msg.h"
+#import "VideoTalkManager.h"
+#import
+#import "BaseViewController.h"
+
+
+@interface AppDelegate()
+
+@end
+
+@implementation AppDelegate {
+ SystemSoundID okSound;
+ SystemSoundID noticeSound;
+ SystemSoundID errorSound;
+ SystemSoundID alarmSound;
+ SystemSoundID ringSound;
+}
+
+@synthesize sysinfo;
+@synthesize db;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- XSFlutterManager * VC = [[XSFlutterManager alloc]init];
+
+ [self initCloudPush];
+ [CloudPushSDK sendNotificationAck:launchOptions];
+ XSFlutterManager *VC = [[XSFlutterManager alloc] init];
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;
}
+- (void)initCloudPush {
+ // SDK初始化
+ [CloudPushSDK asyncInit:@"333904046" appSecret:@"3eead09a7fc7416cb4082319aa6f48c6" callback:^(CloudPushCallbackResult *res) {
+ if (res.success) {
+ NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
+ } else {
+ NSLog(@"Push SDK init failed, error: %@", res.error);
+ }
+ }];
+}
+
+/**
+ * 注册苹果推送,获取deviceToken用于推送
+ *
+ * @param application
+ */
+- (void)registerAPNS:(UIApplication *)application {
+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
+ // iOS 8 Notifications
+ [application registerUserNotificationSettings:
+ [UIUserNotificationSettings settingsForTypes:
+ (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
+ categories:nil]];
+ [application registerForRemoteNotifications];
+ }
+ else {
+ // iOS < 8 Notifications
+ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
+ (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
+ }
+}
+/*
+ * 苹果推送注册成功回调,将苹果返回的deviceToken上传到CloudPush服务器
+ */
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
+ [CloudPushSDK registerDevice:deviceToken withCallback:^(CloudPushCallbackResult *res) {
+ if (res.success) {
+ NSLog(@"Register deviceToken success.");
+ } else {
+ NSLog(@"Register deviceToken failed, error: %@", res.error);
+ }
+ }];
+}
+/*
+ * 苹果推送注册失败回调
+ */
+- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
+ NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
+}
+
+/**
+ * 注册推送消息到来监听
+ */
+- (void)registerMessageReceive {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(onMessageReceived:)
+ name:@"CCPDidReceiveMessageNotification"
+ object:nil];
+}
+/**
+ * 处理到来推送消息
+ *
+ * @param notification
+ */
+- (void)onMessageReceived:(NSNotification *)notification {
+ CCPSysMessage *message = [notification object];
+ NSString *title = [[NSString alloc] initWithData:message.title encoding:NSUTF8StringEncoding];
+ NSString *body = [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding];
+ NSLog(@"Receive message title: %@, content: %@.", title, body);
+}
+
+//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+// // 点击通知将App从关闭状态启动时,将通知打开回执上报
+// // [CloudPushSDK handleLaunching:launchOptions];(Deprecated from v1.8.1)
+// [CloudPushSDK sendNotificationAck:launchOptions];
+// return YES;
+//}
+/*
+ * App处于启动状态时,通知打开回调
+ */
+- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
+ NSLog(@"Receive one notification.");
+ // 取得APNS通知内容
+ NSDictionary *aps = [userInfo valueForKey:@"aps"];
+ // 内容
+ NSString *content = [aps valueForKey:@"alert"];
+ // badge数量
+ NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
+ // 播放声音
+ NSString *sound = [aps valueForKey:@"sound"];
+ // 取得Extras字段内容
+ NSString *Extras = [userInfo valueForKey:@"Extras"]; //服务端中Extras字段,key是自己定义的
+ NSLog(@"content = [%@], badge = [%ld], sound = [%@], Extras = [%@]", content, (long)badge, sound, Extras);
+ // iOS badge 清0
+ application.applicationIconBadgeNumber = 0;
+ // 通知打开回执上报
+ // [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1)
+ [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
diff --git a/star_lock/ios/Runner/CommonDefine.h b/star_lock/ios/Runner/CommonDefine.h
index 08bcda1d..f8dfb8e8 100644
--- a/star_lock/ios/Runner/CommonDefine.h
+++ b/star_lock/ios/Runner/CommonDefine.h
@@ -10,10 +10,11 @@
/** 信号通道,须与flutter里一致*/
-#define flutterMethodChannel @"flutter_native_ios"
+#define XSflutterMethodChannel @"flutter_native_ios"
/** 交互方法字段名,须与flutter里一致*/
-#define flutterMethodSharePassword @"flutter_sharePassword_to_ios"
-#define flutterMethodPresent @"flutter_present_to_ios"
+#define XSflutterMethodSharePassword @"flutter_sharePassword_to_ios"//分享密码
+#define XSflutterMethodPresent @"flutter_present_to_ios"
+#define XSflutterMethodVideoTalk @"flutter_videoTalk_to_ios"//视频对讲
#endif /* CommonDefine_h */
diff --git a/star_lock/ios/Runner/Runner.entitlements b/star_lock/ios/Runner/Runner.entitlements
index c9a86ce0..ccc11436 100644
--- a/star_lock/ios/Runner/Runner.entitlements
+++ b/star_lock/ios/Runner/Runner.entitlements
@@ -2,6 +2,8 @@
+ aps-environment
+ development
com.apple.external-accessory.wireless-configuration
diff --git a/star_lock/ios/Runner/XSFlutterManager.h b/star_lock/ios/Runner/XSFlutterManager.h
index 2be71177..b21284ce 100644
--- a/star_lock/ios/Runner/XSFlutterManager.h
+++ b/star_lock/ios/Runner/XSFlutterManager.h
@@ -7,10 +7,35 @@
#import
+#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
NS_ASSUME_NONNULL_END
diff --git a/star_lock/ios/Runner/XSFlutterManager.m b/star_lock/ios/Runner/XSFlutterManager.m
index 8d037ec6..a3363373 100644
--- a/star_lock/ios/Runner/XSFlutterManager.m
+++ b/star_lock/ios/Runner/XSFlutterManager.m
@@ -17,69 +17,122 @@
@end
-@implementation XSFlutterManager
+@implementation XSFlutterManager{
+ SystemSoundID okSound;
+ SystemSoundID noticeSound;
+ SystemSoundID errorSound;
+ SystemSoundID alarmSound;
+ SystemSoundID ringSound;
+}
+
+@synthesize sysinfo;
+//@synthesize db;
- (void)viewDidLoad {
[super viewDidLoad];
self.textToShare = [[NSString alloc] init];
-
+
[self methodChannelFunction];
}
- (void)methodChannelFunction {
//创建 FlutterMethodChannel
self.methodChannel = [FlutterMethodChannel
- methodChannelWithName:flutterMethodChannel binaryMessenger:self];
+ methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
//设置监听
- [self.methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
+ [self.methodChannel setMethodCallHandler:^(FlutterMethodCall* methodCall, FlutterResult result) {
// TODO
- NSString *method=call.method;
+ NSString *method=methodCall.method;
//调用系统分享
- if ([method isEqualToString:flutterMethodSharePassword]) {
- id params = call.arguments;
+ if ([method isEqualToString:XSflutterMethodSharePassword]) {
+ id params = methodCall.arguments;
self.textToShare = @"您好,您的密码是:";
- if ([params isKindOfClass:[NSDictionary class]]) {
- NSDictionary *paramDic = (NSDictionary *)params;
- //分享的标题
- self.textToShare = paramDic[@"pwdShareStr"];
- }
- //分享的url
- NSURL *urlToShare = [NSURL URLWithString:@"https://pre.lock.star-lock.cn:8093/login"];
-
- //在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
- NSArray *activityItems = @[self.textToShare,urlToShare];
-
- UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
-
- //不出现在活动项目
- activityVC.excludedActivityTypes = @[UIActivityTypePrint];
- [self presentViewController:activityVC animated:YES completion:nil];
-
- // 分享之后的回调
- activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
+ if ([params isKindOfClass:[NSDictionary class]]) {
+ NSDictionary *paramDic = (NSDictionary *)params;
+ //分享的标题
+ self.textToShare = paramDic[@"pwdShareStr"];
+ }
+ //分享的url
+ NSURL *urlToShare = [NSURL URLWithString:@"https://pre.lock.star-lock.cn:8093/login"];
+
+ //在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
+ NSArray *activityItems = @[self.textToShare,urlToShare];
+
+ UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
+
+ //不出现在活动项目
+ activityVC.excludedActivityTypes = @[UIActivityTypePrint];
+ // [self presentViewController:activityVC animated:YES completion:nil];
+ [[Pub getApp].window.rootViewController presentViewController:activityVC animated:YES completion:nil];
+
+ // 分享之后的回调
+ activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) {
-
NSLog(@"completed");
-
//分享 成功
-
} else {
-
NSLog(@"cancled");
-
//分享 取消
-
}
-
- };
-
+ };
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{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
@@ -92,13 +145,13 @@
/*
-#pragma mark - Navigation
-
-// In a storyboard-based application, you will often want to do a little preparation before navigation
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
-}
-*/
+ #pragma mark - Navigation
+
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
@end
diff --git a/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.h b/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.h
new file mode 100755
index 00000000..335166b4
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.h
@@ -0,0 +1,657 @@
+//
+// 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
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.m b/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.m
new file mode 100755
index 00000000..8931679a
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/AsyncSocket.m
@@ -0,0 +1,4313 @@
+//
+// AsyncSocket.m
+//
+// 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/
+//
+
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
+#import "AsyncSocket.h"
+#import
+#import
+#import
+#import
+#import
+
+#if TARGET_OS_IPHONE
+// Note: You may need to add the CFNetwork Framework to your project
+#import
+#endif
+
+#pragma mark Declarations
+
+#define DEFAULT_PREBUFFERING YES // Whether pre-buffering is enabled by default
+
+#define READQUEUE_CAPACITY 5 // Initial capacity
+#define WRITEQUEUE_CAPACITY 5 // Initial capacity
+#define READALL_CHUNKSIZE 256 // Incremental increase in buffer size
+#define WRITE_CHUNKSIZE (1024 * 4) // Limit on size of each write pass
+
+// AsyncSocket is RunLoop based, and is thus not thread-safe.
+// You must always access your AsyncSocket instance from the thread/runloop in which the instance is running.
+// You can use methods such as performSelectorOnThread to accomplish this.
+// Failure to comply with these thread-safety rules may result in errors.
+// You can enable this option to help diagnose where you are incorrectly accessing your socket.
+#if DEBUG
+ #define DEBUG_THREAD_SAFETY 1
+#else
+ #define DEBUG_THREAD_SAFETY 0
+#endif
+//
+// If you constantly need to access your socket from multiple threads
+// then you may consider using GCDAsyncSocket instead, which is thread-safe.
+
+NSString *const AsyncSocketException = @"AsyncSocketException";
+NSString *const AsyncSocketErrorDomain = @"AsyncSocketErrorDomain";
+
+
+enum AsyncSocketFlags
+{
+ kEnablePreBuffering = 1 << 0, // If set, pre-buffering is enabled
+ kDidStartDelegate = 1 << 1, // If set, disconnection results in delegate call
+ kDidCompleteOpenForRead = 1 << 2, // If set, open callback has been called for read stream
+ kDidCompleteOpenForWrite = 1 << 3, // If set, open callback has been called for write stream
+ kStartingReadTLS = 1 << 4, // If set, we're waiting for TLS negotiation to complete
+ kStartingWriteTLS = 1 << 5, // If set, we're waiting for TLS negotiation to complete
+ kForbidReadsWrites = 1 << 6, // If set, no new reads or writes are allowed
+ kDisconnectAfterReads = 1 << 7, // If set, disconnect after no more reads are queued
+ kDisconnectAfterWrites = 1 << 8, // If set, disconnect after no more writes are queued
+ kClosingWithError = 1 << 9, // If set, the socket is being closed due to an error
+ kDequeueReadScheduled = 1 << 10, // If set, a maybeDequeueRead operation is already scheduled
+ kDequeueWriteScheduled = 1 << 11, // If set, a maybeDequeueWrite operation is already scheduled
+ kSocketCanAcceptBytes = 1 << 12, // If set, we know socket can accept bytes. If unset, it's unknown.
+ kSocketHasBytesAvailable = 1 << 13, // If set, we know socket has bytes available. If unset, it's unknown.
+};
+
+@interface AsyncSocket (Private)
+
+// Connecting
+- (void)startConnectTimeout:(NSTimeInterval)timeout;
+- (void)endConnectTimeout;
+- (void)doConnectTimeout:(NSTimer *)timer;
+
+// Socket Implementation
+- (CFSocketRef)newAcceptSocketForAddress:(NSData *)addr error:(NSError **)errPtr;
+- (BOOL)createSocketForAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
+- (BOOL)bindSocketToAddress:(NSData *)interfaceAddr error:(NSError **)errPtr;
+- (BOOL)attachSocketsToRunLoop:(NSRunLoop *)runLoop error:(NSError **)errPtr;
+- (BOOL)configureSocketAndReturnError:(NSError **)errPtr;
+- (BOOL)connectSocketToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
+- (void)doAcceptWithSocket:(CFSocketNativeHandle)newSocket;
+- (void)doSocketOpen:(CFSocketRef)sock withCFSocketError:(CFSocketError)err;
+
+// Stream Implementation
+- (BOOL)createStreamsFromNative:(CFSocketNativeHandle)native error:(NSError **)errPtr;
+- (BOOL)createStreamsToHost:(NSString *)hostname onPort:(UInt16)port error:(NSError **)errPtr;
+- (BOOL)attachStreamsToRunLoop:(NSRunLoop *)runLoop error:(NSError **)errPtr;
+- (BOOL)configureStreamsAndReturnError:(NSError **)errPtr;
+- (BOOL)openStreamsAndReturnError:(NSError **)errPtr;
+- (void)doStreamOpen;
+- (BOOL)setSocketFromStreamsAndReturnError:(NSError **)errPtr;
+
+// Disconnect Implementation
+- (void)closeWithError:(NSError *)err;
+- (void)recoverUnreadData;
+- (void)emptyQueues;
+- (void)close;
+
+// Errors
+- (NSError *)getErrnoError;
+- (NSError *)getAbortError;
+- (NSError *)getStreamError;
+- (NSError *)getSocketError;
+- (NSError *)getConnectTimeoutError;
+- (NSError *)getReadMaxedOutError;
+- (NSError *)getReadTimeoutError;
+- (NSError *)getWriteTimeoutError;
+- (NSError *)errorFromCFStreamError:(CFStreamError)err;
+
+// Diagnostics
+- (BOOL)isDisconnected;
+- (BOOL)areStreamsConnected;
+- (NSString *)connectedHostFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket;
+- (NSString *)connectedHostFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket;
+- (NSString *)connectedHostFromCFSocket4:(CFSocketRef)socket;
+- (NSString *)connectedHostFromCFSocket6:(CFSocketRef)socket;
+- (UInt16)connectedPortFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket;
+- (UInt16)connectedPortFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket;
+- (UInt16)connectedPortFromCFSocket4:(CFSocketRef)socket;
+- (UInt16)connectedPortFromCFSocket6:(CFSocketRef)socket;
+- (NSString *)localHostFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket;
+- (NSString *)localHostFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket;
+- (NSString *)localHostFromCFSocket4:(CFSocketRef)socket;
+- (NSString *)localHostFromCFSocket6:(CFSocketRef)socket;
+- (UInt16)localPortFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket;
+- (UInt16)localPortFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket;
+- (UInt16)localPortFromCFSocket4:(CFSocketRef)socket;
+- (UInt16)localPortFromCFSocket6:(CFSocketRef)socket;
+- (NSString *)hostFromAddress4:(struct sockaddr_in *)pSockaddr4;
+- (NSString *)hostFromAddress6:(struct sockaddr_in6 *)pSockaddr6;
+- (UInt16)portFromAddress4:(struct sockaddr_in *)pSockaddr4;
+- (UInt16)portFromAddress6:(struct sockaddr_in6 *)pSockaddr6;
+
+// Reading
+- (void)doBytesAvailable;
+- (void)completeCurrentRead;
+- (void)endCurrentRead;
+- (void)scheduleDequeueRead;
+- (void)maybeDequeueRead;
+- (void)doReadTimeout:(NSTimer *)timer;
+
+// Writing
+- (void)doSendBytes;
+- (void)completeCurrentWrite;
+- (void)endCurrentWrite;
+- (void)scheduleDequeueWrite;
+- (void)maybeDequeueWrite;
+- (void)maybeScheduleDisconnect;
+- (void)doWriteTimeout:(NSTimer *)timer;
+
+// Run Loop
+- (void)runLoopAddSource:(CFRunLoopSourceRef)source;
+- (void)runLoopRemoveSource:(CFRunLoopSourceRef)source;
+- (void)runLoopAddTimer:(NSTimer *)timer;
+- (void)runLoopRemoveTimer:(NSTimer *)timer;
+- (void)runLoopUnscheduleReadStream;
+- (void)runLoopUnscheduleWriteStream;
+
+// Security
+- (void)maybeStartTLS;
+- (void)onTLSHandshakeSuccessful;
+
+// Callbacks
+- (void)doCFCallback:(CFSocketCallBackType)type
+ forSocket:(CFSocketRef)sock withAddress:(NSData *)address withData:(const void *)pData;
+- (void)doCFReadStreamCallback:(CFStreamEventType)type forStream:(CFReadStreamRef)stream;
+- (void)doCFWriteStreamCallback:(CFStreamEventType)type forStream:(CFWriteStreamRef)stream;
+
+@end
+
+static void MyCFSocketCallback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *);
+static void MyCFReadStreamCallback(CFReadStreamRef stream, CFStreamEventType type, void *pInfo);
+static void MyCFWriteStreamCallback(CFWriteStreamRef stream, CFStreamEventType type, void *pInfo);
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The AsyncReadPacket encompasses the instructions for any given read.
+ * The content of a read packet allows the code to determine if we're:
+ * - reading to a certain length
+ * - reading to a certain separator
+ * - or simply reading the first chunk of available data
+**/
+@interface AsyncReadPacket : NSObject
+{
+ @public
+ NSMutableData *buffer;
+ NSUInteger startOffset;
+ NSUInteger bytesDone;
+ NSUInteger maxLength;
+ NSTimeInterval timeout;
+ NSUInteger readLength;
+ NSData *term;
+ BOOL bufferOwner;
+ NSUInteger originalBufferLength;
+ long tag;
+}
+- (id)initWithData:(NSMutableData *)d
+ startOffset:(NSUInteger)s
+ maxLength:(NSUInteger)m
+ timeout:(NSTimeInterval)t
+ readLength:(NSUInteger)l
+ terminator:(NSData *)e
+ tag:(long)i;
+
+- (NSUInteger)readLengthForNonTerm;
+- (NSUInteger)readLengthForTerm;
+- (NSUInteger)readLengthForTermWithPreBuffer:(NSData *)preBuffer found:(BOOL *)foundPtr;
+
+- (NSUInteger)prebufferReadLengthForTerm;
+- (NSInteger)searchForTermAfterPreBuffering:(NSUInteger)numBytes;
+@end
+
+@implementation AsyncReadPacket
+
+- (id)initWithData:(NSMutableData *)d
+ startOffset:(NSUInteger)s
+ maxLength:(NSUInteger)m
+ timeout:(NSTimeInterval)t
+ readLength:(NSUInteger)l
+ terminator:(NSData *)e
+ tag:(long)i
+{
+ if((self = [super init]))
+ {
+ if (d)
+ {
+ buffer = d;
+ startOffset = s;
+ bufferOwner = NO;
+ originalBufferLength = [d length];
+ }
+ else
+ {
+ if (readLength > 0)
+ buffer = [[NSMutableData alloc] initWithLength:readLength];
+ else
+ buffer = [[NSMutableData alloc] initWithLength:0];
+
+ startOffset = 0;
+ bufferOwner = YES;
+ originalBufferLength = 0;
+ }
+
+ bytesDone = 0;
+ maxLength = m;
+ timeout = t;
+ readLength = l;
+ term = [e copy];
+ tag = i;
+ }
+ return self;
+}
+
+/**
+ * For read packets without a set terminator, returns the safe length of data that can be read
+ * without exceeding the maxLength, or forcing a resize of the buffer if at all possible.
+**/
+- (NSUInteger)readLengthForNonTerm
+{
+ NSAssert(term == nil, @"This method does not apply to term reads");
+
+ if (readLength > 0)
+ {
+ // Read a specific length of data
+
+ return readLength - bytesDone;
+
+ // No need to avoid resizing the buffer.
+ // It should be resized if the buffer space is less than the requested read length.
+ }
+ else
+ {
+ // Read all available data
+
+ NSUInteger result = READALL_CHUNKSIZE;
+
+ if (maxLength > 0)
+ {
+ result = MIN(result, (maxLength - bytesDone));
+ }
+
+ if (!bufferOwner)
+ {
+ // We did NOT create the buffer.
+ // It is owned by the caller.
+ // Avoid resizing the buffer if at all possible.
+
+ if ([buffer length] == originalBufferLength)
+ {
+ NSUInteger buffSize = [buffer length];
+ NSUInteger buffSpace = buffSize - startOffset - bytesDone;
+
+ if (buffSpace > 0)
+ {
+ result = MIN(result, buffSpace);
+ }
+ }
+ }
+
+ return result;
+ }
+}
+
+/**
+ * For read packets with a set terminator, returns the safe length of data that can be read
+ * without going over a terminator, or the maxLength, or forcing a resize of the buffer if at all possible.
+ *
+ * It is assumed the terminator has not already been read.
+**/
+- (NSUInteger)readLengthForTerm
+{
+ NSAssert(term != nil, @"This method does not apply to non-term reads");
+
+ // What we're going to do is look for a partial sequence of the terminator at the end of the buffer.
+ // If a partial sequence occurs, then we must assume the next bytes to arrive will be the rest of the term,
+ // and we can only read that amount.
+ // Otherwise, we're safe to read the entire length of the term.
+
+ NSUInteger termLength = [term length];
+
+ // Shortcuts
+ if (bytesDone == 0) return termLength;
+ if (termLength == 1) return termLength;
+
+ // i = index within buffer at which to check data
+ // j = length of term to check against
+
+ NSUInteger i, j;
+ if (bytesDone >= termLength)
+ {
+ i = bytesDone - termLength + 1;
+ j = termLength - 1;
+ }
+ else
+ {
+ i = 0;
+ j = bytesDone;
+ }
+
+ NSUInteger result = termLength;
+
+ void *buf = [buffer mutableBytes];
+ const void *termBuf = [term bytes];
+
+ while (i < bytesDone)
+ {
+ void *subbuf = buf + startOffset + i;
+
+ if (memcmp(subbuf, termBuf, j) == 0)
+ {
+ result = termLength - j;
+ break;
+ }
+
+ i++;
+ j--;
+ }
+
+ if (maxLength > 0)
+ {
+ result = MIN(result, (maxLength - bytesDone));
+ }
+
+ if (!bufferOwner)
+ {
+ // We did NOT create the buffer.
+ // It is owned by the caller.
+ // Avoid resizing the buffer if at all possible.
+
+ if ([buffer length] == originalBufferLength)
+ {
+ NSUInteger buffSize = [buffer length];
+ NSUInteger buffSpace = buffSize - startOffset - bytesDone;
+
+ if (buffSpace > 0)
+ {
+ result = MIN(result, buffSpace);
+ }
+ }
+ }
+
+ return result;
+}
+
+/**
+ * For read packets with a set terminator,
+ * returns the safe length of data that can be read from the given preBuffer,
+ * without going over a terminator or the maxLength.
+ *
+ * It is assumed the terminator has not already been read.
+**/
+- (NSUInteger)readLengthForTermWithPreBuffer:(NSData *)preBuffer found:(BOOL *)foundPtr
+{
+ NSAssert(term != nil, @"This method does not apply to non-term reads");
+ NSAssert([preBuffer length] > 0, @"Invoked with empty pre buffer!");
+
+ // We know that the terminator, as a whole, doesn't exist in our own buffer.
+ // But it is possible that a portion of it exists in our buffer.
+ // So we're going to look for the terminator starting with a portion of our own buffer.
+ //
+ // Example:
+ //
+ // term length = 3 bytes
+ // bytesDone = 5 bytes
+ // preBuffer length = 5 bytes
+ //
+ // If we append the preBuffer to our buffer,
+ // it would look like this:
+ //
+ // ---------------------
+ // |B|B|B|B|B|P|P|P|P|P|
+ // ---------------------
+ //
+ // So we start our search here:
+ //
+ // ---------------------
+ // |B|B|B|B|B|P|P|P|P|P|
+ // -------^-^-^---------
+ //
+ // And move forwards...
+ //
+ // ---------------------
+ // |B|B|B|B|B|P|P|P|P|P|
+ // ---------^-^-^-------
+ //
+ // Until we find the terminator or reach the end.
+ //
+ // ---------------------
+ // |B|B|B|B|B|P|P|P|P|P|
+ // ---------------^-^-^-
+
+ BOOL found = NO;
+
+ NSUInteger termLength = [term length];
+ NSUInteger preBufferLength = [preBuffer length];
+
+ if ((bytesDone + preBufferLength) < termLength)
+ {
+ // Not enough data for a full term sequence yet
+ return preBufferLength;
+ }
+
+ NSUInteger maxPreBufferLength;
+ if (maxLength > 0) {
+ maxPreBufferLength = MIN(preBufferLength, (maxLength - bytesDone));
+
+ // Note: maxLength >= termLength
+ }
+ else {
+ maxPreBufferLength = preBufferLength;
+ }
+
+ Byte seq[termLength];
+ const void *termBuf = [term bytes];
+
+ NSUInteger bufLen = MIN(bytesDone, (termLength - 1));
+ void *buf = [buffer mutableBytes] + startOffset + bytesDone - bufLen;
+
+ NSUInteger preLen = termLength - bufLen;
+ void *pre = (void *)[preBuffer bytes];
+
+ NSUInteger loopCount = bufLen + maxPreBufferLength - termLength + 1; // Plus one. See example above.
+
+ NSUInteger result = preBufferLength;
+
+ NSUInteger i;
+ for (i = 0; i < loopCount; i++)
+ {
+ if (bufLen > 0)
+ {
+ // Combining bytes from buffer and preBuffer
+
+ memcpy(seq, buf, bufLen);
+ memcpy(seq + bufLen, pre, preLen);
+
+ if (memcmp(seq, termBuf, termLength) == 0)
+ {
+ result = preLen;
+ found = YES;
+ break;
+ }
+
+ buf++;
+ bufLen--;
+ preLen++;
+ }
+ else
+ {
+ // Comparing directly from preBuffer
+
+ if (memcmp(pre, termBuf, termLength) == 0)
+ {
+ NSUInteger preOffset = pre - [preBuffer bytes]; // pointer arithmetic
+
+ result = preOffset + termLength;
+ found = YES;
+ break;
+ }
+
+ pre++;
+ }
+ }
+
+ // There is no need to avoid resizing the buffer in this particular situation.
+
+ if (foundPtr) *foundPtr = found;
+ return result;
+}
+
+/**
+ * Assuming pre-buffering is enabled, returns the amount of data that can be read
+ * without going over the maxLength.
+**/
+- (NSUInteger)prebufferReadLengthForTerm
+{
+ NSAssert(term != nil, @"This method does not apply to non-term reads");
+
+ NSUInteger result = READALL_CHUNKSIZE;
+
+ if (maxLength > 0)
+ {
+ result = MIN(result, (maxLength - bytesDone));
+ }
+
+ if (!bufferOwner)
+ {
+ // We did NOT create the buffer.
+ // It is owned by the caller.
+ // Avoid resizing the buffer if at all possible.
+
+ if ([buffer length] == originalBufferLength)
+ {
+ NSUInteger buffSize = [buffer length];
+ NSUInteger buffSpace = buffSize - startOffset - bytesDone;
+
+ if (buffSpace > 0)
+ {
+ result = MIN(result, buffSpace);
+ }
+ }
+ }
+
+ return result;
+}
+
+/**
+ * For read packets with a set terminator, scans the packet buffer for the term.
+ * It is assumed the terminator had not been fully read prior to the new bytes.
+ *
+ * If the term is found, the number of excess bytes after the term are returned.
+ * If the term is not found, this method will return -1.
+ *
+ * Note: A return value of zero means the term was found at the very end.
+**/
+- (NSInteger)searchForTermAfterPreBuffering:(NSUInteger)numBytes
+{
+ NSAssert(term != nil, @"This method does not apply to non-term reads");
+ NSAssert(bytesDone >= numBytes, @"Invoked with invalid numBytes!");
+
+ // We try to start the search such that the first new byte read matches up with the last byte of the term.
+ // We continue searching forward after this until the term no longer fits into the buffer.
+
+ NSUInteger termLength = [term length];
+ const void *termBuffer = [term bytes];
+
+ // Remember: This method is called after the bytesDone variable has been updated.
+
+ NSUInteger prevBytesDone = bytesDone - numBytes;
+
+ NSUInteger i;
+ if (prevBytesDone >= termLength)
+ i = prevBytesDone - termLength + 1;
+ else
+ i = 0;
+
+ while ((i + termLength) <= bytesDone)
+ {
+ void *subBuffer = [buffer mutableBytes] + startOffset + i;
+
+ if(memcmp(subBuffer, termBuffer, termLength) == 0)
+ {
+ return bytesDone - (i + termLength);
+ }
+
+ i++;
+ }
+
+ return -1;
+}
+
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The AsyncWritePacket encompasses the instructions for any given write.
+**/
+@interface AsyncWritePacket : NSObject
+{
+ @public
+ NSData *buffer;
+ NSUInteger bytesDone;
+ long tag;
+ NSTimeInterval timeout;
+}
+- (id)initWithData:(NSData *)d timeout:(NSTimeInterval)t tag:(long)i;
+@end
+
+@implementation AsyncWritePacket
+
+- (id)initWithData:(NSData *)d timeout:(NSTimeInterval)t tag:(long)i
+{
+ if((self = [super init]))
+ {
+ buffer = d;
+ timeout = t;
+ tag = i;
+ bytesDone = 0;
+ }
+ return self;
+}
+
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The AsyncSpecialPacket encompasses special instructions for interruptions in the read/write queues.
+ * This class my be altered to support more than just TLS in the future.
+**/
+@interface AsyncSpecialPacket : NSObject
+{
+ @public
+ NSDictionary *tlsSettings;
+}
+- (id)initWithTLSSettings:(NSDictionary *)settings;
+@end
+
+@implementation AsyncSpecialPacket
+
+- (id)initWithTLSSettings:(NSDictionary *)settings
+{
+ if((self = [super init]))
+ {
+ tlsSettings = [settings copy];
+ }
+ return self;
+}
+
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+@implementation AsyncSocket
+
+- (id)init
+{
+ return [self initWithDelegate:nil userData:0];
+}
+
+- (id)initWithDelegate:(id)delegate
+{
+ return [self initWithDelegate:delegate userData:0];
+}
+
+// Designated initializer.
+- (id)initWithDelegate:(id)delegate userData:(long)userData
+{
+ if((self = [super init]))
+ {
+ theFlags = DEFAULT_PREBUFFERING ? kEnablePreBuffering : 0;
+ theDelegate = delegate;
+ theUserData = userData;
+
+ theNativeSocket4 = 0;
+ theNativeSocket6 = 0;
+
+ theSocket4 = NULL;
+ theSource4 = NULL;
+
+ theSocket6 = NULL;
+ theSource6 = NULL;
+
+ theRunLoop = NULL;
+ theReadStream = NULL;
+ theWriteStream = NULL;
+
+ theConnectTimer = nil;
+
+ theReadQueue = [[NSMutableArray alloc] initWithCapacity:READQUEUE_CAPACITY];
+ theCurrentRead = nil;
+ theReadTimer = nil;
+
+ partialReadBuffer = [[NSMutableData alloc] initWithCapacity:READALL_CHUNKSIZE];
+
+ theWriteQueue = [[NSMutableArray alloc] initWithCapacity:WRITEQUEUE_CAPACITY];
+ theCurrentWrite = nil;
+ theWriteTimer = nil;
+
+ // Socket context
+ NSAssert(sizeof(CFSocketContext) == sizeof(CFStreamClientContext), @"CFSocketContext != CFStreamClientContext");
+ theContext.version = 0;
+ theContext.info = (__bridge void *)(self);
+ theContext.retain = nil;
+ theContext.release = nil;
+ theContext.copyDescription = nil;
+
+ // Default run loop modes
+ theRunLoopModes = [NSArray arrayWithObject:NSDefaultRunLoopMode];
+ }
+ return self;
+}
+
+// The socket may been initialized in a connected state and auto-released, so this should close it down cleanly.
+- (void)dealloc
+{
+ [self close];
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Thread-Safety
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)checkForThreadSafety
+{
+ if (theRunLoop && (theRunLoop != CFRunLoopGetCurrent()))
+ {
+ // AsyncSocket is RunLoop based.
+ // It is designed to be run and accessed from a particular thread/runloop.
+ // As such, it is faster as it does not have the overhead of locks/synchronization.
+ //
+ // However, this places a minimal requirement on the developer to maintain thread-safety.
+ // If you are seeing errors or crashes in AsyncSocket,
+ // it is very likely that thread-safety has been broken.
+ // This method may be enabled via the DEBUG_THREAD_SAFETY macro,
+ // and will allow you to discover the place in your code where thread-safety is being broken.
+ //
+ // Note:
+ //
+ // If you find you constantly need to access your socket from various threads,
+ // you may prefer to use GCDAsyncSocket which is thread-safe.
+
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to access AsyncSocket instance from incorrect thread."];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Accessors
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (long)userData
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return theUserData;
+}
+
+- (void)setUserData:(long)userData
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theUserData = userData;
+}
+
+- (id)delegate
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return theDelegate;
+}
+
+- (void)setDelegate:(id)delegate
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theDelegate = delegate;
+}
+
+- (BOOL)canSafelySetDelegate
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return ([theReadQueue count] == 0 && [theWriteQueue count] == 0 && theCurrentRead == nil && theCurrentWrite == nil);
+}
+
+- (CFSocketRef)getCFSocket
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(theSocket4)
+ return theSocket4;
+ else
+ return theSocket6;
+}
+
+- (CFReadStreamRef)getCFReadStream
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return theReadStream;
+}
+
+- (CFWriteStreamRef)getCFWriteStream
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return theWriteStream;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Progress
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (float)progressOfReadReturningTag:(long *)tag bytesDone:(NSUInteger *)done total:(NSUInteger *)total
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ // Check to make sure we're actually reading something right now,
+ // and that the read packet isn't an AsyncSpecialPacket (upgrade to TLS).
+ if (!theCurrentRead || ![theCurrentRead isKindOfClass:[AsyncReadPacket class]])
+ {
+ if (tag != NULL) *tag = 0;
+ if (done != NULL) *done = 0;
+ if (total != NULL) *total = 0;
+
+ return NAN;
+ }
+
+ // It's only possible to know the progress of our read if we're reading to a certain length.
+ // If we're reading to data, we of course have no idea when the data will arrive.
+ // If we're reading to timeout, then we have no idea when the next chunk of data will arrive.
+
+ NSUInteger d = theCurrentRead->bytesDone;
+ NSUInteger t = theCurrentRead->readLength;
+
+ if (tag != NULL) *tag = theCurrentRead->tag;
+ if (done != NULL) *done = d;
+ if (total != NULL) *total = t;
+
+ if (t > 0.0)
+ return (float)d / (float)t;
+ else
+ return 1.0F;
+}
+
+- (float)progressOfWriteReturningTag:(long *)tag bytesDone:(NSUInteger *)done total:(NSUInteger *)total
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ // Check to make sure we're actually writing something right now,
+ // and that the write packet isn't an AsyncSpecialPacket (upgrade to TLS).
+ if (!theCurrentWrite || ![theCurrentWrite isKindOfClass:[AsyncWritePacket class]])
+ {
+ if (tag != NULL) *tag = 0;
+ if (done != NULL) *done = 0;
+ if (total != NULL) *total = 0;
+
+ return NAN;
+ }
+
+ NSUInteger d = theCurrentWrite->bytesDone;
+ NSUInteger t = [theCurrentWrite->buffer length];
+
+ if (tag != NULL) *tag = theCurrentWrite->tag;
+ if (done != NULL) *done = d;
+ if (total != NULL) *total = t;
+
+ return (float)d / (float)t;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Run Loop
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)runLoopAddSource:(CFRunLoopSourceRef)source
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopAddSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopRemoveSource:(CFRunLoopSourceRef)source
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopRemoveSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopAddSource:(CFRunLoopSourceRef)source mode:(NSString *)runLoopMode
+{
+ CFRunLoopAddSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+}
+
+- (void)runLoopRemoveSource:(CFRunLoopSourceRef)source mode:(NSString *)runLoopMode
+{
+ CFRunLoopRemoveSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+}
+
+- (void)runLoopAddTimer:(NSTimer *)timer
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopAddTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopRemoveTimer:(NSTimer *)timer
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopRemoveTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopAddTimer:(NSTimer *)timer mode:(NSString *)runLoopMode
+{
+ CFRunLoopAddTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+}
+
+- (void)runLoopRemoveTimer:(NSTimer *)timer mode:(NSString *)runLoopMode
+{
+ CFRunLoopRemoveTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+}
+
+- (void)runLoopUnscheduleReadStream
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFReadStreamUnscheduleFromRunLoop(theReadStream, theRunLoop, (__bridge CFStringRef)runLoopMode);
+ }
+ CFReadStreamSetClient(theReadStream, kCFStreamEventNone, NULL, NULL);
+}
+
+- (void)runLoopUnscheduleWriteStream
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFWriteStreamUnscheduleFromRunLoop(theWriteStream, theRunLoop, (__bridge CFStringRef)runLoopMode);
+ }
+ CFWriteStreamSetClient(theWriteStream, kCFStreamEventNone, NULL, NULL);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Configuration
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * See the header file for a full explanation of pre-buffering.
+**/
+- (void)enablePreBuffering
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theFlags |= kEnablePreBuffering;
+}
+
+/**
+ * See the header file for a full explanation of this method.
+**/
+- (BOOL)moveToRunLoop:(NSRunLoop *)runLoop
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"moveToRunLoop must be called from within the current RunLoop!");
+
+ if(runLoop == nil)
+ {
+ return NO;
+ }
+ if(theRunLoop == [runLoop getCFRunLoop])
+ {
+ return YES;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueReadScheduled;
+ theFlags &= ~kDequeueWriteScheduled;
+
+ if(theReadStream && theWriteStream)
+ {
+ [self runLoopUnscheduleReadStream];
+ [self runLoopUnscheduleWriteStream];
+ }
+
+ if(theSource4) [self runLoopRemoveSource:theSource4];
+ if(theSource6) [self runLoopRemoveSource:theSource6];
+
+ if(theReadTimer) [self runLoopRemoveTimer:theReadTimer];
+ if(theWriteTimer) [self runLoopRemoveTimer:theWriteTimer];
+
+ theRunLoop = [runLoop getCFRunLoop];
+
+ if(theReadTimer) [self runLoopAddTimer:theReadTimer];
+ if(theWriteTimer) [self runLoopAddTimer:theWriteTimer];
+
+ if(theSource4) [self runLoopAddSource:theSource4];
+ if(theSource6) [self runLoopAddSource:theSource6];
+
+ if(theReadStream && theWriteStream)
+ {
+ if(![self attachStreamsToRunLoop:runLoop error:nil])
+ {
+ return NO;
+ }
+ }
+
+ [runLoop performSelector:@selector(maybeDequeueRead) target:self argument:nil order:0 modes:theRunLoopModes];
+ [runLoop performSelector:@selector(maybeDequeueWrite) target:self argument:nil order:0 modes:theRunLoopModes];
+ [runLoop performSelector:@selector(maybeScheduleDisconnect) target:self argument:nil order:0 modes:theRunLoopModes];
+
+ return YES;
+}
+
+/**
+ * See the header file for a full explanation of this method.
+**/
+- (BOOL)setRunLoopModes:(NSArray *)runLoopModes
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"setRunLoopModes must be called from within the current RunLoop!");
+
+ if([runLoopModes count] == 0)
+ {
+ return NO;
+ }
+ if([theRunLoopModes isEqualToArray:runLoopModes])
+ {
+ return YES;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueReadScheduled;
+ theFlags &= ~kDequeueWriteScheduled;
+
+ if(theReadStream && theWriteStream)
+ {
+ [self runLoopUnscheduleReadStream];
+ [self runLoopUnscheduleWriteStream];
+ }
+
+ if(theSource4) [self runLoopRemoveSource:theSource4];
+ if(theSource6) [self runLoopRemoveSource:theSource6];
+
+ if(theReadTimer) [self runLoopRemoveTimer:theReadTimer];
+ if(theWriteTimer) [self runLoopRemoveTimer:theWriteTimer];
+
+ theRunLoopModes = [runLoopModes copy];
+
+ if(theReadTimer) [self runLoopAddTimer:theReadTimer];
+ if(theWriteTimer) [self runLoopAddTimer:theWriteTimer];
+
+ if(theSource4) [self runLoopAddSource:theSource4];
+ if(theSource6) [self runLoopAddSource:theSource6];
+
+ if(theReadStream && theWriteStream)
+ {
+ // Note: theRunLoop variable is a CFRunLoop, and NSRunLoop is NOT toll-free bridged with CFRunLoop.
+ // So we cannot pass theRunLoop to the method below, which is expecting a NSRunLoop parameter.
+ // Instead we pass nil, which will result in the method properly using the current run loop.
+
+ if(![self attachStreamsToRunLoop:nil error:nil])
+ {
+ return NO;
+ }
+ }
+
+ [self performSelector:@selector(maybeDequeueRead) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeDequeueWrite) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeScheduleDisconnect) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+
+ return YES;
+}
+
+- (BOOL)addRunLoopMode:(NSString *)runLoopMode
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"addRunLoopMode must be called from within the current RunLoop!");
+
+ if(runLoopMode == nil)
+ {
+ return NO;
+ }
+ if([theRunLoopModes containsObject:runLoopMode])
+ {
+ return YES;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueReadScheduled;
+ theFlags &= ~kDequeueWriteScheduled;
+
+ NSArray *newRunLoopModes = [theRunLoopModes arrayByAddingObject:runLoopMode];
+ theRunLoopModes = newRunLoopModes;
+
+ if(theReadTimer) [self runLoopAddTimer:theReadTimer mode:runLoopMode];
+ if(theWriteTimer) [self runLoopAddTimer:theWriteTimer mode:runLoopMode];
+
+ if(theSource4) [self runLoopAddSource:theSource4 mode:runLoopMode];
+ if(theSource6) [self runLoopAddSource:theSource6 mode:runLoopMode];
+
+ if(theReadStream && theWriteStream)
+ {
+ CFReadStreamScheduleWithRunLoop(theReadStream, CFRunLoopGetCurrent(), (__bridge CFStringRef)runLoopMode);
+ CFWriteStreamScheduleWithRunLoop(theWriteStream, CFRunLoopGetCurrent(), (__bridge CFStringRef)runLoopMode);
+ }
+
+ [self performSelector:@selector(maybeDequeueRead) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeDequeueWrite) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeScheduleDisconnect) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+
+ return YES;
+}
+
+- (BOOL)removeRunLoopMode:(NSString *)runLoopMode
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"addRunLoopMode must be called from within the current RunLoop!");
+
+ if(runLoopMode == nil)
+ {
+ return NO;
+ }
+ if(![theRunLoopModes containsObject:runLoopMode])
+ {
+ return YES;
+ }
+
+ NSMutableArray *newRunLoopModes = [theRunLoopModes mutableCopy];
+ [newRunLoopModes removeObject:runLoopMode];
+
+ if([newRunLoopModes count] == 0)
+ {
+ return NO;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueReadScheduled;
+ theFlags &= ~kDequeueWriteScheduled;
+
+ theRunLoopModes = [newRunLoopModes copy];
+
+ if(theReadTimer) [self runLoopRemoveTimer:theReadTimer mode:runLoopMode];
+ if(theWriteTimer) [self runLoopRemoveTimer:theWriteTimer mode:runLoopMode];
+
+ if(theSource4) [self runLoopRemoveSource:theSource4 mode:runLoopMode];
+ if(theSource6) [self runLoopRemoveSource:theSource6 mode:runLoopMode];
+
+ if(theReadStream && theWriteStream)
+ {
+ CFReadStreamScheduleWithRunLoop(theReadStream, CFRunLoopGetCurrent(), (__bridge CFStringRef)runLoopMode);
+ CFWriteStreamScheduleWithRunLoop(theWriteStream, CFRunLoopGetCurrent(), (__bridge CFStringRef)runLoopMode);
+ }
+
+ [self performSelector:@selector(maybeDequeueRead) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeDequeueWrite) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeScheduleDisconnect) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+
+ return YES;
+}
+
+- (NSArray *)runLoopModes
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return theRunLoopModes;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Accepting
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (BOOL)acceptOnPort:(UInt16)port error:(NSError **)errPtr
+{
+ return [self acceptOnInterface:nil port:port error:errPtr];
+}
+
+/**
+ * To accept on a certain interface, pass the address to accept on.
+ * To accept on any interface, pass nil or an empty string.
+ * To accept only connections from localhost pass "localhost" or "loopback".
+**/
+- (BOOL)acceptOnInterface:(NSString *)interface port:(UInt16)port error:(NSError **)errPtr
+{
+ if (theDelegate == NULL)
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to accept without a delegate. Set a delegate first."];
+ }
+
+ if (![self isDisconnected])
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to accept while connected or accepting connections. Disconnect first."];
+ }
+
+ // Clear queues (spurious read/write requests post disconnect)
+ [self emptyQueues];
+
+ // Set up the listen sockaddr structs if needed.
+
+ NSData *address4 = nil, *address6 = nil;
+ if(interface == nil || ([interface length] == 0))
+ {
+ // Accept on ANY address
+ struct sockaddr_in nativeAddr4;
+ nativeAddr4.sin_len = sizeof(struct sockaddr_in);
+ nativeAddr4.sin_family = AF_INET;
+ nativeAddr4.sin_port = htons(port);
+ nativeAddr4.sin_addr.s_addr = htonl(INADDR_ANY);
+ memset(&(nativeAddr4.sin_zero), 0, sizeof(nativeAddr4.sin_zero));
+
+ struct sockaddr_in6 nativeAddr6;
+ nativeAddr6.sin6_len = sizeof(struct sockaddr_in6);
+ nativeAddr6.sin6_family = AF_INET6;
+ nativeAddr6.sin6_port = htons(port);
+ nativeAddr6.sin6_flowinfo = 0;
+ nativeAddr6.sin6_addr = in6addr_any;
+ nativeAddr6.sin6_scope_id = 0;
+
+ // Wrap the native address structures for CFSocketSetAddress.
+ address4 = [NSData dataWithBytes:&nativeAddr4 length:sizeof(nativeAddr4)];
+ address6 = [NSData dataWithBytes:&nativeAddr6 length:sizeof(nativeAddr6)];
+ }
+ else if([interface isEqualToString:@"localhost"] || [interface isEqualToString:@"loopback"])
+ {
+ // Accept only on LOOPBACK address
+ struct sockaddr_in nativeAddr4;
+ nativeAddr4.sin_len = sizeof(struct sockaddr_in);
+ nativeAddr4.sin_family = AF_INET;
+ nativeAddr4.sin_port = htons(port);
+ nativeAddr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ memset(&(nativeAddr4.sin_zero), 0, sizeof(nativeAddr4.sin_zero));
+
+ struct sockaddr_in6 nativeAddr6;
+ nativeAddr6.sin6_len = sizeof(struct sockaddr_in6);
+ nativeAddr6.sin6_family = AF_INET6;
+ nativeAddr6.sin6_port = htons(port);
+ nativeAddr6.sin6_flowinfo = 0;
+ nativeAddr6.sin6_addr = in6addr_loopback;
+ nativeAddr6.sin6_scope_id = 0;
+
+ // Wrap the native address structures for CFSocketSetAddress.
+ address4 = [NSData dataWithBytes:&nativeAddr4 length:sizeof(nativeAddr4)];
+ address6 = [NSData dataWithBytes:&nativeAddr6 length:sizeof(nativeAddr6)];
+ }
+ else
+ {
+ NSString *portStr = [NSString stringWithFormat:@"%hu", port];
+
+ struct addrinfo hints, *res, *res0;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ hints.ai_flags = AI_PASSIVE;
+
+ int error = getaddrinfo([interface UTF8String], [portStr UTF8String], &hints, &res0);
+
+ if (error)
+ {
+ if (errPtr)
+ {
+ NSString *errMsg = [NSString stringWithCString:gai_strerror(error) encoding:NSASCIIStringEncoding];
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainNetDB" code:error userInfo:info];
+ }
+ }
+ else
+ {
+ for (res = res0; res; res = res->ai_next)
+ {
+ if (!address4 && (res->ai_family == AF_INET))
+ {
+ // Found IPv4 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ address4 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ else if (!address6 && (res->ai_family == AF_INET6))
+ {
+ // Found IPv6 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ address6 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ }
+ freeaddrinfo(res0);
+ }
+
+ if(!address4 && !address6) return NO;
+ }
+
+ // Create the sockets.
+
+ if (address4)
+ {
+ theSocket4 = [self newAcceptSocketForAddress:address4 error:errPtr];
+ if (theSocket4 == NULL) goto Failed;
+ }
+
+ if (address6)
+ {
+ theSocket6 = [self newAcceptSocketForAddress:address6 error:errPtr];
+
+ // Note: The iPhone doesn't currently support IPv6
+
+#if !TARGET_OS_IPHONE
+ if (theSocket6 == NULL) goto Failed;
+#endif
+ }
+
+ // Attach the sockets to the run loop so that callback methods work
+
+ [self attachSocketsToRunLoop:nil error:nil];
+
+ // Set the SO_REUSEADDR flags.
+
+ int reuseOn = 1;
+ if (theSocket4) setsockopt(CFSocketGetNative(theSocket4), SOL_SOCKET, SO_REUSEADDR, &reuseOn, sizeof(reuseOn));
+ if (theSocket6) setsockopt(CFSocketGetNative(theSocket6), SOL_SOCKET, SO_REUSEADDR, &reuseOn, sizeof(reuseOn));
+
+ // Set the local bindings which causes the sockets to start listening.
+
+ CFSocketError err;
+ if (theSocket4)
+ {
+ err = CFSocketSetAddress(theSocket4, (__bridge CFDataRef)address4);
+ if (err != kCFSocketSuccess) goto Failed;
+
+ //NSLog(@"theSocket4: %hu", [self localPortFromCFSocket4:theSocket4]);
+ }
+
+ if(port == 0 && theSocket4 && theSocket6)
+ {
+ // The user has passed in port 0, which means he wants to allow the kernel to choose the port for them
+ // However, the kernel will choose a different port for both theSocket4 and theSocket6
+ // So we grab the port the kernel choose for theSocket4, and set it as the port for theSocket6
+ UInt16 chosenPort = [self localPortFromCFSocket4:theSocket4];
+
+ struct sockaddr_in6 *pSockAddr6 = (struct sockaddr_in6 *)[address6 bytes];
+ if (pSockAddr6) // If statement to quiet the static analyzer
+ {
+ pSockAddr6->sin6_port = htons(chosenPort);
+ }
+ }
+
+ if (theSocket6)
+ {
+ err = CFSocketSetAddress(theSocket6, (__bridge CFDataRef)address6);
+ if (err != kCFSocketSuccess) goto Failed;
+
+ //NSLog(@"theSocket6: %hu", [self localPortFromCFSocket6:theSocket6]);
+ }
+
+ theFlags |= kDidStartDelegate;
+ return YES;
+
+Failed:
+ if(errPtr) *errPtr = [self getSocketError];
+ if(theSocket4 != NULL)
+ {
+ CFSocketInvalidate(theSocket4);
+ CFRelease(theSocket4);
+ theSocket4 = NULL;
+ }
+ if(theSocket6 != NULL)
+ {
+ CFSocketInvalidate(theSocket6);
+ CFRelease(theSocket6);
+ theSocket6 = NULL;
+ }
+ return NO;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Connecting
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (BOOL)connectToHost:(NSString*)hostname onPort:(UInt16)port error:(NSError **)errPtr
+{
+ return [self connectToHost:hostname onPort:port withTimeout:-1 error:errPtr];
+}
+
+/**
+ * This method creates an initial CFReadStream and CFWriteStream to the given host on the given port.
+ * The connection is then opened, and the corresponding CFSocket will be extracted after the connection succeeds.
+ *
+ * Thus the delegate will have access to the CFReadStream and CFWriteStream prior to connection,
+ * specifically in the onSocketWillConnect: method.
+**/
+- (BOOL)connectToHost:(NSString *)hostname
+ onPort:(UInt16)port
+ withTimeout:(NSTimeInterval)timeout
+ error:(NSError **)errPtr
+{
+ if (theDelegate == NULL)
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to connect without a delegate. Set a delegate first."];
+ }
+
+ if (![self isDisconnected])
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to connect while connected or accepting connections. Disconnect first."];
+ }
+
+ // Clear queues (spurious read/write requests post disconnect)
+ [self emptyQueues];
+
+ if(![self createStreamsToHost:hostname onPort:port error:errPtr]) goto Failed;
+ if(![self attachStreamsToRunLoop:nil error:errPtr]) goto Failed;
+ if(![self configureStreamsAndReturnError:errPtr]) goto Failed;
+ if(![self openStreamsAndReturnError:errPtr]) goto Failed;
+
+ [self startConnectTimeout:timeout];
+ theFlags |= kDidStartDelegate;
+
+ return YES;
+
+Failed:
+ [self close];
+ return NO;
+}
+
+- (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr
+{
+ return [self connectToAddress:remoteAddr viaInterfaceAddress:nil withTimeout:-1 error:errPtr];
+}
+
+/**
+ * This method creates an initial CFSocket to the given address.
+ * The connection is then opened, and the corresponding CFReadStream and CFWriteStream will be
+ * created from the low-level sockets after the connection succeeds.
+ *
+ * Thus the delegate will have access to the CFSocket and CFSocketNativeHandle (BSD socket) prior to connection,
+ * specifically in the onSocketWillConnect: method.
+ *
+ * Note: The NSData parameter is expected to be a sockaddr structure. For example, an NSData object returned from
+ * NSNetService addresses method.
+ * If you have an existing struct sockaddr you can convert it to an 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 withTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr
+{
+ return [self connectToAddress:remoteAddr viaInterfaceAddress:nil withTimeout:timeout error:errPtr];
+}
+
+/**
+ * This method is similar to the one above, but allows you to specify which socket interface
+ * the connection should run over. E.g. ethernet, wifi, bluetooth, etc.
+**/
+- (BOOL)connectToAddress:(NSData *)remoteAddr
+ viaInterfaceAddress:(NSData *)interfaceAddr
+ withTimeout:(NSTimeInterval)timeout
+ error:(NSError **)errPtr
+{
+ if (theDelegate == NULL)
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to connect without a delegate. Set a delegate first."];
+ }
+
+ if (![self isDisconnected])
+ {
+ [NSException raise:AsyncSocketException
+ format:@"Attempting to connect while connected or accepting connections. Disconnect first."];
+ }
+
+ // Clear queues (spurious read/write requests post disconnect)
+ [self emptyQueues];
+
+ if(![self createSocketForAddress:remoteAddr error:errPtr]) goto Failed;
+ if(![self bindSocketToAddress:interfaceAddr error:errPtr]) goto Failed;
+ if(![self attachSocketsToRunLoop:nil error:errPtr]) goto Failed;
+ if(![self configureSocketAndReturnError:errPtr]) goto Failed;
+ if(![self connectSocketToAddress:remoteAddr error:errPtr]) goto Failed;
+
+ [self startConnectTimeout:timeout];
+ theFlags |= kDidStartDelegate;
+
+ return YES;
+
+Failed:
+ [self close];
+ return NO;
+}
+
+- (void)startConnectTimeout:(NSTimeInterval)timeout
+{
+ if(timeout >= 0.0)
+ {
+ theConnectTimer = [NSTimer timerWithTimeInterval:timeout
+ target:self
+ selector:@selector(doConnectTimeout:)
+ userInfo:nil
+ repeats:NO];
+ [self runLoopAddTimer:theConnectTimer];
+ }
+}
+
+- (void)endConnectTimeout
+{
+ [theConnectTimer invalidate];
+ theConnectTimer = nil;
+}
+
+- (void)doConnectTimeout:(NSTimer *)timer
+{
+ #pragma unused(timer)
+
+ [self endConnectTimeout];
+ [self closeWithError:[self getConnectTimeoutError]];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Socket Implementation
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Creates the accept sockets.
+ * Returns true if either IPv4 or IPv6 is created.
+ * If either is missing, an error is returned (even though the method may return true).
+**/
+- (CFSocketRef)newAcceptSocketForAddress:(NSData *)addr error:(NSError **)errPtr
+{
+ struct sockaddr *pSockAddr = (struct sockaddr *)[addr bytes];
+ int addressFamily = pSockAddr->sa_family;
+
+ CFSocketRef theSocket = CFSocketCreate(kCFAllocatorDefault,
+ addressFamily,
+ SOCK_STREAM,
+ 0,
+ kCFSocketAcceptCallBack, // Callback flags
+ (CFSocketCallBack)&MyCFSocketCallback, // Callback method
+ &theContext);
+
+ if(theSocket == NULL)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ }
+
+ return theSocket;
+}
+
+- (BOOL)createSocketForAddress:(NSData *)remoteAddr error:(NSError **)errPtr
+{
+ struct sockaddr *pSockAddr = (struct sockaddr *)[remoteAddr bytes];
+
+ if(pSockAddr->sa_family == AF_INET)
+ {
+ theSocket4 = CFSocketCreate(NULL, // Default allocator
+ PF_INET, // Protocol Family
+ SOCK_STREAM, // Socket Type
+ IPPROTO_TCP, // Protocol
+ kCFSocketConnectCallBack, // Callback flags
+ (CFSocketCallBack)&MyCFSocketCallback, // Callback method
+ &theContext); // Socket Context
+
+ if(theSocket4 == NULL)
+ {
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ }
+ else if(pSockAddr->sa_family == AF_INET6)
+ {
+ theSocket6 = CFSocketCreate(NULL, // Default allocator
+ PF_INET6, // Protocol Family
+ SOCK_STREAM, // Socket Type
+ IPPROTO_TCP, // Protocol
+ kCFSocketConnectCallBack, // Callback flags
+ (CFSocketCallBack)&MyCFSocketCallback, // Callback method
+ &theContext); // Socket Context
+
+ if(theSocket6 == NULL)
+ {
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ }
+ else
+ {
+ if (errPtr)
+ {
+ NSString *errMsg = @"Remote address is not IPv4 or IPv6";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketCFSocketError userInfo:info];
+ }
+ return NO;
+ }
+
+ return YES;
+}
+
+- (BOOL)bindSocketToAddress:(NSData *)interfaceAddr error:(NSError **)errPtr
+{
+ if (interfaceAddr == nil) return YES;
+
+ struct sockaddr *pSockAddr = (struct sockaddr *)[interfaceAddr bytes];
+
+ CFSocketRef theSocket = (theSocket4 != NULL) ? theSocket4 : theSocket6;
+ NSAssert((theSocket != NULL), @"bindSocketToAddress called without valid socket");
+
+ CFSocketNativeHandle nativeSocket = CFSocketGetNative(theSocket);
+
+ if (pSockAddr->sa_family == AF_INET || pSockAddr->sa_family == AF_INET6)
+ {
+ int result = bind(nativeSocket, pSockAddr, (socklen_t)[interfaceAddr length]);
+ if (result != 0)
+ {
+ if (errPtr) *errPtr = [self getErrnoError];
+ return NO;
+ }
+ }
+ else
+ {
+ if (errPtr)
+ {
+ NSString *errMsg = @"Interface address is not IPv4 or IPv6";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketCFSocketError userInfo:info];
+ }
+ return NO;
+ }
+
+ return YES;
+}
+
+/**
+ * Adds the CFSocket's to the run-loop so that callbacks will work properly.
+**/
+- (BOOL)attachSocketsToRunLoop:(NSRunLoop *)runLoop error:(NSError **)errPtr
+{
+ #pragma unused(errPtr)
+
+ // Get the CFRunLoop to which the socket should be attached.
+ theRunLoop = (runLoop == nil) ? CFRunLoopGetCurrent() : [runLoop getCFRunLoop];
+
+ if(theSocket4)
+ {
+ theSource4 = CFSocketCreateRunLoopSource (kCFAllocatorDefault, theSocket4, 0);
+ [self runLoopAddSource:theSource4];
+ }
+
+ if(theSocket6)
+ {
+ theSource6 = CFSocketCreateRunLoopSource (kCFAllocatorDefault, theSocket6, 0);
+ [self runLoopAddSource:theSource6];
+ }
+
+ return YES;
+}
+
+/**
+ * Allows the delegate method to configure the CFSocket or CFNativeSocket as desired before we connect.
+ * Note that the CFReadStream and CFWriteStream will not be available until after the connection is opened.
+**/
+- (BOOL)configureSocketAndReturnError:(NSError **)errPtr
+{
+ // Call the delegate method for further configuration.
+ if([theDelegate respondsToSelector:@selector(onSocketWillConnect:)])
+ {
+ if([theDelegate onSocketWillConnect:self] == NO)
+ {
+ if (errPtr) *errPtr = [self getAbortError];
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (BOOL)connectSocketToAddress:(NSData *)remoteAddr error:(NSError **)errPtr
+{
+ // Start connecting to the given address in the background
+ // The MyCFSocketCallback method will be called when the connection succeeds or fails
+ if(theSocket4)
+ {
+ CFSocketError err = CFSocketConnectToAddress(theSocket4, (__bridge CFDataRef)remoteAddr, -1);
+ if(err != kCFSocketSuccess)
+ {
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ }
+ else if(theSocket6)
+ {
+ CFSocketError err = CFSocketConnectToAddress(theSocket6, (__bridge CFDataRef)remoteAddr, -1);
+ if(err != kCFSocketSuccess)
+ {
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ }
+
+ return YES;
+}
+
+/**
+ * Attempt to make the new socket.
+ * If an error occurs, ignore this event.
+**/
+- (void)doAcceptFromSocket:(CFSocketRef)parentSocket withNewNativeSocket:(CFSocketNativeHandle)newNativeSocket
+{
+ if(newNativeSocket)
+ {
+ // New socket inherits same delegate and run loop modes.
+ // Note: We use [self class] to support subclassing AsyncSocket.
+ AsyncSocket *newSocket = [[[self class] alloc] initWithDelegate:theDelegate];
+ [newSocket setRunLoopModes:theRunLoopModes];
+
+ if (![newSocket createStreamsFromNative:newNativeSocket error:nil])
+ {
+ [newSocket close];
+ return;
+ }
+
+ if (parentSocket == theSocket4)
+ newSocket->theNativeSocket4 = newNativeSocket;
+ else
+ newSocket->theNativeSocket6 = newNativeSocket;
+
+ if ([theDelegate respondsToSelector:@selector(onSocket:didAcceptNewSocket:)])
+ [theDelegate onSocket:self didAcceptNewSocket:newSocket];
+
+ newSocket->theFlags |= kDidStartDelegate;
+
+ NSRunLoop *runLoop = nil;
+ if ([theDelegate respondsToSelector:@selector(onSocket:wantsRunLoopForNewSocket:)])
+ {
+ runLoop = [theDelegate onSocket:self wantsRunLoopForNewSocket:newSocket];
+ }
+
+ if(![newSocket attachStreamsToRunLoop:runLoop error:nil]) goto Failed;
+ if(![newSocket configureStreamsAndReturnError:nil]) goto Failed;
+ if(![newSocket openStreamsAndReturnError:nil]) goto Failed;
+
+ return;
+
+ Failed:
+ [newSocket close];
+ }
+}
+
+/**
+ * This method is called as a result of connectToAddress:withTimeout:error:.
+ * At this point we have an open CFSocket from which we need to create our read and write stream.
+**/
+- (void)doSocketOpen:(CFSocketRef)sock withCFSocketError:(CFSocketError)socketError
+{
+ NSParameterAssert ((sock == theSocket4) || (sock == theSocket6));
+
+ if(socketError == kCFSocketTimeout || socketError == kCFSocketError)
+ {
+ [self closeWithError:[self getSocketError]];
+ return;
+ }
+
+ // Get the underlying native (BSD) socket
+ CFSocketNativeHandle nativeSocket = CFSocketGetNative(sock);
+
+ // Store a reference to it
+ if (sock == theSocket4)
+ theNativeSocket4 = nativeSocket;
+ else
+ theNativeSocket6 = nativeSocket;
+
+ // Setup the CFSocket so that invalidating it will not close the underlying native socket
+ CFSocketSetSocketFlags(sock, 0);
+
+ // Invalidate and release the CFSocket - All we need from here on out is the nativeSocket.
+ // Note: If we don't invalidate the CFSocket (leaving the native socket open)
+ // then theReadStream and theWriteStream won't function properly.
+ // Specifically, their callbacks won't work, with the exception of kCFStreamEventOpenCompleted.
+ //
+ // This is likely due to the mixture of the CFSocketCreateWithNative method,
+ // along with the CFStreamCreatePairWithSocket method.
+ // The documentation for CFSocketCreateWithNative states:
+ //
+ // If a CFSocket object already exists for sock,
+ // the function returns the pre-existing object instead of creating a new object;
+ // the context, callout, and callBackTypes parameters are ignored in this case.
+ //
+ // So the CFStreamCreateWithNative method invokes the CFSocketCreateWithNative method,
+ // thinking that is creating a new underlying CFSocket for it's own purposes.
+ // When it does this, it uses the context/callout/callbackTypes parameters to setup everything appropriately.
+ // However, if a CFSocket already exists for the native socket,
+ // then it is returned (as per the documentation), which in turn screws up the CFStreams.
+
+ CFSocketInvalidate(sock);
+ CFRelease(sock);
+ theSocket4 = NULL;
+ theSocket6 = NULL;
+
+ NSError *err;
+ BOOL pass = YES;
+
+ if(pass && ![self createStreamsFromNative:nativeSocket error:&err]) pass = NO;
+ if(pass && ![self attachStreamsToRunLoop:nil error:&err]) pass = NO;
+ if(pass && ![self openStreamsAndReturnError:&err]) pass = NO;
+
+ if(!pass)
+ {
+ [self closeWithError:err];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Stream Implementation
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Creates the CFReadStream and CFWriteStream from the given native socket.
+ * The CFSocket may be extracted from either stream after the streams have been opened.
+ *
+ * Note: The given native socket must already be connected!
+**/
+- (BOOL)createStreamsFromNative:(CFSocketNativeHandle)native error:(NSError **)errPtr
+{
+ // Create the socket & streams.
+ CFStreamCreatePairWithSocket(kCFAllocatorDefault, native, &theReadStream, &theWriteStream);
+ if (theReadStream == NULL || theWriteStream == NULL)
+ {
+ NSError *err = [self getStreamError];
+
+ NSLog(@"AsyncSocket %p couldn't create streams from accepted socket: %@", self, err);
+
+ if (errPtr) *errPtr = err;
+ return NO;
+ }
+
+ // Ensure the CF & BSD socket is closed when the streams are closed.
+ CFReadStreamSetProperty(theReadStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+ CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+
+ return YES;
+}
+
+/**
+ * Creates the CFReadStream and CFWriteStream from the given hostname and port number.
+ * The CFSocket may be extracted from either stream after the streams have been opened.
+**/
+- (BOOL)createStreamsToHost:(NSString *)hostname onPort:(UInt16)port error:(NSError **)errPtr
+{
+ // Create the socket & streams.
+ CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)hostname, port, &theReadStream, &theWriteStream);
+ if (theReadStream == NULL || theWriteStream == NULL)
+ {
+ if (errPtr) *errPtr = [self getStreamError];
+ return NO;
+ }
+
+ // Ensure the CF & BSD socket is closed when the streams are closed.
+ CFReadStreamSetProperty(theReadStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+ CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+
+ return YES;
+}
+
+- (BOOL)attachStreamsToRunLoop:(NSRunLoop *)runLoop error:(NSError **)errPtr
+{
+ // Get the CFRunLoop to which the socket should be attached.
+ theRunLoop = (runLoop == nil) ? CFRunLoopGetCurrent() : [runLoop getCFRunLoop];
+
+ // Setup read stream callbacks
+
+ CFOptionFlags readStreamEvents = kCFStreamEventHasBytesAvailable |
+ kCFStreamEventErrorOccurred |
+ kCFStreamEventEndEncountered |
+ kCFStreamEventOpenCompleted;
+
+ if (!CFReadStreamSetClient(theReadStream,
+ readStreamEvents,
+ (CFReadStreamClientCallBack)&MyCFReadStreamCallback,
+ (CFStreamClientContext *)(&theContext)))
+ {
+ NSError *err = [self getStreamError];
+
+ NSLog (@"AsyncSocket %p couldn't attach read stream to run-loop,", self);
+ NSLog (@"Error: %@", err);
+
+ if (errPtr) *errPtr = err;
+ return NO;
+ }
+
+ // Setup write stream callbacks
+
+ CFOptionFlags writeStreamEvents = kCFStreamEventCanAcceptBytes |
+ kCFStreamEventErrorOccurred |
+ kCFStreamEventEndEncountered |
+ kCFStreamEventOpenCompleted;
+
+ if (!CFWriteStreamSetClient (theWriteStream,
+ writeStreamEvents,
+ (CFWriteStreamClientCallBack)&MyCFWriteStreamCallback,
+ (CFStreamClientContext *)(&theContext)))
+ {
+ NSError *err = [self getStreamError];
+
+ NSLog (@"AsyncSocket %p couldn't attach write stream to run-loop,", self);
+ NSLog (@"Error: %@", err);
+
+ if (errPtr) *errPtr = err;
+ return NO;
+ }
+
+ // Add read and write streams to run loop
+
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFReadStreamScheduleWithRunLoop(theReadStream, theRunLoop, (__bridge CFStringRef)runLoopMode);
+ CFWriteStreamScheduleWithRunLoop(theWriteStream, theRunLoop, (__bridge CFStringRef)runLoopMode);
+ }
+
+ return YES;
+}
+
+/**
+ * Allows the delegate method to configure the CFReadStream and/or CFWriteStream as desired before we connect.
+ *
+ * If being called from a connect method,
+ * the CFSocket and CFNativeSocket will not be available until after the connection is opened.
+**/
+- (BOOL)configureStreamsAndReturnError:(NSError **)errPtr
+{
+ // Call the delegate method for further configuration.
+ if([theDelegate respondsToSelector:@selector(onSocketWillConnect:)])
+ {
+ if([theDelegate onSocketWillConnect:self] == NO)
+ {
+ if (errPtr) *errPtr = [self getAbortError];
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (BOOL)openStreamsAndReturnError:(NSError **)errPtr
+{
+ BOOL pass = YES;
+
+ if(pass && !CFReadStreamOpen(theReadStream))
+ {
+ NSLog (@"AsyncSocket %p couldn't open read stream,", self);
+ pass = NO;
+ }
+
+ if(pass && !CFWriteStreamOpen(theWriteStream))
+ {
+ NSLog (@"AsyncSocket %p couldn't open write stream,", self);
+ pass = NO;
+ }
+
+ if(!pass)
+ {
+ if (errPtr) *errPtr = [self getStreamError];
+ }
+
+ return pass;
+}
+
+/**
+ * Called when read or write streams open.
+ * When the socket is connected and both streams are open, consider the AsyncSocket instance to be ready.
+**/
+- (void)doStreamOpen
+{
+ if ((theFlags & kDidCompleteOpenForRead) && (theFlags & kDidCompleteOpenForWrite))
+ {
+ NSError *err = nil;
+
+ // Get the socket
+ if (![self setSocketFromStreamsAndReturnError: &err])
+ {
+ NSLog (@"AsyncSocket %p couldn't get socket from streams, %@. Disconnecting.", self, err);
+ [self closeWithError:err];
+ return;
+ }
+
+ // Stop the connection attempt timeout timer
+ [self endConnectTimeout];
+
+ if ([theDelegate respondsToSelector:@selector(onSocket:didConnectToHost:port:)])
+ {
+ [theDelegate onSocket:self didConnectToHost:[self connectedHost] port:[self connectedPort]];
+ }
+
+ // Immediately deal with any already-queued requests.
+ [self maybeDequeueRead];
+ [self maybeDequeueWrite];
+ }
+}
+
+- (BOOL)setSocketFromStreamsAndReturnError:(NSError **)errPtr
+{
+ // Get the CFSocketNativeHandle from theReadStream
+ CFSocketNativeHandle native;
+ CFDataRef nativeProp = CFReadStreamCopyProperty(theReadStream, kCFStreamPropertySocketNativeHandle);
+ if(nativeProp == NULL)
+ {
+ if (errPtr) *errPtr = [self getStreamError];
+ return NO;
+ }
+
+ CFIndex nativePropLen = CFDataGetLength(nativeProp);
+ CFIndex nativeLen = (CFIndex)sizeof(native);
+
+ CFIndex len = MIN(nativePropLen, nativeLen);
+
+ CFDataGetBytes(nativeProp, CFRangeMake(0, len), (UInt8 *)&native);
+ CFRelease(nativeProp);
+
+ CFSocketRef theSocket = CFSocketCreateWithNative(kCFAllocatorDefault, native, 0, NULL, NULL);
+ if(theSocket == NULL)
+ {
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+
+ // Determine whether the connection was IPv4 or IPv6.
+ // We may already know if this was an accepted socket,
+ // or if the connectToAddress method was used.
+ // In either of the above two cases, the native socket variable would already be set.
+
+ if (theNativeSocket4 > 0)
+ {
+ theSocket4 = theSocket;
+ return YES;
+ }
+ if (theNativeSocket6 > 0)
+ {
+ theSocket6 = theSocket;
+ return YES;
+ }
+
+ CFDataRef peeraddr = CFSocketCopyPeerAddress(theSocket);
+ if(peeraddr == NULL)
+ {
+ NSLog(@"AsyncSocket couldn't determine IP version of socket");
+
+ CFRelease(theSocket);
+
+ if (errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ struct sockaddr *sa = (struct sockaddr *)CFDataGetBytePtr(peeraddr);
+
+ if(sa->sa_family == AF_INET)
+ {
+ theSocket4 = theSocket;
+ theNativeSocket4 = native;
+ }
+ else
+ {
+ theSocket6 = theSocket;
+ theNativeSocket6 = native;
+ }
+
+ CFRelease(peeraddr);
+
+ return YES;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Disconnect Implementation
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// Sends error message and disconnects
+- (void)closeWithError:(NSError *)err
+{
+ theFlags |= kClosingWithError;
+
+ if (theFlags & kDidStartDelegate)
+ {
+ // Try to salvage what data we can.
+ [self recoverUnreadData];
+
+ // Let the delegate know, so it can try to recover if it likes.
+ if ([theDelegate respondsToSelector:@selector(onSocket:willDisconnectWithError:)])
+ {
+ [theDelegate onSocket:self willDisconnectWithError:err];
+ }
+ }
+ [self close];
+}
+
+// Prepare partially read data for recovery.
+- (void)recoverUnreadData
+{
+ if(theCurrentRead != nil)
+ {
+ // We never finished the current read.
+ // Check to see if it's a normal read packet (not AsyncSpecialPacket) and if it had read anything yet.
+
+ if(([theCurrentRead isKindOfClass:[AsyncReadPacket class]]) && (theCurrentRead->bytesDone > 0))
+ {
+ // We need to move its data into the front of the partial read buffer.
+
+ void *buffer = [theCurrentRead->buffer mutableBytes] + theCurrentRead->startOffset;
+
+ [partialReadBuffer replaceBytesInRange:NSMakeRange(0, 0)
+ withBytes:buffer
+ length:theCurrentRead->bytesDone];
+ }
+ }
+
+ [self emptyQueues];
+}
+
+- (void)emptyQueues
+{
+ if (theCurrentRead != nil) [self endCurrentRead];
+ if (theCurrentWrite != nil) [self endCurrentWrite];
+
+ [theReadQueue removeAllObjects];
+ [theWriteQueue removeAllObjects];
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(maybeDequeueRead) object:nil];
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(maybeDequeueWrite) object:nil];
+
+ theFlags &= ~kDequeueReadScheduled;
+ theFlags &= ~kDequeueWriteScheduled;
+}
+
+/**
+ * Disconnects. This is called for both error and clean disconnections.
+**/
+- (void)close
+{
+ // Empty queues
+ [self emptyQueues];
+
+ // Clear partialReadBuffer (pre-buffer and also unreadData buffer in case of error)
+ [partialReadBuffer replaceBytesInRange:NSMakeRange(0, [partialReadBuffer length]) withBytes:NULL length:0];
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(disconnect) object:nil];
+
+ // Stop the connection attempt timeout timer
+ if (theConnectTimer != nil)
+ {
+ [self endConnectTimeout];
+ }
+
+ // Close streams.
+ if (theReadStream != NULL)
+ {
+ [self runLoopUnscheduleReadStream];
+ CFReadStreamClose(theReadStream);
+ CFRelease(theReadStream);
+ theReadStream = NULL;
+ }
+ if (theWriteStream != NULL)
+ {
+ [self runLoopUnscheduleWriteStream];
+ CFWriteStreamClose(theWriteStream);
+ CFRelease(theWriteStream);
+ theWriteStream = NULL;
+ }
+
+ // Close sockets.
+ if (theSocket4 != NULL)
+ {
+ CFSocketInvalidate (theSocket4);
+ CFRelease (theSocket4);
+ theSocket4 = NULL;
+ }
+ if (theSocket6 != NULL)
+ {
+ CFSocketInvalidate (theSocket6);
+ CFRelease (theSocket6);
+ theSocket6 = NULL;
+ }
+
+ // Closing the streams or sockets resulted in closing the underlying native socket
+ theNativeSocket4 = 0;
+ theNativeSocket6 = 0;
+
+ // Remove run loop sources
+ if (theSource4 != NULL)
+ {
+ [self runLoopRemoveSource:theSource4];
+ CFRelease (theSource4);
+ theSource4 = NULL;
+ }
+ if (theSource6 != NULL)
+ {
+ [self runLoopRemoveSource:theSource6];
+ CFRelease (theSource6);
+ theSource6 = NULL;
+ }
+ theRunLoop = NULL;
+
+ // If the client has passed the connect/accept method, then the connection has at least begun.
+ // Notify delegate that it is now ending.
+ BOOL shouldCallDelegate = (theFlags & kDidStartDelegate);
+
+ // Clear all flags (except the pre-buffering flag, which should remain as is)
+ theFlags &= kEnablePreBuffering;
+
+ if (shouldCallDelegate)
+ {
+ if ([theDelegate respondsToSelector: @selector(onSocketDidDisconnect:)])
+ {
+ [theDelegate onSocketDidDisconnect:self];
+ }
+ }
+
+ // Do not access any instance variables after calling onSocketDidDisconnect.
+ // This gives the delegate freedom to release us without returning here and crashing.
+}
+
+/**
+ * Disconnects immediately. Any pending reads or writes are dropped.
+**/
+- (void)disconnect
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ [self close];
+}
+
+/**
+ * Diconnects after all pending reads have completed.
+**/
+- (void)disconnectAfterReading
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theFlags |= (kForbidReadsWrites | kDisconnectAfterReads);
+
+ [self maybeScheduleDisconnect];
+}
+
+/**
+ * Disconnects after all pending writes have completed.
+**/
+- (void)disconnectAfterWriting
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theFlags |= (kForbidReadsWrites | kDisconnectAfterWrites);
+
+ [self maybeScheduleDisconnect];
+}
+
+/**
+ * Disconnects after all pending reads and writes have completed.
+**/
+- (void)disconnectAfterReadingAndWriting
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ theFlags |= (kForbidReadsWrites | kDisconnectAfterReads | kDisconnectAfterWrites);
+
+ [self maybeScheduleDisconnect];
+}
+
+/**
+ * Schedules a call to disconnect if possible.
+ * That is, if all writes have completed, and we're set to disconnect after writing,
+ * or if all reads have completed, and we're set to disconnect after reading.
+**/
+- (void)maybeScheduleDisconnect
+{
+ BOOL shouldDisconnect = NO;
+
+ if(theFlags & kDisconnectAfterReads)
+ {
+ if(([theReadQueue count] == 0) && (theCurrentRead == nil))
+ {
+ if(theFlags & kDisconnectAfterWrites)
+ {
+ if(([theWriteQueue count] == 0) && (theCurrentWrite == nil))
+ {
+ shouldDisconnect = YES;
+ }
+ }
+ else
+ {
+ shouldDisconnect = YES;
+ }
+ }
+ }
+ else if(theFlags & kDisconnectAfterWrites)
+ {
+ if(([theWriteQueue count] == 0) && (theCurrentWrite == nil))
+ {
+ shouldDisconnect = YES;
+ }
+ }
+
+ if(shouldDisconnect)
+ {
+ [self performSelector:@selector(disconnect) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+/**
+ * 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
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ // Ensure this method will only return data in the event of an error
+ if (!(theFlags & kClosingWithError)) return nil;
+
+ if (theReadStream == NULL) return nil;
+
+ NSUInteger totalBytesRead = [partialReadBuffer length];
+
+ BOOL error = NO;
+ while (!error && CFReadStreamHasBytesAvailable(theReadStream))
+ {
+ if (totalBytesRead == [partialReadBuffer length])
+ {
+ [partialReadBuffer increaseLengthBy:READALL_CHUNKSIZE];
+ }
+
+ // Number of bytes to read is space left in packet buffer.
+ NSUInteger bytesToRead = [partialReadBuffer length] - totalBytesRead;
+
+ // Read data into packet buffer
+ UInt8 *packetbuf = (UInt8 *)( [partialReadBuffer mutableBytes] + totalBytesRead );
+
+ CFIndex result = CFReadStreamRead(theReadStream, packetbuf, bytesToRead);
+
+ // Check results
+ if (result < 0)
+ {
+ error = YES;
+ }
+ else
+ {
+ CFIndex bytesRead = result;
+
+ totalBytesRead += bytesRead;
+ }
+ }
+
+ [partialReadBuffer setLength:totalBytesRead];
+
+ return partialReadBuffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Errors
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns a standard error object for the current errno value.
+ * Errno is used for low-level BSD socket errors.
+**/
+- (NSError *)getErrnoError
+{
+ NSString *errorMsg = [NSString stringWithUTF8String:strerror(errno)];
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:errorMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:userInfo];
+}
+
+/**
+ * Returns a standard error message for a CFSocket error.
+ * Unfortunately, CFSocket offers no feedback on its errors.
+**/
+- (NSError *)getSocketError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketCFSocketError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"General CFSocket error", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketCFSocketError userInfo:info];
+}
+
+- (NSError *)getStreamError
+{
+ CFStreamError err;
+ if (theReadStream != NULL)
+ {
+ err = CFReadStreamGetError (theReadStream);
+ if (err.error != 0) return [self errorFromCFStreamError: err];
+ }
+
+ if (theWriteStream != NULL)
+ {
+ err = CFWriteStreamGetError (theWriteStream);
+ if (err.error != 0) return [self errorFromCFStreamError: err];
+ }
+
+ return nil;
+}
+
+/**
+ * Returns a standard AsyncSocket abort error.
+**/
+- (NSError *)getAbortError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketCanceledError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"Connection canceled", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketCanceledError userInfo:info];
+}
+
+/**
+ * Returns a standard AsyncSocket connect timeout error.
+**/
+- (NSError *)getConnectTimeoutError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketConnectTimeoutError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"Attempt to connect to host timed out", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketConnectTimeoutError userInfo:info];
+}
+
+/**
+ * Returns a standard AsyncSocket maxed out error.
+**/
+- (NSError *)getReadMaxedOutError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketReadMaxedOutError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"Read operation reached set maximum length", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketReadMaxedOutError userInfo:info];
+}
+
+/**
+ * Returns a standard AsyncSocket read timeout error.
+**/
+- (NSError *)getReadTimeoutError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketReadTimeoutError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"Read operation timed out", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketReadTimeoutError userInfo:info];
+}
+
+/**
+ * Returns a standard AsyncSocket write timeout error.
+**/
+- (NSError *)getWriteTimeoutError
+{
+ NSString *errMsg = NSLocalizedStringWithDefaultValue(@"AsyncSocketWriteTimeoutError",
+ @"AsyncSocket", [NSBundle mainBundle],
+ @"Write operation timed out", nil);
+
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncSocketErrorDomain code:AsyncSocketWriteTimeoutError userInfo:info];
+}
+
+- (NSError *)errorFromCFStreamError:(CFStreamError)err
+{
+ if (err.domain == 0 && err.error == 0) return nil;
+
+ // Can't use switch; these constants aren't int literals.
+ NSString *domain = @"CFStreamError (unlisted domain)";
+ NSString *message = nil;
+
+ if(err.domain == kCFStreamErrorDomainPOSIX) {
+ domain = NSPOSIXErrorDomain;
+ }
+ else if(err.domain == kCFStreamErrorDomainMacOSStatus) {
+ domain = NSOSStatusErrorDomain;
+ }
+ else if(err.domain == kCFStreamErrorDomainMach) {
+ domain = NSMachErrorDomain;
+ }
+ else if(err.domain == kCFStreamErrorDomainNetDB)
+ {
+ domain = @"kCFStreamErrorDomainNetDB";
+ message = [NSString stringWithCString:gai_strerror(err.error) encoding:NSASCIIStringEncoding];
+ }
+ else if(err.domain == kCFStreamErrorDomainNetServices) {
+ domain = @"kCFStreamErrorDomainNetServices";
+ }
+ else if(err.domain == kCFStreamErrorDomainSOCKS) {
+ domain = @"kCFStreamErrorDomainSOCKS";
+ }
+ else if(err.domain == kCFStreamErrorDomainSystemConfiguration) {
+ domain = @"kCFStreamErrorDomainSystemConfiguration";
+ }
+ else if(err.domain == kCFStreamErrorDomainSSL) {
+ domain = @"kCFStreamErrorDomainSSL";
+ }
+
+ NSDictionary *info = nil;
+ if(message != nil)
+ {
+ info = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
+ }
+ return [NSError errorWithDomain:domain code:err.error userInfo:info];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Diagnostics
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (BOOL)isDisconnected
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if (theNativeSocket4 > 0) return NO;
+ if (theNativeSocket6 > 0) return NO;
+
+ if (theSocket4) return NO;
+ if (theSocket6) return NO;
+
+ if (theReadStream) return NO;
+ if (theWriteStream) return NO;
+
+ return YES;
+}
+
+- (BOOL)isConnected
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return [self areStreamsConnected];
+}
+
+- (NSString *)connectedHost
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(theSocket4)
+ return [self connectedHostFromCFSocket4:theSocket4];
+ if(theSocket6)
+ return [self connectedHostFromCFSocket6:theSocket6];
+
+ if(theNativeSocket4 > 0)
+ return [self connectedHostFromNativeSocket4:theNativeSocket4];
+ if(theNativeSocket6 > 0)
+ return [self connectedHostFromNativeSocket6:theNativeSocket6];
+
+ return nil;
+}
+
+- (UInt16)connectedPort
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(theSocket4)
+ return [self connectedPortFromCFSocket4:theSocket4];
+ if(theSocket6)
+ return [self connectedPortFromCFSocket6:theSocket6];
+
+ if(theNativeSocket4 > 0)
+ return [self connectedPortFromNativeSocket4:theNativeSocket4];
+ if(theNativeSocket6 > 0)
+ return [self connectedPortFromNativeSocket6:theNativeSocket6];
+
+ return 0;
+}
+
+- (NSString *)localHost
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(theSocket4)
+ return [self localHostFromCFSocket4:theSocket4];
+ if(theSocket6)
+ return [self localHostFromCFSocket6:theSocket6];
+
+ if(theNativeSocket4 > 0)
+ return [self localHostFromNativeSocket4:theNativeSocket4];
+ if(theNativeSocket6 > 0)
+ return [self localHostFromNativeSocket6:theNativeSocket6];
+
+ return nil;
+}
+
+- (UInt16)localPort
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(theSocket4)
+ return [self localPortFromCFSocket4:theSocket4];
+ if(theSocket6)
+ return [self localPortFromCFSocket6:theSocket6];
+
+ if(theNativeSocket4 > 0)
+ return [self localPortFromNativeSocket4:theNativeSocket4];
+ if(theNativeSocket6 > 0)
+ return [self localPortFromNativeSocket6:theNativeSocket6];
+
+ return 0;
+}
+
+- (NSString *)connectedHost4
+{
+ if(theSocket4)
+ return [self connectedHostFromCFSocket4:theSocket4];
+ if(theNativeSocket4 > 0)
+ return [self connectedHostFromNativeSocket4:theNativeSocket4];
+
+ return nil;
+}
+
+- (NSString *)connectedHost6
+{
+ if(theSocket6)
+ return [self connectedHostFromCFSocket6:theSocket6];
+ if(theNativeSocket6 > 0)
+ return [self connectedHostFromNativeSocket6:theNativeSocket6];
+
+ return nil;
+}
+
+- (UInt16)connectedPort4
+{
+ if(theSocket4)
+ return [self connectedPortFromCFSocket4:theSocket4];
+ if(theNativeSocket4 > 0)
+ return [self connectedPortFromNativeSocket4:theNativeSocket4];
+
+ return 0;
+}
+
+- (UInt16)connectedPort6
+{
+ if(theSocket6)
+ return [self connectedPortFromCFSocket6:theSocket6];
+ if(theNativeSocket6 > 0)
+ return [self connectedPortFromNativeSocket6:theNativeSocket6];
+
+ return 0;
+}
+
+- (NSString *)localHost4
+{
+ if(theSocket4)
+ return [self localHostFromCFSocket4:theSocket4];
+ if(theNativeSocket4 > 0)
+ return [self localHostFromNativeSocket4:theNativeSocket4];
+
+ return nil;
+}
+
+- (NSString *)localHost6
+{
+ if(theSocket6)
+ return [self localHostFromCFSocket6:theSocket6];
+ if(theNativeSocket6 > 0)
+ return [self localHostFromNativeSocket6:theNativeSocket6];
+
+ return nil;
+}
+
+- (UInt16)localPort4
+{
+ if(theSocket4)
+ return [self localPortFromCFSocket4:theSocket4];
+ if(theNativeSocket4 > 0)
+ return [self localPortFromNativeSocket4:theNativeSocket4];
+
+ return 0;
+}
+
+- (UInt16)localPort6
+{
+ if(theSocket6)
+ return [self localPortFromCFSocket6:theSocket6];
+ if(theNativeSocket6 > 0)
+ return [self localPortFromNativeSocket6:theNativeSocket6];
+
+ return 0;
+}
+
+- (NSString *)connectedHostFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if(getpeername(theNativeSocket, (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return nil;
+ }
+ return [self hostFromAddress4:&sockaddr4];
+}
+
+- (NSString *)connectedHostFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if(getpeername(theNativeSocket, (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return nil;
+ }
+ return [self hostFromAddress6:&sockaddr6];
+}
+
+- (NSString *)connectedHostFromCFSocket4:(CFSocketRef)theSocket
+{
+ CFDataRef peeraddr;
+ NSString *peerstr = nil;
+
+ if((peeraddr = CFSocketCopyPeerAddress(theSocket)))
+ {
+ struct sockaddr_in *pSockAddr = (struct sockaddr_in *)CFDataGetBytePtr(peeraddr);
+
+ peerstr = [self hostFromAddress4:pSockAddr];
+ CFRelease (peeraddr);
+ }
+
+ return peerstr;
+}
+
+- (NSString *)connectedHostFromCFSocket6:(CFSocketRef)theSocket
+{
+ CFDataRef peeraddr;
+ NSString *peerstr = nil;
+
+ if((peeraddr = CFSocketCopyPeerAddress(theSocket)))
+ {
+ struct sockaddr_in6 *pSockAddr = (struct sockaddr_in6 *)CFDataGetBytePtr(peeraddr);
+
+ peerstr = [self hostFromAddress6:pSockAddr];
+ CFRelease (peeraddr);
+ }
+
+ return peerstr;
+}
+
+- (UInt16)connectedPortFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if(getpeername(theNativeSocket, (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return 0;
+ }
+ return [self portFromAddress4:&sockaddr4];
+}
+
+- (UInt16)connectedPortFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if(getpeername(theNativeSocket, (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return 0;
+ }
+ return [self portFromAddress6:&sockaddr6];
+}
+
+- (UInt16)connectedPortFromCFSocket4:(CFSocketRef)theSocket
+{
+ CFDataRef peeraddr;
+ UInt16 peerport = 0;
+
+ if((peeraddr = CFSocketCopyPeerAddress(theSocket)))
+ {
+ struct sockaddr_in *pSockAddr = (struct sockaddr_in *)CFDataGetBytePtr(peeraddr);
+
+ peerport = [self portFromAddress4:pSockAddr];
+ CFRelease (peeraddr);
+ }
+
+ return peerport;
+}
+
+- (UInt16)connectedPortFromCFSocket6:(CFSocketRef)theSocket
+{
+ CFDataRef peeraddr;
+ UInt16 peerport = 0;
+
+ if((peeraddr = CFSocketCopyPeerAddress(theSocket)))
+ {
+ struct sockaddr_in6 *pSockAddr = (struct sockaddr_in6 *)CFDataGetBytePtr(peeraddr);
+
+ peerport = [self portFromAddress6:pSockAddr];
+ CFRelease (peeraddr);
+ }
+
+ return peerport;
+}
+
+- (NSString *)localHostFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if(getsockname(theNativeSocket, (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return nil;
+ }
+ return [self hostFromAddress4:&sockaddr4];
+}
+
+- (NSString *)localHostFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if(getsockname(theNativeSocket, (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return nil;
+ }
+ return [self hostFromAddress6:&sockaddr6];
+}
+
+- (NSString *)localHostFromCFSocket4:(CFSocketRef)theSocket
+{
+ CFDataRef selfaddr;
+ NSString *selfstr = nil;
+
+ if((selfaddr = CFSocketCopyAddress(theSocket)))
+ {
+ struct sockaddr_in *pSockAddr = (struct sockaddr_in *)CFDataGetBytePtr(selfaddr);
+
+ selfstr = [self hostFromAddress4:pSockAddr];
+ CFRelease (selfaddr);
+ }
+
+ return selfstr;
+}
+
+- (NSString *)localHostFromCFSocket6:(CFSocketRef)theSocket
+{
+ CFDataRef selfaddr;
+ NSString *selfstr = nil;
+
+ if((selfaddr = CFSocketCopyAddress(theSocket)))
+ {
+ struct sockaddr_in6 *pSockAddr = (struct sockaddr_in6 *)CFDataGetBytePtr(selfaddr);
+
+ selfstr = [self hostFromAddress6:pSockAddr];
+ CFRelease (selfaddr);
+ }
+
+ return selfstr;
+}
+
+- (UInt16)localPortFromNativeSocket4:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if(getsockname(theNativeSocket, (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return 0;
+ }
+ return [self portFromAddress4:&sockaddr4];
+}
+
+- (UInt16)localPortFromNativeSocket6:(CFSocketNativeHandle)theNativeSocket
+{
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if(getsockname(theNativeSocket, (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return 0;
+ }
+ return [self portFromAddress6:&sockaddr6];
+}
+
+- (UInt16)localPortFromCFSocket4:(CFSocketRef)theSocket
+{
+ CFDataRef selfaddr;
+ UInt16 selfport = 0;
+
+ if ((selfaddr = CFSocketCopyAddress(theSocket)))
+ {
+ struct sockaddr_in *pSockAddr = (struct sockaddr_in *)CFDataGetBytePtr(selfaddr);
+
+ selfport = [self portFromAddress4:pSockAddr];
+ CFRelease (selfaddr);
+ }
+
+ return selfport;
+}
+
+- (UInt16)localPortFromCFSocket6:(CFSocketRef)theSocket
+{
+ CFDataRef selfaddr;
+ UInt16 selfport = 0;
+
+ if ((selfaddr = CFSocketCopyAddress(theSocket)))
+ {
+ struct sockaddr_in6 *pSockAddr = (struct sockaddr_in6 *)CFDataGetBytePtr(selfaddr);
+
+ selfport = [self portFromAddress6:pSockAddr];
+ CFRelease (selfaddr);
+ }
+
+ return selfport;
+}
+
+- (NSString *)hostFromAddress4:(struct sockaddr_in *)pSockaddr4
+{
+ char addrBuf[INET_ADDRSTRLEN];
+
+ if(inet_ntop(AF_INET, &pSockaddr4->sin_addr, addrBuf, (socklen_t)sizeof(addrBuf)) == NULL)
+ {
+ [NSException raise:NSInternalInconsistencyException format:@"Cannot convert IPv4 address to string."];
+ }
+
+ return [NSString stringWithCString:addrBuf encoding:NSASCIIStringEncoding];
+}
+
+- (NSString *)hostFromAddress6:(struct sockaddr_in6 *)pSockaddr6
+{
+ char addrBuf[INET6_ADDRSTRLEN];
+
+ if(inet_ntop(AF_INET6, &pSockaddr6->sin6_addr, addrBuf, (socklen_t)sizeof(addrBuf)) == NULL)
+ {
+ [NSException raise:NSInternalInconsistencyException format:@"Cannot convert IPv6 address to string."];
+ }
+
+ return [NSString stringWithCString:addrBuf encoding:NSASCIIStringEncoding];
+}
+
+- (UInt16)portFromAddress4:(struct sockaddr_in *)pSockaddr4
+{
+ return ntohs(pSockaddr4->sin_port);
+}
+
+- (UInt16)portFromAddress6:(struct sockaddr_in6 *)pSockaddr6
+{
+ return ntohs(pSockaddr6->sin6_port);
+}
+
+- (NSData *)connectedAddress
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ // Extract address from CFSocket
+
+ CFSocketRef theSocket;
+
+ if (theSocket4)
+ theSocket = theSocket4;
+ else
+ theSocket = theSocket6;
+
+ if (theSocket)
+ {
+ CFDataRef peeraddr = CFSocketCopyPeerAddress(theSocket);
+
+ if (peeraddr == NULL) return nil;
+
+ NSData *result = (__bridge_transfer NSData *)peeraddr;
+ return result;
+ }
+
+ // Extract address from CFSocketNativeHandle
+
+ socklen_t sockaddrlen;
+ CFSocketNativeHandle theNativeSocket = 0;
+
+ if (theNativeSocket4 > 0)
+ {
+ theNativeSocket = theNativeSocket4;
+ sockaddrlen = sizeof(struct sockaddr_in);
+ }
+ else
+ {
+ theNativeSocket = theNativeSocket6;
+ sockaddrlen = sizeof(struct sockaddr_in6);
+ }
+
+ NSData *result = nil;
+ void *sockaddr = malloc(sockaddrlen);
+
+ if(getpeername(theNativeSocket, (struct sockaddr *)sockaddr, &sockaddrlen) >= 0)
+ {
+ result = [NSData dataWithBytesNoCopy:sockaddr length:sockaddrlen freeWhenDone:YES];
+ }
+ else
+ {
+ free(sockaddr);
+ }
+
+ return result;
+}
+
+- (NSData *)localAddress
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ // Extract address from CFSocket
+
+ CFSocketRef theSocket;
+
+ if (theSocket4)
+ theSocket = theSocket4;
+ else
+ theSocket = theSocket6;
+
+ if (theSocket)
+ {
+ CFDataRef selfaddr = CFSocketCopyAddress(theSocket);
+
+ if (selfaddr == NULL) return nil;
+
+ NSData *result = (__bridge_transfer NSData *)selfaddr;
+ return result;
+ }
+
+ // Extract address from CFSocketNativeHandle
+
+ socklen_t sockaddrlen;
+ CFSocketNativeHandle theNativeSocket = 0;
+
+ if (theNativeSocket4 > 0)
+ {
+ theNativeSocket = theNativeSocket4;
+ sockaddrlen = sizeof(struct sockaddr_in);
+ }
+ else
+ {
+ theNativeSocket = theNativeSocket6;
+ sockaddrlen = sizeof(struct sockaddr_in6);
+ }
+
+ NSData *result = nil;
+ void *sockaddr = malloc(sockaddrlen);
+
+ if(getsockname(theNativeSocket, (struct sockaddr *)sockaddr, &sockaddrlen) >= 0)
+ {
+ result = [NSData dataWithBytesNoCopy:sockaddr length:sockaddrlen freeWhenDone:YES];
+ }
+ else
+ {
+ free(sockaddr);
+ }
+
+ return result;
+}
+
+- (BOOL)isIPv4
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return (theNativeSocket4 > 0 || theSocket4 != NULL);
+}
+
+- (BOOL)isIPv6
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ return (theNativeSocket6 > 0 || theSocket6 != NULL);
+}
+
+- (BOOL)areStreamsConnected
+{
+ CFStreamStatus s;
+
+ if (theReadStream != NULL)
+ {
+ s = CFReadStreamGetStatus(theReadStream);
+ if ( !(s == kCFStreamStatusOpen || s == kCFStreamStatusReading || s == kCFStreamStatusError) )
+ return NO;
+ }
+ else return NO;
+
+ if (theWriteStream != NULL)
+ {
+ s = CFWriteStreamGetStatus(theWriteStream);
+ if ( !(s == kCFStreamStatusOpen || s == kCFStreamStatusWriting || s == kCFStreamStatusError) )
+ return NO;
+ }
+ else return NO;
+
+ return YES;
+}
+
+- (NSString *)description
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ static const char *statstr[] = {"not open","opening","open","reading","writing","at end","closed","has error"};
+ CFStreamStatus rs = (theReadStream != NULL) ? CFReadStreamGetStatus(theReadStream) : 0;
+ CFStreamStatus ws = (theWriteStream != NULL) ? CFWriteStreamGetStatus(theWriteStream) : 0;
+
+ NSString *peerstr, *selfstr;
+
+ BOOL is4 = [self isIPv4];
+ BOOL is6 = [self isIPv6];
+
+ if (is4 || is6)
+ {
+ if (is4 && is6)
+ {
+ peerstr = [NSString stringWithFormat: @"%@/%@ %u",
+ [self connectedHost4],
+ [self connectedHost6],
+ [self connectedPort]];
+ }
+ else if (is4)
+ {
+ peerstr = [NSString stringWithFormat: @"%@ %u",
+ [self connectedHost4],
+ [self connectedPort4]];
+ }
+ else
+ {
+ peerstr = [NSString stringWithFormat: @"%@ %u",
+ [self connectedHost6],
+ [self connectedPort6]];
+ }
+ }
+ else peerstr = @"nowhere";
+
+ if (is4 || is6)
+ {
+ if (is4 && is6)
+ {
+ selfstr = [NSString stringWithFormat: @"%@/%@ %u",
+ [self localHost4],
+ [self localHost6],
+ [self localPort]];
+ }
+ else if (is4)
+ {
+ selfstr = [NSString stringWithFormat: @"%@ %u",
+ [self localHost4],
+ [self localPort4]];
+ }
+ else
+ {
+ selfstr = [NSString stringWithFormat: @"%@ %u",
+ [self localHost6],
+ [self localPort6]];
+ }
+ }
+ else selfstr = @"nowhere";
+
+ NSMutableString *ms = [[NSMutableString alloc] initWithCapacity:150];
+
+ [ms appendString:[NSString stringWithFormat:@"readLength > 0)
+ percentDone = (float)theCurrentRead->bytesDone / (float)theCurrentRead->readLength * 100.0F;
+ else
+ percentDone = 100.0F;
+
+ [ms appendString: [NSString stringWithFormat:@"currently read %u bytes (%d%% done), ",
+ (unsigned int)[theCurrentRead->buffer length],
+ theCurrentRead->bytesDone ? percentDone : 0]];
+ }
+
+ if (theCurrentWrite == nil || [theCurrentWrite isKindOfClass:[AsyncSpecialPacket class]])
+ [ms appendString: @"no current write, "];
+ else
+ {
+ int percentDone = (float)theCurrentWrite->bytesDone / (float)[theCurrentWrite->buffer length] * 100.0F;
+
+ [ms appendString: [NSString stringWithFormat:@"currently written %u (%d%%), ",
+ (unsigned int)[theCurrentWrite->buffer length],
+ theCurrentWrite->bytesDone ? percentDone : 0]];
+ }
+
+ [ms appendString:[NSString stringWithFormat:@"read stream %p %s, ", theReadStream, statstr[rs]]];
+ [ms appendString:[NSString stringWithFormat:@"write stream %p %s", theWriteStream, statstr[ws]]];
+
+ if(theFlags & kDisconnectAfterReads)
+ {
+ if(theFlags & kDisconnectAfterWrites)
+ [ms appendString: @", will disconnect after reads & writes"];
+ else
+ [ms appendString: @", will disconnect after reads"];
+ }
+ else if(theFlags & kDisconnectAfterWrites)
+ {
+ [ms appendString: @", will disconnect after writes"];
+ }
+
+ if (![self isConnected]) [ms appendString: @", not connected"];
+
+ [ms appendString:@">"];
+
+ return ms;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Reading
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)readDataWithTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ [self readDataWithTimeout:timeout buffer:nil bufferOffset:0 maxLength:0 tag:tag];
+}
+
+- (void)readDataWithTimeout:(NSTimeInterval)timeout
+ buffer:(NSMutableData *)buffer
+ bufferOffset:(NSUInteger)offset
+ tag:(long)tag
+{
+ [self readDataWithTimeout:timeout buffer:buffer bufferOffset:offset maxLength:0 tag:tag];
+}
+
+- (void)readDataWithTimeout:(NSTimeInterval)timeout
+ buffer:(NSMutableData *)buffer
+ bufferOffset:(NSUInteger)offset
+ maxLength:(NSUInteger)length
+ tag:(long)tag
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if (offset > [buffer length]) return;
+ if (theFlags & kForbidReadsWrites) return;
+
+ AsyncReadPacket *packet = [[AsyncReadPacket alloc] initWithData:buffer
+ startOffset:offset
+ maxLength:length
+ timeout:timeout
+ readLength:0
+ terminator:nil
+ tag:tag];
+ [theReadQueue addObject:packet];
+ [self scheduleDequeueRead];
+
+}
+
+- (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ [self readDataToLength:length withTimeout:timeout buffer:nil bufferOffset:0 tag:tag];
+}
+
+- (void)readDataToLength:(NSUInteger)length
+ withTimeout:(NSTimeInterval)timeout
+ buffer:(NSMutableData *)buffer
+ bufferOffset:(NSUInteger)offset
+ tag:(long)tag
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if (length == 0) return;
+ if (offset > [buffer length]) return;
+ if (theFlags & kForbidReadsWrites) return;
+
+ AsyncReadPacket *packet = [[AsyncReadPacket alloc] initWithData:buffer
+ startOffset:offset
+ maxLength:0
+ timeout:timeout
+ readLength:length
+ terminator:nil
+ tag:tag];
+ [theReadQueue addObject:packet];
+ [self scheduleDequeueRead];
+
+}
+
+- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ [self readDataToData:data withTimeout:timeout buffer:nil bufferOffset:0 maxLength:0 tag:tag];
+}
+
+- (void)readDataToData:(NSData *)data
+ withTimeout:(NSTimeInterval)timeout
+ buffer:(NSMutableData *)buffer
+ bufferOffset:(NSUInteger)offset
+ tag:(long)tag
+{
+ [self readDataToData:data withTimeout:timeout buffer:buffer bufferOffset:offset maxLength:0 tag:tag];
+}
+
+- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout maxLength:(NSUInteger)length tag:(long)tag
+{
+ [self readDataToData:data withTimeout:timeout buffer:nil bufferOffset:0 maxLength:length tag:tag];
+}
+
+- (void)readDataToData:(NSData *)data
+ withTimeout:(NSTimeInterval)timeout
+ buffer:(NSMutableData *)buffer
+ bufferOffset:(NSUInteger)offset
+ maxLength:(NSUInteger)length
+ tag:(long)tag
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if (data == nil || [data length] == 0) return;
+ if (offset > [buffer length]) return;
+ if (length > 0 && length < [data length]) return;
+ if (theFlags & kForbidReadsWrites) return;
+
+ AsyncReadPacket *packet = [[AsyncReadPacket alloc] initWithData:buffer
+ startOffset:offset
+ maxLength:length
+ timeout:timeout
+ readLength:0
+ terminator:data
+ tag:tag];
+ [theReadQueue addObject:packet];
+ [self scheduleDequeueRead];
+
+}
+
+/**
+ * Puts a maybeDequeueRead on the run loop.
+ * An assumption here is that selectors will be performed consecutively within their priority.
+**/
+- (void)scheduleDequeueRead
+{
+ if((theFlags & kDequeueReadScheduled) == 0)
+ {
+ theFlags |= kDequeueReadScheduled;
+ [self performSelector:@selector(maybeDequeueRead) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+/**
+ * This method starts a new read, if needed.
+ * It is called when a user requests a read,
+ * or when a stream opens that may have requested reads sitting in the queue, etc.
+**/
+- (void)maybeDequeueRead
+{
+ // Unset the flag indicating a call to this method is scheduled
+ theFlags &= ~kDequeueReadScheduled;
+
+ // If we're not currently processing a read AND we have an available read stream
+ if((theCurrentRead == nil) && (theReadStream != NULL))
+ {
+ if([theReadQueue count] > 0)
+ {
+ // Dequeue the next object in the write queue
+ theCurrentRead = [theReadQueue objectAtIndex:0];
+ [theReadQueue removeObjectAtIndex:0];
+
+ if([theCurrentRead isKindOfClass:[AsyncSpecialPacket class]])
+ {
+ // Attempt to start TLS
+ theFlags |= kStartingReadTLS;
+
+ // This method won't do anything unless both kStartingReadTLS and kStartingWriteTLS are set
+ [self maybeStartTLS];
+ }
+ else
+ {
+ // Start time-out timer
+ if(theCurrentRead->timeout >= 0.0)
+ {
+ theReadTimer = [NSTimer timerWithTimeInterval:theCurrentRead->timeout
+ target:self
+ selector:@selector(doReadTimeout:)
+ userInfo:nil
+ repeats:NO];
+ [self runLoopAddTimer:theReadTimer];
+ }
+
+ // Immediately read, if possible
+ [self doBytesAvailable];
+ }
+ }
+ else if(theFlags & kDisconnectAfterReads)
+ {
+ if(theFlags & kDisconnectAfterWrites)
+ {
+ if(([theWriteQueue count] == 0) && (theCurrentWrite == nil))
+ {
+ [self disconnect];
+ }
+ }
+ else
+ {
+ [self disconnect];
+ }
+ }
+ }
+}
+
+/**
+ * Call this method in doBytesAvailable instead of CFReadStreamHasBytesAvailable().
+ * This method supports pre-buffering properly as well as the kSocketHasBytesAvailable flag.
+**/
+- (BOOL)hasBytesAvailable
+{
+ if ((theFlags & kSocketHasBytesAvailable) || ([partialReadBuffer length] > 0))
+ {
+ return YES;
+ }
+ else
+ {
+ return CFReadStreamHasBytesAvailable(theReadStream);
+ }
+}
+
+/**
+ * Call this method in doBytesAvailable instead of CFReadStreamRead().
+ * This method support pre-buffering properly.
+**/
+- (CFIndex)readIntoBuffer:(void *)buffer maxLength:(NSUInteger)length
+{
+ if([partialReadBuffer length] > 0)
+ {
+ // Determine the maximum amount of data to read
+ NSUInteger bytesToRead = MIN(length, [partialReadBuffer length]);
+
+ // Copy the bytes from the partial read buffer
+ memcpy(buffer, [partialReadBuffer bytes], (size_t)bytesToRead);
+
+ // Remove the copied bytes from the partial read buffer
+ [partialReadBuffer replaceBytesInRange:NSMakeRange(0, bytesToRead) withBytes:NULL length:0];
+
+ return (CFIndex)bytesToRead;
+ }
+ else
+ {
+ // Unset the "has-bytes-available" flag
+ theFlags &= ~kSocketHasBytesAvailable;
+
+ return CFReadStreamRead(theReadStream, (UInt8 *)buffer, length);
+ }
+}
+
+/**
+ * This method is called when a new read is taken from the read queue or when new data becomes available on the stream.
+**/
+- (void)doBytesAvailable
+{
+ // If data is available on the stream, but there is no read request, then we don't need to process the data yet.
+ // Also, if there is a read request but no read stream setup, we can't process any data yet.
+ if((theCurrentRead == nil) || (theReadStream == NULL))
+ {
+ return;
+ }
+
+ // Note: This method is not called if theCurrentRead is an AsyncSpecialPacket (startTLS packet)
+
+ NSUInteger totalBytesRead = 0;
+
+ BOOL done = NO;
+ BOOL socketError = NO;
+ BOOL maxoutError = NO;
+
+ while(!done && !socketError && !maxoutError && [self hasBytesAvailable])
+ {
+ BOOL didPreBuffer = NO;
+ BOOL didReadFromPreBuffer = NO;
+
+ // There are 3 types of read packets:
+ //
+ // 1) Read all available data.
+ // 2) Read a specific length of data.
+ // 3) Read up to a particular terminator.
+
+ NSUInteger bytesToRead;
+
+ if (theCurrentRead->term != nil)
+ {
+ // Read type #3 - read up to a terminator
+ //
+ // If pre-buffering is enabled we'll read a chunk and search for the terminator.
+ // If the terminator is found, overflow data will be placed in the partialReadBuffer for the next read.
+ //
+ // If pre-buffering is disabled we'll be forced to read only a few bytes.
+ // Just enough to ensure we don't go past our term or over our max limit.
+ //
+ // If we already have data pre-buffered, we can read directly from it.
+
+ if ([partialReadBuffer length] > 0)
+ {
+ didReadFromPreBuffer = YES;
+ bytesToRead = [theCurrentRead readLengthForTermWithPreBuffer:partialReadBuffer found:&done];
+ }
+ else
+ {
+ if (theFlags & kEnablePreBuffering)
+ {
+ didPreBuffer = YES;
+ bytesToRead = [theCurrentRead prebufferReadLengthForTerm];
+ }
+ else
+ {
+ bytesToRead = [theCurrentRead readLengthForTerm];
+ }
+ }
+ }
+ else
+ {
+ // Read type #1 or #2
+
+ bytesToRead = [theCurrentRead readLengthForNonTerm];
+ }
+
+ // Make sure we have enough room in the buffer for our read
+
+ NSUInteger buffSize = [theCurrentRead->buffer length];
+ NSUInteger buffSpace = buffSize - theCurrentRead->startOffset - theCurrentRead->bytesDone;
+
+ if (bytesToRead > buffSpace)
+ {
+ NSUInteger buffInc = bytesToRead - buffSpace;
+
+ [theCurrentRead->buffer increaseLengthBy:buffInc];
+ }
+
+ // Read data into packet buffer
+
+ void *buffer = [theCurrentRead->buffer mutableBytes] + theCurrentRead->startOffset;
+ void *subBuffer = buffer + theCurrentRead->bytesDone;
+
+ CFIndex result = [self readIntoBuffer:subBuffer maxLength:bytesToRead];
+
+ // Check results
+ if (result < 0)
+ {
+ socketError = YES;
+ }
+ else
+ {
+ CFIndex bytesRead = result;
+
+ // Update total amount read for the current read
+ theCurrentRead->bytesDone += bytesRead;
+
+ // Update total amount read in this method invocation
+ totalBytesRead += bytesRead;
+
+
+ // Is packet done?
+ if (theCurrentRead->readLength > 0)
+ {
+ // Read type #2 - read a specific length of data
+
+ done = (theCurrentRead->bytesDone == theCurrentRead->readLength);
+ }
+ else if (theCurrentRead->term != nil)
+ {
+ // Read type #3 - read up to a terminator
+
+ if (didPreBuffer)
+ {
+ // Search for the terminating sequence within the big chunk we just read.
+
+ NSInteger overflow = [theCurrentRead searchForTermAfterPreBuffering:result];
+
+ if (overflow > 0)
+ {
+ // Copy excess data into partialReadBuffer
+ void *overflowBuffer = buffer + theCurrentRead->bytesDone - overflow;
+
+ [partialReadBuffer appendBytes:overflowBuffer length:overflow];
+
+ // Update the bytesDone variable.
+ theCurrentRead->bytesDone -= overflow;
+
+ // Note: The completeCurrentRead method will trim the buffer for us.
+ }
+
+ done = (overflow >= 0);
+ }
+ else if (didReadFromPreBuffer)
+ {
+ // Our 'done' variable was updated via the readLengthForTermWithPreBuffer:found: method
+ }
+ else
+ {
+ // Search for the terminating sequence at the end of the buffer
+
+ NSUInteger termlen = [theCurrentRead->term length];
+
+ if(theCurrentRead->bytesDone >= termlen)
+ {
+ void *bufferEnd = buffer + (theCurrentRead->bytesDone - termlen);
+
+ const void *seq = [theCurrentRead->term bytes];
+
+ done = (memcmp (bufferEnd, seq, termlen) == 0);
+ }
+ }
+
+ if(!done && theCurrentRead->maxLength > 0)
+ {
+ // We're not done and there's a set maxLength.
+ // Have we reached that maxLength yet?
+
+ if(theCurrentRead->bytesDone >= theCurrentRead->maxLength)
+ {
+ maxoutError = YES;
+ }
+ }
+ }
+ else
+ {
+ // Read type #1 - read all available data
+ //
+ // We're done when:
+ // - we reach maxLength (if there is a max)
+ // - all readable is read (see below)
+
+ if (theCurrentRead->maxLength > 0)
+ {
+ done = (theCurrentRead->bytesDone >= theCurrentRead->maxLength);
+ }
+ }
+ }
+ }
+
+ if (theCurrentRead->readLength <= 0 && theCurrentRead->term == nil)
+ {
+ // Read type #1 - read all available data
+
+ if (theCurrentRead->bytesDone > 0)
+ {
+ // Ran out of bytes, so the "read-all-available-data" type packet is done
+ done = YES;
+ }
+ }
+
+ if (done)
+ {
+ [self completeCurrentRead];
+ if (!socketError) [self scheduleDequeueRead];
+ }
+ else if (totalBytesRead > 0)
+ {
+ // We're not done with the readToLength or readToData yet, but we have read in some bytes
+ if ([theDelegate respondsToSelector:@selector(onSocket:didReadPartialDataOfLength:tag:)])
+ {
+ [theDelegate onSocket:self didReadPartialDataOfLength:totalBytesRead tag:theCurrentRead->tag];
+ }
+ }
+
+ if(socketError)
+ {
+ CFStreamError err = CFReadStreamGetError(theReadStream);
+ [self closeWithError:[self errorFromCFStreamError:err]];
+ return;
+ }
+
+ if(maxoutError)
+ {
+ [self closeWithError:[self getReadMaxedOutError]];
+ return;
+ }
+}
+
+// Ends current read and calls delegate.
+- (void)completeCurrentRead
+{
+ NSAssert(theCurrentRead, @"Trying to complete current read when there is no current read.");
+
+ NSData *result;
+
+ if (theCurrentRead->bufferOwner)
+ {
+ // We created the buffer on behalf of the user.
+ // Trim our buffer to be the proper size.
+ [theCurrentRead->buffer setLength:theCurrentRead->bytesDone];
+
+ result = theCurrentRead->buffer;
+ }
+ else
+ {
+ // We did NOT create the buffer.
+ // The buffer is owned by the caller.
+ // Only trim the buffer if we had to increase its size.
+
+ if ([theCurrentRead->buffer length] > theCurrentRead->originalBufferLength)
+ {
+ NSUInteger readSize = theCurrentRead->startOffset + theCurrentRead->bytesDone;
+ NSUInteger origSize = theCurrentRead->originalBufferLength;
+
+ NSUInteger buffSize = MAX(readSize, origSize);
+
+ [theCurrentRead->buffer setLength:buffSize];
+ }
+
+ void *buffer = [theCurrentRead->buffer mutableBytes] + theCurrentRead->startOffset;
+
+ result = [NSData dataWithBytesNoCopy:buffer length:theCurrentRead->bytesDone freeWhenDone:NO];
+ }
+
+ if([theDelegate respondsToSelector:@selector(onSocket:didReadData:withTag:)])
+ {
+ [theDelegate onSocket:self didReadData:result withTag:theCurrentRead->tag];
+ }
+
+ // Caller may have disconnected in the above delegate method
+ if (theCurrentRead != nil)
+ {
+ [self endCurrentRead];
+ }
+}
+
+// Ends current read.
+- (void)endCurrentRead
+{
+ NSAssert(theCurrentRead, @"Trying to end current read when there is no current read.");
+
+ [theReadTimer invalidate];
+ theReadTimer = nil;
+
+ theCurrentRead = nil;
+}
+
+- (void)doReadTimeout:(NSTimer *)timer
+{
+ #pragma unused(timer)
+
+ NSTimeInterval timeoutExtension = 0.0;
+
+ if([theDelegate respondsToSelector:@selector(onSocket:shouldTimeoutReadWithTag:elapsed:bytesDone:)])
+ {
+ timeoutExtension = [theDelegate onSocket:self shouldTimeoutReadWithTag:theCurrentRead->tag
+ elapsed:theCurrentRead->timeout
+ bytesDone:theCurrentRead->bytesDone];
+ }
+
+ if(timeoutExtension > 0.0)
+ {
+ theCurrentRead->timeout += timeoutExtension;
+
+ theReadTimer = [NSTimer timerWithTimeInterval:timeoutExtension
+ target:self
+ selector:@selector(doReadTimeout:)
+ userInfo:nil
+ repeats:NO];
+ [self runLoopAddTimer:theReadTimer];
+ }
+ else
+ {
+ // Do not call endCurrentRead here.
+ // We must allow the delegate access to any partial read in the unreadData method.
+
+ [self closeWithError:[self getReadTimeoutError]];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Writing
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if (data == nil || [data length] == 0) return;
+ if (theFlags & kForbidReadsWrites) return;
+
+ AsyncWritePacket *packet = [[AsyncWritePacket alloc] initWithData:data timeout:timeout tag:tag];
+
+ [theWriteQueue addObject:packet];
+ [self scheduleDequeueWrite];
+
+}
+
+- (void)scheduleDequeueWrite
+{
+ if((theFlags & kDequeueWriteScheduled) == 0)
+ {
+ theFlags |= kDequeueWriteScheduled;
+ [self performSelector:@selector(maybeDequeueWrite) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+/**
+ * Conditionally starts a new write.
+ *
+ * IF there is not another write in process
+ * AND there is a write queued
+ * AND we have a write stream available
+ *
+ * This method also handles auto-disconnect post read/write completion.
+**/
+- (void)maybeDequeueWrite
+{
+ // Unset the flag indicating a call to this method is scheduled
+ theFlags &= ~kDequeueWriteScheduled;
+
+ // If we're not currently processing a write AND we have an available write stream
+ if((theCurrentWrite == nil) && (theWriteStream != NULL))
+ {
+ if([theWriteQueue count] > 0)
+ {
+ // Dequeue the next object in the write queue
+ theCurrentWrite = [theWriteQueue objectAtIndex:0];
+ [theWriteQueue removeObjectAtIndex:0];
+
+ if([theCurrentWrite isKindOfClass:[AsyncSpecialPacket class]])
+ {
+ // Attempt to start TLS
+ theFlags |= kStartingWriteTLS;
+
+ // This method won't do anything unless both kStartingReadTLS and kStartingWriteTLS are set
+ [self maybeStartTLS];
+ }
+ else
+ {
+ // Start time-out timer
+ if(theCurrentWrite->timeout >= 0.0)
+ {
+ theWriteTimer = [NSTimer timerWithTimeInterval:theCurrentWrite->timeout
+ target:self
+ selector:@selector(doWriteTimeout:)
+ userInfo:nil
+ repeats:NO];
+ [self runLoopAddTimer:theWriteTimer];
+ }
+
+ // Immediately write, if possible
+ [self doSendBytes];
+ }
+ }
+ else if(theFlags & kDisconnectAfterWrites)
+ {
+ if(theFlags & kDisconnectAfterReads)
+ {
+ if(([theReadQueue count] == 0) && (theCurrentRead == nil))
+ {
+ [self disconnect];
+ }
+ }
+ else
+ {
+ [self disconnect];
+ }
+ }
+ }
+}
+
+/**
+ * Call this method in doSendBytes instead of CFWriteStreamCanAcceptBytes().
+ * This method supports the kSocketCanAcceptBytes flag.
+**/
+- (BOOL)canAcceptBytes
+{
+ if (theFlags & kSocketCanAcceptBytes)
+ {
+ return YES;
+ }
+ else
+ {
+ return CFWriteStreamCanAcceptBytes(theWriteStream);
+ }
+}
+
+- (void)doSendBytes
+{
+ if ((theCurrentWrite == nil) || (theWriteStream == NULL))
+ {
+ return;
+ }
+
+ // Note: This method is not called if theCurrentWrite is an AsyncSpecialPacket (startTLS packet)
+
+ NSUInteger totalBytesWritten = 0;
+
+ BOOL done = NO;
+ BOOL error = NO;
+
+ while (!done && !error && [self canAcceptBytes])
+ {
+ // Figure out what to write
+ NSUInteger bytesRemaining = [theCurrentWrite->buffer length] - theCurrentWrite->bytesDone;
+ NSUInteger bytesToWrite = (bytesRemaining < WRITE_CHUNKSIZE) ? bytesRemaining : WRITE_CHUNKSIZE;
+
+ UInt8 *writestart = (UInt8 *)([theCurrentWrite->buffer bytes] + theCurrentWrite->bytesDone);
+
+ // Write
+ CFIndex result = CFWriteStreamWrite(theWriteStream, writestart, bytesToWrite);
+
+ // Unset the "can accept bytes" flag
+ theFlags &= ~kSocketCanAcceptBytes;
+
+ // Check results
+ if (result < 0)
+ {
+ error = YES;
+ }
+ else
+ {
+ CFIndex bytesWritten = result;
+
+ // Update total amount read for the current write
+ theCurrentWrite->bytesDone += bytesWritten;
+
+ // Update total amount written in this method invocation
+ totalBytesWritten += bytesWritten;
+
+ // Is packet done?
+ done = ([theCurrentWrite->buffer length] == theCurrentWrite->bytesDone);
+ }
+ }
+
+ if(done)
+ {
+ [self completeCurrentWrite];
+ [self scheduleDequeueWrite];
+ }
+ else if(error)
+ {
+ CFStreamError err = CFWriteStreamGetError(theWriteStream);
+ [self closeWithError:[self errorFromCFStreamError:err]];
+ return;
+ }
+ else if (totalBytesWritten > 0)
+ {
+ // We're not done with the entire write, but we have written some bytes
+ if ([theDelegate respondsToSelector:@selector(onSocket:didWritePartialDataOfLength:tag:)])
+ {
+ [theDelegate onSocket:self didWritePartialDataOfLength:totalBytesWritten tag:theCurrentWrite->tag];
+ }
+ }
+}
+
+// Ends current write and calls delegate.
+- (void)completeCurrentWrite
+{
+ NSAssert(theCurrentWrite, @"Trying to complete current write when there is no current write.");
+
+ if ([theDelegate respondsToSelector:@selector(onSocket:didWriteDataWithTag:)])
+ {
+ [theDelegate onSocket:self didWriteDataWithTag:theCurrentWrite->tag];
+ }
+
+ if (theCurrentWrite != nil) [self endCurrentWrite]; // Caller may have disconnected.
+}
+
+// Ends current write.
+- (void)endCurrentWrite
+{
+ NSAssert(theCurrentWrite, @"Trying to complete current write when there is no current write.");
+
+ [theWriteTimer invalidate];
+ theWriteTimer = nil;
+
+ theCurrentWrite = nil;
+}
+
+- (void)doWriteTimeout:(NSTimer *)timer
+{
+ #pragma unused(timer)
+
+ NSTimeInterval timeoutExtension = 0.0;
+
+ if([theDelegate respondsToSelector:@selector(onSocket:shouldTimeoutWriteWithTag:elapsed:bytesDone:)])
+ {
+ timeoutExtension = [theDelegate onSocket:self shouldTimeoutWriteWithTag:theCurrentWrite->tag
+ elapsed:theCurrentWrite->timeout
+ bytesDone:theCurrentWrite->bytesDone];
+ }
+
+ if(timeoutExtension > 0.0)
+ {
+ theCurrentWrite->timeout += timeoutExtension;
+
+ theWriteTimer = [NSTimer timerWithTimeInterval:timeoutExtension
+ target:self
+ selector:@selector(doWriteTimeout:)
+ userInfo:nil
+ repeats:NO];
+ [self runLoopAddTimer:theWriteTimer];
+ }
+ else
+ {
+ [self closeWithError:[self getWriteTimeoutError]];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Security
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)startTLS:(NSDictionary *)tlsSettings
+{
+#if DEBUG_THREAD_SAFETY
+ [self checkForThreadSafety];
+#endif
+
+ if(tlsSettings == nil)
+ {
+ // Passing nil/NULL to CFReadStreamSetProperty will appear to work the same as passing an empty dictionary,
+ // but causes problems if we later try to fetch the remote host's certificate.
+ //
+ // To be exact, it causes the following to return NULL instead of the normal result:
+ // CFReadStreamCopyProperty(readStream, kCFStreamPropertySSLPeerCertificates)
+ //
+ // So we use an empty dictionary instead, which works perfectly.
+
+ tlsSettings = [NSDictionary dictionary];
+ }
+
+ AsyncSpecialPacket *packet = [[AsyncSpecialPacket alloc] initWithTLSSettings:tlsSettings];
+
+ [theReadQueue addObject:packet];
+ [self scheduleDequeueRead];
+
+ [theWriteQueue addObject:packet];
+ [self scheduleDequeueWrite];
+
+}
+
+- (void)maybeStartTLS
+{
+ // We can't start TLS until:
+ // - All queued reads prior to the user calling StartTLS are complete
+ // - All queued writes prior to the user calling StartTLS are complete
+ //
+ // We'll know these conditions are met when both kStartingReadTLS and kStartingWriteTLS are set
+
+ if((theFlags & kStartingReadTLS) && (theFlags & kStartingWriteTLS))
+ {
+ AsyncSpecialPacket *tlsPacket = (AsyncSpecialPacket *)theCurrentRead;
+
+ BOOL didStartOnReadStream = CFReadStreamSetProperty(theReadStream, kCFStreamPropertySSLSettings,
+ (__bridge CFDictionaryRef)tlsPacket->tlsSettings);
+ BOOL didStartOnWriteStream = CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertySSLSettings,
+ (__bridge CFDictionaryRef)tlsPacket->tlsSettings);
+
+ if(!didStartOnReadStream || !didStartOnWriteStream)
+ {
+ [self closeWithError:[self getSocketError]];
+ }
+ }
+}
+
+- (void)onTLSHandshakeSuccessful
+{
+ if((theFlags & kStartingReadTLS) && (theFlags & kStartingWriteTLS))
+ {
+ theFlags &= ~kStartingReadTLS;
+ theFlags &= ~kStartingWriteTLS;
+
+ if([theDelegate respondsToSelector:@selector(onSocketDidSecure:)])
+ {
+ [theDelegate onSocketDidSecure:self];
+ }
+
+ [self endCurrentRead];
+ [self endCurrentWrite];
+
+ [self scheduleDequeueRead];
+ [self scheduleDequeueWrite];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark CF Callbacks
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)doCFSocketCallback:(CFSocketCallBackType)type
+ forSocket:(CFSocketRef)sock
+ withAddress:(NSData *)address
+ withData:(const void *)pData
+{
+ #pragma unused(address)
+
+ NSParameterAssert ((sock == theSocket4) || (sock == theSocket6));
+
+ switch (type)
+ {
+ case kCFSocketConnectCallBack:
+ // The data argument is either NULL or a pointer to an SInt32 error code, if the connect failed.
+ if(pData)
+ [self doSocketOpen:sock withCFSocketError:kCFSocketError];
+ else
+ [self doSocketOpen:sock withCFSocketError:kCFSocketSuccess];
+ break;
+ case kCFSocketAcceptCallBack:
+ [self doAcceptFromSocket:sock withNewNativeSocket:*((CFSocketNativeHandle *)pData)];
+ break;
+ default:
+ NSLog(@"AsyncSocket %p received unexpected CFSocketCallBackType %i", self, (int)type);
+ break;
+ }
+}
+
+- (void)doCFReadStreamCallback:(CFStreamEventType)type forStream:(CFReadStreamRef)stream
+{
+ #pragma unused(stream)
+
+ NSParameterAssert(theReadStream != NULL);
+
+ CFStreamError err;
+ switch (type)
+ {
+ case kCFStreamEventOpenCompleted:
+ theFlags |= kDidCompleteOpenForRead;
+ [self doStreamOpen];
+ break;
+ case kCFStreamEventHasBytesAvailable:
+ if(theFlags & kStartingReadTLS) {
+ [self onTLSHandshakeSuccessful];
+ }
+ else {
+ theFlags |= kSocketHasBytesAvailable;
+ [self doBytesAvailable];
+ }
+ break;
+ case kCFStreamEventErrorOccurred:
+ case kCFStreamEventEndEncountered:
+ err = CFReadStreamGetError (theReadStream);
+ [self closeWithError: [self errorFromCFStreamError:err]];
+ break;
+ default:
+ NSLog(@"AsyncSocket %p received unexpected CFReadStream callback, CFStreamEventType %i", self, (int)type);
+ }
+}
+
+- (void)doCFWriteStreamCallback:(CFStreamEventType)type forStream:(CFWriteStreamRef)stream
+{
+ #pragma unused(stream)
+
+ NSParameterAssert(theWriteStream != NULL);
+
+ CFStreamError err;
+ switch (type)
+ {
+ case kCFStreamEventOpenCompleted:
+ theFlags |= kDidCompleteOpenForWrite;
+ [self doStreamOpen];
+ break;
+ case kCFStreamEventCanAcceptBytes:
+ if(theFlags & kStartingWriteTLS) {
+ [self onTLSHandshakeSuccessful];
+ }
+ else {
+ theFlags |= kSocketCanAcceptBytes;
+ [self doSendBytes];
+ }
+ break;
+ case kCFStreamEventErrorOccurred:
+ case kCFStreamEventEndEncountered:
+ err = CFWriteStreamGetError (theWriteStream);
+ [self closeWithError: [self errorFromCFStreamError:err]];
+ break;
+ default:
+ NSLog(@"AsyncSocket %p received unexpected CFWriteStream callback, CFStreamEventType %i", self, (int)type);
+ }
+}
+
+/**
+ * This is the callback we setup for CFSocket.
+ * This method does nothing but forward the call to it's Objective-C counterpart
+**/
+static void MyCFSocketCallback (CFSocketRef sref, CFSocketCallBackType type, CFDataRef inAddress, const void *pData, void *pInfo)
+{
+ @autoreleasepool {
+
+ AsyncSocket *theSocket = (__bridge AsyncSocket *)pInfo;
+ NSData *address = [(__bridge NSData *)inAddress copy];
+
+ [theSocket doCFSocketCallback:type forSocket:sref withAddress:address withData:pData];
+
+ }
+}
+
+/**
+ * This is the callback we setup for CFReadStream.
+ * This method does nothing but forward the call to it's Objective-C counterpart
+**/
+static void MyCFReadStreamCallback (CFReadStreamRef stream, CFStreamEventType type, void *pInfo)
+{
+ @autoreleasepool {
+
+ AsyncSocket *theSocket = (__bridge AsyncSocket *)pInfo;
+ [theSocket doCFReadStreamCallback:type forStream:stream];
+
+ }
+}
+
+/**
+ * This is the callback we setup for CFWriteStream.
+ * This method does nothing but forward the call to it's Objective-C counterpart
+**/
+static void MyCFWriteStreamCallback (CFWriteStreamRef stream, CFStreamEventType type, void *pInfo)
+{
+ @autoreleasepool {
+
+ AsyncSocket *theSocket = (__bridge AsyncSocket *)pInfo;
+ [theSocket doCFWriteStreamCallback:type forStream:stream];
+
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Class Methods
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// Return line separators.
++ (NSData *)CRLFData
+{
+ return [NSData dataWithBytes:"\x0D\x0A" length:2];
+}
+
++ (NSData *)CRData
+{
+ return [NSData dataWithBytes:"\x0D" length:1];
+}
+
++ (NSData *)LFData
+{
+ return [NSData dataWithBytes:"\x0A" length:1];
+}
+
++ (NSData *)ZeroData
+{
+ return [NSData dataWithBytes:"" length:1];
+}
+
+@end
diff --git a/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.h b/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.h
new file mode 100755
index 00000000..7bacef41
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.h
@@ -0,0 +1,368 @@
+//
+// 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
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.m b/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.m
new file mode 100755
index 00000000..e8e68e26
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/AsyncUdpSocket.m
@@ -0,0 +1,2318 @@
+//
+// AsyncUdpSocket.m
+//
+// 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/
+//
+
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
+#import "AsyncUdpSocket.h"
+#import
+#import
+#import
+#import
+#import
+#import
+#import
+
+#if TARGET_OS_IPHONE
+// Note: You may need to add the CFNetwork Framework to your project
+#import
+#endif
+
+
+#define SENDQUEUE_CAPACITY 5 // Initial capacity
+#define RECEIVEQUEUE_CAPACITY 5 // Initial capacity
+
+#define DEFAULT_MAX_RECEIVE_BUFFER_SIZE 9216
+
+NSString *const AsyncUdpSocketException = @"AsyncUdpSocketException";
+NSString *const AsyncUdpSocketErrorDomain = @"AsyncUdpSocketErrorDomain";
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+// Mutex lock used by all instances of AsyncUdpSocket, to protect getaddrinfo.
+// Prior to Mac OS X 10.5 this method was not thread-safe.
+static NSString *getaddrinfoLock = @"lock";
+#endif
+
+enum AsyncUdpSocketFlags
+{
+ kDidBind = 1 << 0, // If set, bind has been called.
+ kDidConnect = 1 << 1, // If set, connect has been called.
+ kSock4CanAcceptBytes = 1 << 2, // If set, we know socket4 can accept bytes. If unset, it's unknown.
+ kSock6CanAcceptBytes = 1 << 3, // If set, we know socket6 can accept bytes. If unset, it's unknown.
+ kSock4HasBytesAvailable = 1 << 4, // If set, we know socket4 has bytes available. If unset, it's unknown.
+ kSock6HasBytesAvailable = 1 << 5, // If set, we know socket6 has bytes available. If unset, it's unknown.
+ kForbidSendReceive = 1 << 6, // If set, no new send or receive operations are allowed to be queued.
+ kCloseAfterSends = 1 << 7, // If set, close as soon as no more sends are queued.
+ kCloseAfterReceives = 1 << 8, // If set, close as soon as no more receives are queued.
+ kDidClose = 1 << 9, // If set, the socket has been closed, and should not be used anymore.
+ kDequeueSendScheduled = 1 << 10, // If set, a maybeDequeueSend operation is already scheduled.
+ kDequeueReceiveScheduled = 1 << 11, // If set, a maybeDequeueReceive operation is already scheduled.
+ kFlipFlop = 1 << 12, // Used to alternate between IPv4 and IPv6 sockets.
+};
+
+@interface AsyncUdpSocket (Private)
+
+// Run Loop
+- (void)runLoopAddSource:(CFRunLoopSourceRef)source;
+- (void)runLoopRemoveSource:(CFRunLoopSourceRef)source;
+- (void)runLoopAddTimer:(NSTimer *)timer;
+- (void)runLoopRemoveTimer:(NSTimer *)timer;
+
+// Utilities
+- (NSString *)addressHost4:(struct sockaddr_in *)pSockaddr4;
+- (NSString *)addressHost6:(struct sockaddr_in6 *)pSockaddr6;
+- (NSString *)addressHost:(struct sockaddr *)pSockaddr;
+
+// Disconnect Implementation
+- (void)emptyQueues;
+- (void)closeSocket4;
+- (void)closeSocket6;
+- (void)maybeScheduleClose;
+
+// Errors
+- (NSError *)getErrnoError;
+- (NSError *)getSocketError;
+- (NSError *)getIPv4UnavailableError;
+- (NSError *)getIPv6UnavailableError;
+- (NSError *)getSendTimeoutError;
+- (NSError *)getReceiveTimeoutError;
+
+// Diagnostics
+- (NSString *)connectedHost:(CFSocketRef)socket;
+- (UInt16)connectedPort:(CFSocketRef)socket;
+- (NSString *)localHost:(CFSocketRef)socket;
+- (UInt16)localPort:(CFSocketRef)socket;
+
+// Sending
+- (BOOL)canAcceptBytes:(CFSocketRef)sockRef;
+- (void)scheduleDequeueSend;
+- (void)maybeDequeueSend;
+- (void)doSend:(CFSocketRef)sockRef;
+- (void)completeCurrentSend;
+- (void)failCurrentSend:(NSError *)error;
+- (void)endCurrentSend;
+- (void)doSendTimeout:(NSTimer *)timer;
+
+// Receiving
+- (BOOL)hasBytesAvailable:(CFSocketRef)sockRef;
+- (void)scheduleDequeueReceive;
+- (void)maybeDequeueReceive;
+- (void)doReceive4;
+- (void)doReceive6;
+- (void)doReceive:(CFSocketRef)sockRef;
+- (BOOL)maybeCompleteCurrentReceive;
+- (void)failCurrentReceive:(NSError *)error;
+- (void)endCurrentReceive;
+- (void)doReceiveTimeout:(NSTimer *)timer;
+
+@end
+
+static void MyCFSocketCallback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *);
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The AsyncSendPacket encompasses the instructions for a single send/write.
+**/
+@interface AsyncSendPacket : NSObject
+{
+@public
+ NSData *buffer;
+ NSData *address;
+ NSTimeInterval timeout;
+ long tag;
+}
+- (id)initWithData:(NSData *)d address:(NSData *)a timeout:(NSTimeInterval)t tag:(long)i;
+@end
+
+@implementation AsyncSendPacket
+
+- (id)initWithData:(NSData *)d address:(NSData *)a timeout:(NSTimeInterval)t tag:(long)i
+{
+ if((self = [super init]))
+ {
+ buffer = d;
+ address = a;
+ timeout = t;
+ tag = i;
+ }
+ return self;
+}
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The AsyncReceivePacket encompasses the instructions for a single receive/read.
+**/
+@interface AsyncReceivePacket : NSObject
+{
+@public
+ NSTimeInterval timeout;
+ long tag;
+ NSData *buffer;
+ NSString *host;
+ UInt16 port;
+}
+- (id)initWithTimeout:(NSTimeInterval)t tag:(long)i;
+@end
+
+@implementation AsyncReceivePacket
+
+- (id)initWithTimeout:(NSTimeInterval)t tag:(long)i
+{
+ if((self = [super init]))
+ {
+ timeout = t;
+ tag = i;
+
+ buffer = nil;
+ host = nil;
+ port = 0;
+ }
+ return self;
+}
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+@implementation AsyncUdpSocket
+
+- (id)initWithDelegate:(id)delegate userData:(long)userData enableIPv4:(BOOL)enableIPv4 enableIPv6:(BOOL)enableIPv6
+{
+ if((self = [super init]))
+ {
+ theFlags = 0;
+ theDelegate = delegate;
+ theUserData = userData;
+ maxReceiveBufferSize = DEFAULT_MAX_RECEIVE_BUFFER_SIZE;
+
+ theSendQueue = [[NSMutableArray alloc] initWithCapacity:SENDQUEUE_CAPACITY];
+ theCurrentSend = nil;
+ theSendTimer = nil;
+
+ theReceiveQueue = [[NSMutableArray alloc] initWithCapacity:RECEIVEQUEUE_CAPACITY];
+ theCurrentReceive = nil;
+ theReceiveTimer = nil;
+
+ // Socket context
+ theContext.version = 0;
+ theContext.info = (__bridge void *)self;
+ theContext.retain = nil;
+ theContext.release = nil;
+ theContext.copyDescription = nil;
+
+ // Create the sockets
+ theSocket4 = NULL;
+ theSocket6 = NULL;
+
+ if(enableIPv4)
+ {
+ theSocket4 = CFSocketCreate(kCFAllocatorDefault,
+ PF_INET,
+ SOCK_DGRAM,
+ IPPROTO_UDP,
+ kCFSocketReadCallBack | kCFSocketWriteCallBack,
+ (CFSocketCallBack)&MyCFSocketCallback,
+ &theContext);
+ }
+ if(enableIPv6)
+ {
+ theSocket6 = CFSocketCreate(kCFAllocatorDefault,
+ PF_INET6,
+ SOCK_DGRAM,
+ IPPROTO_UDP,
+ kCFSocketReadCallBack | kCFSocketWriteCallBack,
+ (CFSocketCallBack)&MyCFSocketCallback,
+ &theContext);
+ }
+
+ // Disable continuous callbacks for read and write.
+ // If we don't do this, the socket(s) will just sit there firing read callbacks
+ // at us hundreds of times a second if we don't immediately read the available data.
+ if(theSocket4)
+ {
+ CFSocketSetSocketFlags(theSocket4, kCFSocketCloseOnInvalidate);
+ }
+ if(theSocket6)
+ {
+ CFSocketSetSocketFlags(theSocket6, kCFSocketCloseOnInvalidate);
+ }
+
+ // Prevent sendto calls from sending SIGPIPE signal when socket has been shutdown for writing.
+ // sendto will instead let us handle errors as usual by returning -1.
+ int noSigPipe = 1;
+ if(theSocket4)
+ {
+ setsockopt(CFSocketGetNative(theSocket4), SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe));
+ }
+ if(theSocket6)
+ {
+ setsockopt(CFSocketGetNative(theSocket6), SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe));
+ }
+
+ // Get the CFRunLoop to which the socket should be attached.
+ theRunLoop = CFRunLoopGetCurrent();
+
+ // Set default run loop modes
+ theRunLoopModes = [NSArray arrayWithObject:NSDefaultRunLoopMode];
+
+ // Attach the sockets to the run loop
+
+ if(theSocket4)
+ {
+ theSource4 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, theSocket4, 0);
+ [self runLoopAddSource:theSource4];
+ }
+
+ if(theSocket6)
+ {
+ theSource6 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, theSocket6, 0);
+ [self runLoopAddSource:theSource6];
+ }
+
+ cachedLocalPort = 0;
+ cachedConnectedPort = 0;
+ }
+ return self;
+}
+
+- (id)init
+{
+ return [self initWithDelegate:nil userData:0 enableIPv4:YES enableIPv6:YES];
+}
+
+- (id)initWithDelegate:(id)delegate
+{
+ return [self initWithDelegate:delegate userData:0 enableIPv4:YES enableIPv6:YES];
+}
+
+- (id)initWithDelegate:(id)delegate userData:(long)userData
+{
+ return [self initWithDelegate:delegate userData:userData enableIPv4:YES enableIPv6:YES];
+}
+
+- (id)initIPv4
+{
+ return [self initWithDelegate:nil userData:0 enableIPv4:YES enableIPv6:NO];
+}
+
+- (id)initIPv6
+{
+ return [self initWithDelegate:nil userData:0 enableIPv4:NO enableIPv6:YES];
+}
+
+- (void) dealloc
+{
+ [self close];
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:theDelegate selector:@selector(onUdpSocketDidClose:) object:self];
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Accessors
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (id)delegate
+{
+ return theDelegate;
+}
+
+- (void)setDelegate:(id)delegate
+{
+ theDelegate = delegate;
+}
+
+- (long)userData
+{
+ return theUserData;
+}
+
+- (void)setUserData:(long)userData
+{
+ theUserData = userData;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Run Loop
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)runLoopAddSource:(CFRunLoopSourceRef)source
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopAddSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopRemoveSource:(CFRunLoopSourceRef)source
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopRemoveSource(theRunLoop, source, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopAddTimer:(NSTimer *)timer
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopAddTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+- (void)runLoopRemoveTimer:(NSTimer *)timer
+{
+ for (NSString *runLoopMode in theRunLoopModes)
+ {
+ CFRunLoopRemoveTimer(theRunLoop, (__bridge CFRunLoopTimerRef)timer, (__bridge CFStringRef)runLoopMode);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Configuration
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (UInt32)maxReceiveBufferSize
+{
+ return maxReceiveBufferSize;
+}
+
+- (void)setMaxReceiveBufferSize:(UInt32)max
+{
+ maxReceiveBufferSize = max;
+}
+
+/**
+ * See the header file for a full explanation of this method.
+**/
+- (BOOL)moveToRunLoop:(NSRunLoop *)runLoop
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"moveToRunLoop must be called from within the current RunLoop!");
+
+ if(runLoop == nil)
+ {
+ return NO;
+ }
+ if(theRunLoop == [runLoop getCFRunLoop])
+ {
+ return YES;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueSendScheduled;
+ theFlags &= ~kDequeueReceiveScheduled;
+
+ if(theSource4) [self runLoopRemoveSource:theSource4];
+ if(theSource6) [self runLoopRemoveSource:theSource6];
+
+ if(theSendTimer) [self runLoopRemoveTimer:theSendTimer];
+ if(theReceiveTimer) [self runLoopRemoveTimer:theReceiveTimer];
+
+ theRunLoop = [runLoop getCFRunLoop];
+
+ if(theSendTimer) [self runLoopAddTimer:theSendTimer];
+ if(theReceiveTimer) [self runLoopAddTimer:theReceiveTimer];
+
+ if(theSource4) [self runLoopAddSource:theSource4];
+ if(theSource6) [self runLoopAddSource:theSource6];
+
+ [runLoop performSelector:@selector(maybeDequeueSend) target:self argument:nil order:0 modes:theRunLoopModes];
+ [runLoop performSelector:@selector(maybeDequeueReceive) target:self argument:nil order:0 modes:theRunLoopModes];
+ [runLoop performSelector:@selector(maybeScheduleClose) target:self argument:nil order:0 modes:theRunLoopModes];
+
+ return YES;
+}
+
+/**
+ * See the header file for a full explanation of this method.
+**/
+- (BOOL)setRunLoopModes:(NSArray *)runLoopModes
+{
+ NSAssert((theRunLoop == NULL) || (theRunLoop == CFRunLoopGetCurrent()),
+ @"setRunLoopModes must be called from within the current RunLoop!");
+
+ if([runLoopModes count] == 0)
+ {
+ return NO;
+ }
+ if([theRunLoopModes isEqualToArray:runLoopModes])
+ {
+ return YES;
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ theFlags &= ~kDequeueSendScheduled;
+ theFlags &= ~kDequeueReceiveScheduled;
+
+ if(theSource4) [self runLoopRemoveSource:theSource4];
+ if(theSource6) [self runLoopRemoveSource:theSource6];
+
+ if(theSendTimer) [self runLoopRemoveTimer:theSendTimer];
+ if(theReceiveTimer) [self runLoopRemoveTimer:theReceiveTimer];
+
+ theRunLoopModes = [runLoopModes copy];
+
+ if(theSendTimer) [self runLoopAddTimer:theSendTimer];
+ if(theReceiveTimer) [self runLoopAddTimer:theReceiveTimer];
+
+ if(theSource4) [self runLoopAddSource:theSource4];
+ if(theSource6) [self runLoopAddSource:theSource6];
+
+ [self performSelector:@selector(maybeDequeueSend) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeDequeueReceive) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ [self performSelector:@selector(maybeScheduleClose) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+
+ return YES;
+}
+
+- (NSArray *)runLoopModes
+{
+ return [theRunLoopModes copy];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Utilities:
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Attempts to convert the given host/port into and IPv4 and/or IPv6 data structure.
+ * The data structure is of type sockaddr_in for IPv4 and sockaddr_in6 for IPv6.
+ *
+ * Returns zero on success, or one of the error codes listed in gai_strerror if an error occurs (as per getaddrinfo).
+**/
+- (int)convertForBindHost:(NSString *)host
+ port:(UInt16)port
+ intoAddress4:(NSData **)address4
+ address6:(NSData **)address6
+{
+ if(host == nil || ([host length] == 0))
+ {
+ // Use ANY address
+ struct sockaddr_in nativeAddr;
+ nativeAddr.sin_len = sizeof(struct sockaddr_in);
+ nativeAddr.sin_family = AF_INET;
+ nativeAddr.sin_port = htons(port);
+ nativeAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ memset(&(nativeAddr.sin_zero), 0, sizeof(nativeAddr.sin_zero));
+
+ struct sockaddr_in6 nativeAddr6;
+ nativeAddr6.sin6_len = sizeof(struct sockaddr_in6);
+ nativeAddr6.sin6_family = AF_INET6;
+ nativeAddr6.sin6_port = htons(port);
+ nativeAddr6.sin6_flowinfo = 0;
+ nativeAddr6.sin6_addr = in6addr_any;
+ nativeAddr6.sin6_scope_id = 0;
+
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address4) *address4 = [NSData dataWithBytes:&nativeAddr length:sizeof(nativeAddr)];
+ if(address6) *address6 = [NSData dataWithBytes:&nativeAddr6 length:sizeof(nativeAddr6)];
+
+ return 0;
+ }
+ else if([host isEqualToString:@"localhost"] || [host isEqualToString:@"loopback"])
+ {
+ // Note: getaddrinfo("localhost",...) fails on 10.5.3
+
+ // Use LOOPBACK address
+ struct sockaddr_in nativeAddr;
+ nativeAddr.sin_len = sizeof(struct sockaddr_in);
+ nativeAddr.sin_family = AF_INET;
+ nativeAddr.sin_port = htons(port);
+ nativeAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ memset(&(nativeAddr.sin_zero), 0, sizeof(nativeAddr.sin_zero));
+
+ struct sockaddr_in6 nativeAddr6;
+ nativeAddr6.sin6_len = sizeof(struct sockaddr_in6);
+ nativeAddr6.sin6_family = AF_INET6;
+ nativeAddr6.sin6_port = htons(port);
+ nativeAddr6.sin6_flowinfo = 0;
+ nativeAddr6.sin6_addr = in6addr_loopback;
+ nativeAddr6.sin6_scope_id = 0;
+
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address4) *address4 = [NSData dataWithBytes:&nativeAddr length:sizeof(nativeAddr)];
+ if(address6) *address6 = [NSData dataWithBytes:&nativeAddr6 length:sizeof(nativeAddr6)];
+
+ return 0;
+ }
+ else
+ {
+ NSString *portStr = [NSString stringWithFormat:@"%hu", port];
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ @synchronized (getaddrinfoLock)
+#endif
+ {
+ struct addrinfo hints, *res, *res0;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ hints.ai_flags = AI_PASSIVE;
+
+ int error = getaddrinfo([host UTF8String], [portStr UTF8String], &hints, &res0);
+
+ if(error) return error;
+
+ for(res = res0; res; res = res->ai_next)
+ {
+ if(address4 && !*address4 && (res->ai_family == AF_INET))
+ {
+ // Found IPv4 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address4) *address4 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ else if(address6 && !*address6 && (res->ai_family == AF_INET6))
+ {
+ // Found IPv6 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address6) *address6 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ }
+ freeaddrinfo(res0);
+ }
+
+ return 0;
+ }
+}
+
+/**
+ * Attempts to convert the given host/port into and IPv4 and/or IPv6 data structure.
+ * The data structure is of type sockaddr_in for IPv4 and sockaddr_in6 for IPv6.
+ *
+ * Returns zero on success, or one of the error codes listed in gai_strerror if an error occurs (as per getaddrinfo).
+**/
+- (int)convertForSendHost:(NSString *)host
+ port:(UInt16)port
+ intoAddress4:(NSData **)address4
+ address6:(NSData **)address6
+{
+ if(host == nil || ([host length] == 0))
+ {
+ // We're not binding, so what are we supposed to do with this?
+ return EAI_NONAME;
+ }
+ else if([host isEqualToString:@"localhost"] || [host isEqualToString:@"loopback"])
+ {
+ // Note: getaddrinfo("localhost",...) fails on 10.5.3
+
+ // Use LOOPBACK address
+ struct sockaddr_in nativeAddr;
+ nativeAddr.sin_len = sizeof(struct sockaddr_in);
+ nativeAddr.sin_family = AF_INET;
+ nativeAddr.sin_port = htons(port);
+ nativeAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ memset(&(nativeAddr.sin_zero), 0, sizeof(nativeAddr.sin_zero));
+
+ struct sockaddr_in6 nativeAddr6;
+ nativeAddr6.sin6_len = sizeof(struct sockaddr_in6);
+ nativeAddr6.sin6_family = AF_INET6;
+ nativeAddr6.sin6_port = htons(port);
+ nativeAddr6.sin6_flowinfo = 0;
+ nativeAddr6.sin6_addr = in6addr_loopback;
+ nativeAddr6.sin6_scope_id = 0;
+
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address4) *address4 = [NSData dataWithBytes:&nativeAddr length:sizeof(nativeAddr)];
+ if(address6) *address6 = [NSData dataWithBytes:&nativeAddr6 length:sizeof(nativeAddr6)];
+
+ return 0;
+ }
+ else
+ {
+ NSString *portStr = [NSString stringWithFormat:@"%hu", port];
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ @synchronized (getaddrinfoLock)
+#endif
+ {
+ struct addrinfo hints, *res, *res0;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ // No passive flag on a send or connect
+
+ int error = getaddrinfo([host UTF8String], [portStr UTF8String], &hints, &res0);
+
+ if(error) return error;
+
+ for(res = res0; res; res = res->ai_next)
+ {
+ if(address4 && !*address4 && (res->ai_family == AF_INET))
+ {
+ // Found IPv4 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address4) *address4 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ else if(address6 && !*address6 && (res->ai_family == AF_INET6))
+ {
+ // Found IPv6 address
+ // Wrap the native address structures for CFSocketSetAddress.
+ if(address6) *address6 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
+ }
+ }
+ freeaddrinfo(res0);
+ }
+
+ return 0;
+ }
+}
+
+- (NSString *)addressHost4:(struct sockaddr_in *)pSockaddr4
+{
+ char addrBuf[INET_ADDRSTRLEN];
+
+ if(inet_ntop(AF_INET, &pSockaddr4->sin_addr, addrBuf, sizeof(addrBuf)) == NULL)
+ {
+ [NSException raise:NSInternalInconsistencyException format:@"Cannot convert address to string."];
+ }
+
+ return [NSString stringWithCString:addrBuf encoding:NSASCIIStringEncoding];
+}
+
+- (NSString *)addressHost6:(struct sockaddr_in6 *)pSockaddr6
+{
+ char addrBuf[INET6_ADDRSTRLEN];
+
+ if(inet_ntop(AF_INET6, &pSockaddr6->sin6_addr, addrBuf, sizeof(addrBuf)) == NULL)
+ {
+ [NSException raise:NSInternalInconsistencyException format:@"Cannot convert address to string."];
+ }
+
+ return [NSString stringWithCString:addrBuf encoding:NSASCIIStringEncoding];
+}
+
+- (NSString *)addressHost:(struct sockaddr *)pSockaddr
+{
+ if(pSockaddr->sa_family == AF_INET)
+ {
+ return [self addressHost4:(struct sockaddr_in *)pSockaddr];
+ }
+ else
+ {
+ return [self addressHost6:(struct sockaddr_in6 *)pSockaddr];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Socket Implementation:
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Binds the underlying socket(s) to the given port.
+ * The socket(s) will be able to receive data on any interface.
+ *
+ * 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
+{
+ return [self bindToAddress:nil port:port error:errPtr];
+}
+
+/**
+ * Binds the underlying socket(s) to the given address and port.
+ * The sockets(s) will be able to receive data only on the given interface.
+ *
+ * To receive data on any interface, pass nil or "".
+ * To receive data only on the loopback interface, pass "localhost" or "loopback".
+ *
+ * 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)bindToAddress:(NSString *)host port:(UInt16)port error:(NSError **)errPtr
+{
+ if(theFlags & kDidClose)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"The socket is closed."];
+ }
+ if(theFlags & kDidBind)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Cannot bind a socket more than once."];
+ }
+ if(theFlags & kDidConnect)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Cannot bind after connecting. If needed, bind first, then connect."];
+ }
+
+ // Convert the given host/port into native address structures for CFSocketSetAddress
+ NSData *address4 = nil, *address6 = nil;
+
+ int gai_error = [self convertForBindHost:host port:port intoAddress4:&address4 address6:&address6];
+ if(gai_error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = [NSString stringWithCString:gai_strerror(gai_error) encoding:NSASCIIStringEncoding];
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainNetDB" code:gai_error userInfo:info];
+ }
+ return NO;
+ }
+
+ NSAssert((address4 || address6), @"address4 and address6 are nil");
+
+ // Set the SO_REUSEADDR flags
+
+ int reuseOn = 1;
+ if (theSocket4) setsockopt(CFSocketGetNative(theSocket4), SOL_SOCKET, SO_REUSEADDR, &reuseOn, sizeof(reuseOn));
+ if (theSocket6) setsockopt(CFSocketGetNative(theSocket6), SOL_SOCKET, SO_REUSEADDR, &reuseOn, sizeof(reuseOn));
+
+ // Bind the sockets
+
+ if(address4)
+ {
+ if(theSocket4)
+ {
+ CFSocketError error = CFSocketSetAddress(theSocket4, (__bridge CFDataRef)address4);
+ if(error != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+
+ if(!address6)
+ {
+ // Using IPv4 only
+ [self closeSocket6];
+ }
+ }
+ else if(!address6)
+ {
+ if(errPtr) *errPtr = [self getIPv4UnavailableError];
+ return NO;
+ }
+ }
+
+ if(address6)
+ {
+ // Note: The iPhone doesn't currently support IPv6
+
+ if(theSocket6)
+ {
+ CFSocketError error = CFSocketSetAddress(theSocket6, (__bridge CFDataRef)address6);
+ if(error != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+
+ if(!address4)
+ {
+ // Using IPv6 only
+ [self closeSocket4];
+ }
+ }
+ else if(!address4)
+ {
+ if(errPtr) *errPtr = [self getIPv6UnavailableError];
+ return NO;
+ }
+ }
+
+ theFlags |= kDidBind;
+ return YES;
+}
+
+/**
+ * Connects the underlying UDP socket to the given host and port.
+ * If an IPv4 address is resolved, the IPv4 socket is connected, and the IPv6 socket is invalidated and released.
+ * If an IPv6 address is resolved, the IPv6 socket is connected, and the IPv4 socket is invalidated and released.
+ *
+ * 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
+{
+ if(theFlags & kDidClose)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"The socket is closed."];
+ }
+ if(theFlags & kDidConnect)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Cannot connect a socket more than once."];
+ }
+
+ // Convert the given host/port into native address structures for CFSocketSetAddress
+ NSData *address4 = nil, *address6 = nil;
+
+ int error = [self convertForSendHost:host port:port intoAddress4:&address4 address6:&address6];
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = [NSString stringWithCString:gai_strerror(error) encoding:NSASCIIStringEncoding];
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainNetDB" code:error userInfo:info];
+ }
+ return NO;
+ }
+
+ NSAssert((address4 || address6), @"address4 and address6 are nil");
+
+ // We only want to connect via a single interface.
+ // IPv4 is currently preferred, but this may change in the future.
+
+ CFSocketError sockErr;
+
+ if (address4)
+ {
+ if (theSocket4)
+ {
+ sockErr = CFSocketConnectToAddress(theSocket4, (__bridge CFDataRef)address4, (CFTimeInterval)0.0);
+ if (sockErr != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ theFlags |= kDidConnect;
+
+ // We're connected to an IPv4 address, so no need for the IPv6 socket
+ [self closeSocket6];
+
+ return YES;
+ }
+ else if(!address6)
+ {
+ if(errPtr) *errPtr = [self getIPv4UnavailableError];
+ return NO;
+ }
+ }
+
+ if (address6)
+ {
+ // Note: The iPhone doesn't currently support IPv6
+
+ if (theSocket6)
+ {
+ sockErr = CFSocketConnectToAddress(theSocket6, (__bridge CFDataRef)address6, (CFTimeInterval)0.0);
+ if (sockErr != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ theFlags |= kDidConnect;
+
+ // We're connected to an IPv6 address, so no need for the IPv4 socket
+ [self closeSocket4];
+
+ return YES;
+ }
+ else
+ {
+ if(errPtr) *errPtr = [self getIPv6UnavailableError];
+ return NO;
+ }
+ }
+
+ // It shouldn't be possible to get to this point because either address4 or address6 was non-nil.
+ if(errPtr) *errPtr = nil;
+ return NO;
+}
+
+/**
+ * Connects the underlying UDP socket to the remote address.
+ * If the address is an IPv4 address, the IPv4 socket is connected, and the IPv6 socket is invalidated and released.
+ * If the address is an IPv6 address, the IPv6 socket is connected, and the IPv4 socket is invalidated and released.
+ *
+ * The address is a native address structure, as may be returned from API's such as Bonjour.
+ * An address may be created manually by simply wrapping a sockaddr_in or sockaddr_in6 in an NSData object.
+ *
+ * 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)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr
+{
+ if (theFlags & kDidClose)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"The socket is closed."];
+ }
+ if (theFlags & kDidConnect)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Cannot connect a socket more than once."];
+ }
+
+ CFSocketError sockErr;
+
+ // Is remoteAddr an IPv4 address?
+ if ([remoteAddr length] == sizeof(struct sockaddr_in))
+ {
+ if (theSocket4)
+ {
+ sockErr = CFSocketConnectToAddress(theSocket4, (__bridge CFDataRef)remoteAddr, (CFTimeInterval)0.0);
+ if (sockErr != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ theFlags |= kDidConnect;
+
+ // We're connected to an IPv4 address, so no need for the IPv6 socket
+ [self closeSocket6];
+
+ return YES;
+ }
+ else
+ {
+ if(errPtr) *errPtr = [self getIPv4UnavailableError];
+ return NO;
+ }
+ }
+
+ // Is remoteAddr an IPv6 address?
+ if ([remoteAddr length] == sizeof(struct sockaddr_in6))
+ {
+ if (theSocket6)
+ {
+ sockErr = CFSocketConnectToAddress(theSocket6, (__bridge CFDataRef)remoteAddr, (CFTimeInterval)0.0);
+ if (sockErr != kCFSocketSuccess)
+ {
+ if(errPtr) *errPtr = [self getSocketError];
+ return NO;
+ }
+ theFlags |= kDidConnect;
+
+ // We're connected to an IPv6 address, so no need for the IPv4 socket
+ [self closeSocket4];
+
+ return YES;
+ }
+ else
+ {
+ if(errPtr) *errPtr = [self getIPv6UnavailableError];
+ return NO;
+ }
+ }
+
+ // The remoteAddr was invalid
+ if(errPtr)
+ {
+ NSString *errMsg = @"remoteAddr parameter is not a valid address";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:AsyncUdpSocketErrorDomain
+ code:AsyncUdpSocketBadParameter
+ userInfo:info];
+ }
+ return NO;
+}
+
+/**
+ * Join multicast group
+ *
+ * Group should be a multicast IP address (eg. @"239.255.250.250" for IPv4).
+ * Address is local interface for IPv4, but currently defaults under IPv6.
+**/
+- (BOOL)joinMulticastGroup:(NSString *)group error:(NSError **)errPtr
+{
+ return [self joinMulticastGroup:group withAddress:nil error:errPtr];
+}
+
+- (BOOL)joinMulticastGroup:(NSString *)group withAddress:(NSString *)address error:(NSError **)errPtr
+{
+ if(theFlags & kDidClose)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"The socket is closed."];
+ }
+ if(!(theFlags & kDidBind))
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Must bind a socket before joining a multicast group."];
+ }
+ if(theFlags & kDidConnect)
+ {
+ [NSException raise:AsyncUdpSocketException
+ format:@"Cannot join a multicast group if connected."];
+ }
+
+ // Get local interface address
+ // Convert the given host/port into native address structures for CFSocketSetAddress
+ NSData *address4 = nil, *address6 = nil;
+
+ int error = [self convertForBindHost:address port:0 intoAddress4:&address4 address6:&address6];
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = [NSString stringWithCString:gai_strerror(error) encoding:NSASCIIStringEncoding];
+ NSString *errDsc = [NSString stringWithFormat:@"Invalid parameter 'address': %@", errMsg];
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errDsc forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainNetDB" code:error userInfo:info];
+ }
+ return NO;
+ }
+
+ NSAssert((address4 || address6), @"address4 and address6 are nil");
+
+ // Get multicast address (group)
+ NSData *group4 = nil, *group6 = nil;
+
+ error = [self convertForBindHost:group port:0 intoAddress4:&group4 address6:&group6];
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = [NSString stringWithCString:gai_strerror(error) encoding:NSASCIIStringEncoding];
+ NSString *errDsc = [NSString stringWithFormat:@"Invalid parameter 'group': %@", errMsg];
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errDsc forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainNetDB" code:error userInfo:info];
+ }
+ return NO;
+ }
+
+ NSAssert((group4 || group6), @"group4 and group6 are nil");
+
+ if(theSocket4 && group4 && address4)
+ {
+ const struct sockaddr_in* nativeAddress = [address4 bytes];
+ const struct sockaddr_in* nativeGroup = [group4 bytes];
+
+ struct ip_mreq imreq;
+ imreq.imr_multiaddr = nativeGroup->sin_addr;
+ imreq.imr_interface = nativeAddress->sin_addr;
+
+ // JOIN multicast group on default interface
+ error = setsockopt(CFSocketGetNative(theSocket4), IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ (const void *)&imreq, sizeof(struct ip_mreq));
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = @"Unable to join IPv4 multicast group";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainPOSIX" code:error userInfo:info];
+ }
+ return NO;
+ }
+
+ // Using IPv4 only
+ [self closeSocket6];
+
+ return YES;
+ }
+
+ if(theSocket6 && group6 && address6)
+ {
+ const struct sockaddr_in6* nativeGroup = [group6 bytes];
+
+ struct ipv6_mreq imreq;
+ imreq.ipv6mr_multiaddr = nativeGroup->sin6_addr;
+ imreq.ipv6mr_interface = 0;
+
+ // JOIN multicast group on default interface
+ error = setsockopt(CFSocketGetNative(theSocket6), IPPROTO_IP, IPV6_JOIN_GROUP,
+ (const void *)&imreq, sizeof(struct ipv6_mreq));
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = @"Unable to join IPv6 multicast group";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainPOSIX" code:error userInfo:info];
+ }
+ return NO;
+ }
+
+ // Using IPv6 only
+ [self closeSocket4];
+
+ return YES;
+ }
+
+ // The given address and group didn't match the existing socket(s).
+ // This means there were no compatible combination of all IPv4 or IPv6 socket, group and address.
+ if(errPtr)
+ {
+ NSString *errMsg = @"Invalid group and/or address, not matching existing socket(s)";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:AsyncUdpSocketErrorDomain
+ code:AsyncUdpSocketBadParameter
+ userInfo:info];
+ }
+ return NO;
+}
+
+/**
+ * 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
+{
+ if (theSocket4)
+ {
+ int value = flag ? 1 : 0;
+ int error = setsockopt(CFSocketGetNative(theSocket4), SOL_SOCKET, SO_BROADCAST,
+ (const void *)&value, sizeof(value));
+ if(error)
+ {
+ if(errPtr)
+ {
+ NSString *errMsg = @"Unable to enable broadcast message sending";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ *errPtr = [NSError errorWithDomain:@"kCFStreamErrorDomainPOSIX" code:error userInfo:info];
+ }
+ return NO;
+ }
+ }
+
+ // IPv6 does not implement broadcast, the ability to send a packet to all hosts on the attached link.
+ // The same effect can be achieved by sending a packet to the link-local all hosts multicast group.
+
+ return YES;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Disconnect Implementation:
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)emptyQueues
+{
+ if (theCurrentSend) [self endCurrentSend];
+ if (theCurrentReceive) [self endCurrentReceive];
+
+ [theSendQueue removeAllObjects];
+ [theReceiveQueue removeAllObjects];
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(maybeDequeueSend) object:nil];
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(maybeDequeueReceive) object:nil];
+
+ theFlags &= ~kDequeueSendScheduled;
+ theFlags &= ~kDequeueReceiveScheduled;
+}
+
+- (void)closeSocket4
+{
+ if (theSocket4 != NULL)
+ {
+ CFSocketInvalidate(theSocket4);
+ CFRelease(theSocket4);
+ theSocket4 = NULL;
+ }
+ if (theSource4 != NULL)
+ {
+ [self runLoopRemoveSource:theSource4];
+ CFRelease(theSource4);
+ theSource4 = NULL;
+ }
+}
+
+- (void)closeSocket6
+{
+ if (theSocket6 != NULL)
+ {
+ CFSocketInvalidate(theSocket6);
+ CFRelease(theSocket6);
+ theSocket6 = NULL;
+ }
+ if (theSource6 != NULL)
+ {
+ [self runLoopRemoveSource:theSource6];
+ CFRelease(theSource6);
+ theSource6 = NULL;
+ }
+}
+
+- (void)close
+{
+ [self emptyQueues];
+ [self closeSocket4];
+ [self closeSocket6];
+
+ theRunLoop = NULL;
+
+ // Delay notification to give user freedom to release without returning here and core-dumping.
+ if ([theDelegate respondsToSelector:@selector(onUdpSocketDidClose:)])
+ {
+ [theDelegate performSelector:@selector(onUdpSocketDidClose:)
+ withObject:self
+ afterDelay:0
+ inModes:theRunLoopModes];
+ }
+
+ theFlags |= kDidClose;
+}
+
+- (void)closeAfterSending
+{
+ if(theFlags & kDidClose) return;
+
+ theFlags |= (kForbidSendReceive | kCloseAfterSends);
+ [self maybeScheduleClose];
+}
+
+- (void)closeAfterReceiving
+{
+ if(theFlags & kDidClose) return;
+
+ theFlags |= (kForbidSendReceive | kCloseAfterReceives);
+ [self maybeScheduleClose];
+}
+
+- (void)closeAfterSendingAndReceiving
+{
+ if(theFlags & kDidClose) return;
+
+ theFlags |= (kForbidSendReceive | kCloseAfterSends | kCloseAfterReceives);
+ [self maybeScheduleClose];
+}
+
+- (void)maybeScheduleClose
+{
+ BOOL shouldDisconnect = NO;
+
+ if(theFlags & kCloseAfterSends)
+ {
+ if(([theSendQueue count] == 0) && (theCurrentSend == nil))
+ {
+ if(theFlags & kCloseAfterReceives)
+ {
+ if(([theReceiveQueue count] == 0) && (theCurrentReceive == nil))
+ {
+ shouldDisconnect = YES;
+ }
+ }
+ else
+ {
+ shouldDisconnect = YES;
+ }
+ }
+ }
+ else if(theFlags & kCloseAfterReceives)
+ {
+ if(([theReceiveQueue count] == 0) && (theCurrentReceive == nil))
+ {
+ shouldDisconnect = YES;
+ }
+ }
+
+ if(shouldDisconnect)
+ {
+ [self performSelector:@selector(close) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Errors
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns a standard error object for the current errno value.
+ * Errno is used for low-level BSD socket errors.
+**/
+- (NSError *)getErrnoError
+{
+ NSString *errorMsg = [NSString stringWithUTF8String:strerror(errno)];
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:errorMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:userInfo];
+}
+
+/**
+ * Returns a standard error message for a CFSocket error.
+ * Unfortunately, CFSocket offers no feedback on its errors.
+**/
+- (NSError *)getSocketError
+{
+ NSString *errMsg = @"General CFSocket error";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncUdpSocketErrorDomain code:AsyncUdpSocketCFSocketError userInfo:info];
+}
+
+- (NSError *)getIPv4UnavailableError
+{
+ NSString *errMsg = @"IPv4 is unavailable due to binding/connecting using IPv6 only";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncUdpSocketErrorDomain code:AsyncUdpSocketIPv4Unavailable userInfo:info];
+}
+
+- (NSError *)getIPv6UnavailableError
+{
+ NSString *errMsg = @"IPv6 is unavailable due to binding/connecting using IPv4 only or is not supported on this platform";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncUdpSocketErrorDomain code:AsyncUdpSocketIPv6Unavailable userInfo:info];
+}
+
+- (NSError *)getSendTimeoutError
+{
+ NSString *errMsg = @"Send operation timed out";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncUdpSocketErrorDomain code:AsyncUdpSocketSendTimeoutError userInfo:info];
+}
+- (NSError *)getReceiveTimeoutError
+{
+ NSString *errMsg = @"Receive operation timed out";
+ NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:AsyncUdpSocketErrorDomain code:AsyncUdpSocketReceiveTimeoutError userInfo:info];
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Diagnostics
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (NSString *)localHost
+{
+ if(cachedLocalHost) return cachedLocalHost;
+
+ if(theSocket4)
+ return [self localHost:theSocket4];
+ else
+ return [self localHost:theSocket6];
+}
+
+- (UInt16)localPort
+{
+ if(cachedLocalPort > 0) return cachedLocalPort;
+
+ if(theSocket4)
+ return [self localPort:theSocket4];
+ else
+ return [self localPort:theSocket6];
+}
+
+- (NSString *)connectedHost
+{
+ if(cachedConnectedHost) return cachedConnectedHost;
+
+ if(theSocket4)
+ return [self connectedHost:theSocket4];
+ else
+ return [self connectedHost:theSocket6];
+}
+
+- (UInt16)connectedPort
+{
+ if(cachedConnectedPort > 0) return cachedConnectedPort;
+
+ if(theSocket4)
+ return [self connectedPort:theSocket4];
+ else
+ return [self connectedPort:theSocket6];
+}
+
+- (NSString *)localHost:(CFSocketRef)theSocket
+{
+ if (theSocket == NULL) return nil;
+
+ // Unfortunately we can't use CFSocketCopyAddress.
+ // The CFSocket library caches the address the first time you call CFSocketCopyAddress.
+ // So if this is called prior to binding/connecting/sending, it won't be updated again when necessary,
+ // and will continue to return the old value of the socket address.
+
+ NSString *result = nil;
+
+ if (theSocket == theSocket4)
+ {
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if (getsockname(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return nil;
+ }
+ result = [self addressHost4:&sockaddr4];
+ }
+ else
+ {
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if (getsockname(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return nil;
+ }
+ result = [self addressHost6:&sockaddr6];
+ }
+
+ if (theFlags & kDidBind)
+ {
+ cachedLocalHost = [result copy];
+ }
+
+ return result;
+}
+
+- (UInt16)localPort:(CFSocketRef)theSocket
+{
+ if (theSocket == NULL) return 0;
+
+ // Unfortunately we can't use CFSocketCopyAddress.
+ // The CFSocket library caches the address the first time you call CFSocketCopyAddress.
+ // So if this is called prior to binding/connecting/sending, it won't be updated again when necessary,
+ // and will continue to return the old value of the socket address.
+
+ UInt16 result = 0;
+
+ if (theSocket == theSocket4)
+ {
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if (getsockname(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return 0;
+ }
+ result = ntohs(sockaddr4.sin_port);
+ }
+ else
+ {
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if (getsockname(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return 0;
+ }
+ result = ntohs(sockaddr6.sin6_port);
+ }
+
+ if (theFlags & kDidBind)
+ {
+ cachedLocalPort = result;
+ }
+
+ return result;
+}
+
+- (NSString *)connectedHost:(CFSocketRef)theSocket
+{
+ if (theSocket == NULL) return nil;
+
+ // Unfortunately we can't use CFSocketCopyPeerAddress.
+ // The CFSocket library caches the address the first time you call CFSocketCopyPeerAddress.
+ // So if this is called prior to binding/connecting/sending, it may not be updated again when necessary,
+ // and will continue to return the old value of the socket peer address.
+
+ NSString *result = nil;
+
+ if (theSocket == theSocket4)
+ {
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if (getpeername(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return nil;
+ }
+ result = [self addressHost4:&sockaddr4];
+ }
+ else
+ {
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if (getpeername(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return nil;
+ }
+ result = [self addressHost6:&sockaddr6];
+ }
+
+ if (theFlags & kDidConnect)
+ {
+ cachedConnectedHost = [result copy];
+ }
+
+ return result;
+}
+
+- (UInt16)connectedPort:(CFSocketRef)theSocket
+{
+ if(theSocket == NULL) return 0;
+
+ // Unfortunately we can't use CFSocketCopyPeerAddress.
+ // The CFSocket library caches the address the first time you call CFSocketCopyPeerAddress.
+ // So if this is called prior to binding/connecting/sending, it may not be updated again when necessary,
+ // and will continue to return the old value of the socket peer address.
+
+ UInt16 result = 0;
+
+ if(theSocket == theSocket4)
+ {
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ if(getpeername(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr4, &sockaddr4len) < 0)
+ {
+ return 0;
+ }
+ result = ntohs(sockaddr4.sin_port);
+ }
+ else
+ {
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ if(getpeername(CFSocketGetNative(theSocket), (struct sockaddr *)&sockaddr6, &sockaddr6len) < 0)
+ {
+ return 0;
+ }
+ result = ntohs(sockaddr6.sin6_port);
+ }
+
+ if(theFlags & kDidConnect)
+ {
+ cachedConnectedPort = result;
+ }
+
+ return result;
+}
+
+- (BOOL)isConnected
+{
+ return (((theFlags & kDidConnect) != 0) && ((theFlags & kDidClose) == 0));
+}
+
+- (BOOL)isConnectedToHost:(NSString *)host port:(UInt16)port
+{
+ return [[self connectedHost] isEqualToString:host] && ([self connectedPort] == port);
+}
+
+- (BOOL)isClosed
+{
+ return (theFlags & kDidClose) ? YES : NO;
+}
+
+- (BOOL)isIPv4
+{
+ return (theSocket4 != NULL);
+}
+
+- (BOOL)isIPv6
+{
+ return (theSocket6 != NULL);
+}
+
+- (unsigned int)maximumTransmissionUnit
+{
+ CFSocketNativeHandle theNativeSocket;
+ if(theSocket4)
+ theNativeSocket = CFSocketGetNative(theSocket4);
+ else if(theSocket6)
+ theNativeSocket = CFSocketGetNative(theSocket6);
+ else
+ return 0;
+
+ if(theNativeSocket == 0)
+ {
+ return 0;
+ }
+
+ struct ifreq ifr;
+ bzero(&ifr, sizeof(ifr));
+
+ if(if_indextoname(theNativeSocket, ifr.ifr_name) == NULL)
+ {
+ return 0;
+ }
+
+ if(ioctl(theNativeSocket, SIOCGIFMTU, &ifr) >= 0)
+ {
+ return ifr.ifr_mtu;
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Sending
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (BOOL)sendData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ if([data length] == 0) return NO;
+ if(theFlags & kForbidSendReceive) return NO;
+ if(theFlags & kDidClose) return NO;
+
+ // This method is only for connected sockets
+ if(![self isConnected]) return NO;
+
+ AsyncSendPacket *packet = [[AsyncSendPacket alloc] initWithData:data address:nil timeout:timeout tag:tag];
+
+ [theSendQueue addObject:packet];
+ [self scheduleDequeueSend];
+
+ return YES;
+}
+
+- (BOOL)sendData:(NSData *)data
+ toHost:(NSString *)host
+ port:(UInt16)port
+ withTimeout:(NSTimeInterval)timeout
+ tag:(long)tag
+{
+ if([data length] == 0) return NO;
+ if(theFlags & kForbidSendReceive) return NO;
+ if(theFlags & kDidClose) return NO;
+
+ // This method is only for non-connected sockets
+ if([self isConnected]) return NO;
+
+ NSData *address4 = nil, *address6 = nil;
+ [self convertForSendHost:host port:port intoAddress4:&address4 address6:&address6];
+
+ AsyncSendPacket *packet = nil;
+
+ if(address4 && theSocket4)
+ packet = [[AsyncSendPacket alloc] initWithData:data address:address4 timeout:timeout tag:tag];
+ else if(address6 && theSocket6)
+ packet = [[AsyncSendPacket alloc] initWithData:data address:address6 timeout:timeout tag:tag];
+ else
+ return NO;
+
+ if(address6 && theSocket6){
+ NSLog(@"sendData ipv6");
+ }
+
+
+ [theSendQueue addObject:packet];
+ [self scheduleDequeueSend];
+
+ return YES;
+}
+
+- (BOOL)sendData:(NSData *)data toAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ if([data length] == 0) return NO;
+ if(theFlags & kForbidSendReceive) return NO;
+ if(theFlags & kDidClose) return NO;
+
+ // This method is only for non-connected sockets
+ if([self isConnected]) return NO;
+
+ if([remoteAddr length] == sizeof(struct sockaddr_in) && !theSocket4)
+ return NO;
+
+ if([remoteAddr length] == sizeof(struct sockaddr_in6) && !theSocket6)
+ return NO;
+
+ AsyncSendPacket *packet = [[AsyncSendPacket alloc] initWithData:data address:remoteAddr timeout:timeout tag:tag];
+
+ [theSendQueue addObject:packet];
+ [self scheduleDequeueSend];
+
+ return YES;
+}
+
+- (BOOL)canAcceptBytes:(CFSocketRef)sockRef
+{
+ if(sockRef == theSocket4)
+ {
+ if(theFlags & kSock4CanAcceptBytes) return YES;
+ }
+ else
+ {
+ if(theFlags & kSock6CanAcceptBytes) return YES;
+ }
+
+ CFSocketNativeHandle theNativeSocket = CFSocketGetNative(sockRef);
+
+ if(theNativeSocket == 0)
+ {
+ NSLog(@"Error - Could not get CFSocketNativeHandle from CFSocketRef");
+ return NO;
+ }
+
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(theNativeSocket, &fds);
+
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+
+ return select(FD_SETSIZE, NULL, &fds, NULL, &timeout) > 0;
+}
+
+- (CFSocketRef)socketForPacket:(AsyncSendPacket *)packet
+{
+ if(!theSocket4)
+ return theSocket6;
+ if(!theSocket6)
+ return theSocket4;
+
+ return ([packet->address length] == sizeof(struct sockaddr_in)) ? theSocket4 : theSocket6;
+}
+
+/**
+ * Puts a maybeDequeueSend on the run loop.
+**/
+- (void)scheduleDequeueSend
+{
+ if((theFlags & kDequeueSendScheduled) == 0)
+ {
+ theFlags |= kDequeueSendScheduled;
+ [self performSelector:@selector(maybeDequeueSend) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+/**
+ * This method starts a new send, if needed.
+ * It is called when a user requests a send.
+**/
+- (void)maybeDequeueSend
+{
+ // Unset the flag indicating a call to this method is scheduled
+ theFlags &= ~kDequeueSendScheduled;
+
+ if(theCurrentSend == nil)
+ {
+ if([theSendQueue count] > 0)
+ {
+ // Dequeue next send packet
+ theCurrentSend = [theSendQueue objectAtIndex:0];
+ [theSendQueue removeObjectAtIndex:0];
+
+ // Start time-out timer.
+ if(theCurrentSend->timeout >= 0.0)
+ {
+ theSendTimer = [NSTimer timerWithTimeInterval:theCurrentSend->timeout
+ target:self
+ selector:@selector(doSendTimeout:)
+ userInfo:nil
+ repeats:NO];
+
+ [self runLoopAddTimer:theSendTimer];
+ }
+
+ // Immediately send, if possible.
+ [self doSend:[self socketForPacket:theCurrentSend]];
+ }
+ else if(theFlags & kCloseAfterSends)
+ {
+ if(theFlags & kCloseAfterReceives)
+ {
+ if(([theReceiveQueue count] == 0) && (theCurrentReceive == nil))
+ {
+ [self close];
+ }
+ }
+ else
+ {
+ [self close];
+ }
+ }
+ }
+}
+
+/**
+ * This method is called when a new read is taken from the read queue or when new data becomes available on the stream.
+**/
+- (void)doSend:(CFSocketRef)theSocket
+{
+ if(theCurrentSend != nil)
+ {
+ if(theSocket != [self socketForPacket:theCurrentSend])
+ {
+ // Current send is for the other socket
+ return;
+ }
+
+ if([self canAcceptBytes:theSocket])
+ {
+ ssize_t result;
+ CFSocketNativeHandle theNativeSocket = CFSocketGetNative(theSocket);
+
+ const void *buf = [theCurrentSend->buffer bytes];
+ NSUInteger bufSize = [theCurrentSend->buffer length];
+
+ if([self isConnected])
+ {
+ result = send(theNativeSocket, buf, (size_t)bufSize, 0);
+ }
+ else
+ {
+ const void *dst = [theCurrentSend->address bytes];
+ NSUInteger dstSize = [theCurrentSend->address length];
+
+ result = sendto(theNativeSocket, buf, (size_t)bufSize, 0, dst, (socklen_t)dstSize);
+ }
+
+ if(theSocket == theSocket4)
+ theFlags &= ~kSock4CanAcceptBytes;
+ else
+ theFlags &= ~kSock6CanAcceptBytes;
+
+ if(result < 0)
+ {
+ [self failCurrentSend:[self getErrnoError]];
+ }
+ else
+ {
+ // If it wasn't bound before, it's bound now
+ theFlags |= kDidBind;
+
+ [self completeCurrentSend];
+ }
+
+ [self scheduleDequeueSend];
+ }
+ else
+ {
+ // Request notification when the socket is ready to send more data
+ CFSocketEnableCallBacks(theSocket, kCFSocketReadCallBack | kCFSocketWriteCallBack);
+ }
+ }
+}
+
+- (void)completeCurrentSend
+{
+ NSAssert (theCurrentSend, @"Trying to complete current send when there is no current send.");
+
+ if ([theDelegate respondsToSelector:@selector(onUdpSocket:didSendDataWithTag:)])
+ {
+ [theDelegate onUdpSocket:self didSendDataWithTag:theCurrentSend->tag];
+ }
+
+ if (theCurrentSend != nil) [self endCurrentSend]; // Caller may have disconnected.
+}
+
+- (void)failCurrentSend:(NSError *)error
+{
+ NSAssert (theCurrentSend, @"Trying to fail current send when there is no current send.");
+
+ if ([theDelegate respondsToSelector:@selector(onUdpSocket:didNotSendDataWithTag:dueToError:)])
+ {
+ [theDelegate onUdpSocket:self didNotSendDataWithTag:theCurrentSend->tag dueToError:error];
+ }
+
+ if (theCurrentSend != nil) [self endCurrentSend]; // Caller may have disconnected.
+}
+
+/**
+ * Ends the current send, and all associated variables such as the send timer.
+**/
+- (void)endCurrentSend
+{
+ NSAssert (theCurrentSend, @"Trying to end current send when there is no current send.");
+
+ [theSendTimer invalidate];
+ theSendTimer = nil;
+
+ theCurrentSend = nil;
+}
+
+- (void)doSendTimeout:(NSTimer *)timer
+{
+ if (timer != theSendTimer) return; // Old timer. Ignore it.
+ if (theCurrentSend != nil)
+ {
+ [self failCurrentSend:[self getSendTimeoutError]];
+ [self scheduleDequeueSend];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Receiving
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)receiveWithTimeout:(NSTimeInterval)timeout tag:(long)tag
+{
+ if(theFlags & kForbidSendReceive) return;
+ if(theFlags & kDidClose) return;
+
+ AsyncReceivePacket *packet = [[AsyncReceivePacket alloc] initWithTimeout:timeout tag:tag];
+
+ [theReceiveQueue addObject:packet];
+ [self scheduleDequeueReceive];
+}
+
+- (BOOL)hasBytesAvailable:(CFSocketRef)sockRef
+{
+ if(sockRef == theSocket4)
+ {
+ if(theFlags & kSock4HasBytesAvailable) return YES;
+ }
+ else
+ {
+ if(theFlags & kSock6HasBytesAvailable) return YES;
+ }
+
+ CFSocketNativeHandle theNativeSocket = CFSocketGetNative(sockRef);
+
+ if(theNativeSocket == 0)
+ {
+ NSLog(@"Error - Could not get CFSocketNativeHandle from CFSocketRef");
+ return NO;
+ }
+
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(theNativeSocket, &fds);
+
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+
+ return select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0;
+}
+
+/**
+ * Puts a maybeDequeueReceive on the run loop.
+**/
+- (void)scheduleDequeueReceive
+{
+ if((theFlags & kDequeueReceiveScheduled) == 0)
+ {
+ theFlags |= kDequeueReceiveScheduled;
+ [self performSelector:@selector(maybeDequeueReceive) withObject:nil afterDelay:0 inModes:theRunLoopModes];
+ }
+}
+
+/**
+ * Starts a new receive operation if needed
+**/
+- (void)maybeDequeueReceive
+{
+ // Unset the flag indicating a call to this method is scheduled
+ theFlags &= ~kDequeueReceiveScheduled;
+
+ if (theCurrentReceive == nil)
+ {
+ if ([theReceiveQueue count] > 0)
+ {
+ // Dequeue next receive packet
+ theCurrentReceive = [theReceiveQueue objectAtIndex:0];
+ [theReceiveQueue removeObjectAtIndex:0];
+
+ // Start time-out timer.
+ if (theCurrentReceive->timeout >= 0.0)
+ {
+ theReceiveTimer = [NSTimer timerWithTimeInterval:theCurrentReceive->timeout
+ target:self
+ selector:@selector(doReceiveTimeout:)
+ userInfo:nil
+ repeats:NO];
+
+ [self runLoopAddTimer:theReceiveTimer];
+ }
+
+ // Immediately receive, if possible
+ // We always check both sockets so we don't ever starve one of them.
+ // We also check them in alternating orders to prevent starvation if both of them
+ // have a continuous flow of incoming data.
+ if(theFlags & kFlipFlop)
+ {
+ [self doReceive4];
+ [self doReceive6];
+ }
+ else
+ {
+ [self doReceive6];
+ [self doReceive4];
+ }
+
+ theFlags ^= kFlipFlop;
+ }
+ else if(theFlags & kCloseAfterReceives)
+ {
+ if(theFlags & kCloseAfterSends)
+ {
+ if(([theSendQueue count] == 0) && (theCurrentSend == nil))
+ {
+ [self close];
+ }
+ }
+ else
+ {
+ [self close];
+ }
+ }
+ }
+}
+
+- (void)doReceive4
+{
+ if(theSocket4) [self doReceive:theSocket4];
+}
+
+- (void)doReceive6
+{
+ if(theSocket6) [self doReceive:theSocket6];
+}
+
+- (void)doReceive:(CFSocketRef)theSocket
+{
+ if (theCurrentReceive != nil)
+ {
+ BOOL appIgnoredReceivedData;
+ BOOL userIgnoredReceivedData;
+
+ do
+ {
+ // Set or reset ignored variables.
+ // If the app or user ignores the received data, we'll continue this do-while loop.
+ appIgnoredReceivedData = NO;
+ userIgnoredReceivedData = NO;
+
+ if([self hasBytesAvailable:theSocket])
+ {
+ NSData* bufferData = nil;
+ ssize_t result;
+ CFSocketNativeHandle theNativeSocket = CFSocketGetNative(theSocket);
+
+ // Allocate buffer for recvfrom operation.
+ // If the operation is successful, we'll realloc the buffer to the appropriate size,
+ // and create an NSData wrapper around it without needing to copy any bytes around.
+ void *buf = malloc(maxReceiveBufferSize);
+ size_t bufSize = maxReceiveBufferSize;
+
+ if(theSocket == theSocket4)
+ {
+ struct sockaddr_in sockaddr4;
+ socklen_t sockaddr4len = sizeof(sockaddr4);
+
+ result = recvfrom(theNativeSocket, buf, bufSize, 0, (struct sockaddr *)&sockaddr4, &sockaddr4len);
+
+ if(result >= 0)
+ {
+ NSString *host = [self addressHost4:&sockaddr4];
+ UInt16 port = ntohs(sockaddr4.sin_port);
+
+ if([self isConnected] && ![self isConnectedToHost:host port:port])
+ {
+ // The user connected to an address, and the received data doesn't match the address.
+ // This may happen if the data is received by the kernel prior to the connect call.
+ appIgnoredReceivedData = YES;
+ }
+ else
+ {
+ if(result != bufSize)
+ {
+ buf = realloc(buf, result);
+ }
+ bufferData = [[NSData alloc] initWithBytesNoCopy:buf
+ length:result
+ freeWhenDone:YES];
+ theCurrentReceive->buffer = bufferData;
+ theCurrentReceive->host = host;
+ theCurrentReceive->port = port;
+ }
+ }
+
+ theFlags &= ~kSock4HasBytesAvailable;
+ }
+ else
+ {
+ struct sockaddr_in6 sockaddr6;
+ socklen_t sockaddr6len = sizeof(sockaddr6);
+
+ result = recvfrom(theNativeSocket, buf, bufSize, 0, (struct sockaddr *)&sockaddr6, &sockaddr6len);
+
+ if(result >= 0)
+ {
+ NSString *host = [self addressHost6:&sockaddr6];
+ UInt16 port = ntohs(sockaddr6.sin6_port);
+
+ if([self isConnected] && ![self isConnectedToHost:host port:port])
+ {
+ // The user connected to an address, and the received data doesn't match the address.
+ // This may happen if the data is received by the kernel prior to the connect call.
+ appIgnoredReceivedData = YES;
+ }
+ else
+ {
+ if(result != bufSize)
+ {
+ buf = realloc(buf, result);
+ }
+ bufferData = [[NSData alloc] initWithBytesNoCopy:buf
+ length:result
+ freeWhenDone:YES];
+ theCurrentReceive->buffer = bufferData;
+ theCurrentReceive->host = host;
+ theCurrentReceive->port = port;
+ }
+ }
+
+ theFlags &= ~kSock6HasBytesAvailable;
+ }
+
+ // Check to see if we need to free our alloc'd buffer
+ // If bufferData is non-nil, it has taken ownership of the buffer
+ if(bufferData == nil)
+ {
+ free(buf);
+ }
+
+ if(result < 0)
+ {
+ [self failCurrentReceive:[self getErrnoError]];
+ [self scheduleDequeueReceive];
+ }
+ else if(!appIgnoredReceivedData)
+ {
+ BOOL finished = [self maybeCompleteCurrentReceive];
+
+ if(finished)
+ {
+ [self scheduleDequeueReceive];
+ }
+ else
+ {
+ theCurrentReceive->buffer = nil;
+ theCurrentReceive->host = nil;
+
+ userIgnoredReceivedData = YES;
+ }
+ }
+ }
+ else
+ {
+ // Request notification when the socket is ready to receive more data
+ CFSocketEnableCallBacks(theSocket, kCFSocketReadCallBack | kCFSocketWriteCallBack);
+ }
+
+ } while(appIgnoredReceivedData || userIgnoredReceivedData);
+ }
+}
+
+- (BOOL)maybeCompleteCurrentReceive
+{
+ NSAssert (theCurrentReceive, @"Trying to complete current receive when there is no current receive.");
+
+ BOOL finished = YES;
+
+ if ([theDelegate respondsToSelector:@selector(onUdpSocket:didReceiveData:withTag:fromHost:port:)])
+ {
+ finished = [theDelegate onUdpSocket:self
+ didReceiveData:theCurrentReceive->buffer
+ withTag:theCurrentReceive->tag
+ fromHost:theCurrentReceive->host
+ port:theCurrentReceive->port];
+ }
+
+ if (finished)
+ {
+ if (theCurrentReceive != nil) [self endCurrentReceive]; // Caller may have disconnected.
+ }
+ return finished;
+}
+
+- (void)failCurrentReceive:(NSError *)error
+{
+ NSAssert (theCurrentReceive, @"Trying to fail current receive when there is no current receive.");
+
+ if ([theDelegate respondsToSelector:@selector(onUdpSocket:didNotReceiveDataWithTag:dueToError:)])
+ {
+ [theDelegate onUdpSocket:self didNotReceiveDataWithTag:theCurrentReceive->tag dueToError:error];
+ }
+
+ if (theCurrentReceive != nil) [self endCurrentReceive]; // Caller may have disconnected.
+}
+
+- (void)endCurrentReceive
+{
+ NSAssert (theCurrentReceive, @"Trying to end current receive when there is no current receive.");
+
+ [theReceiveTimer invalidate];
+ theReceiveTimer = nil;
+
+ theCurrentReceive = nil;
+}
+
+- (void)doReceiveTimeout:(NSTimer *)timer
+{
+ if (timer != theReceiveTimer) return; // Old timer. Ignore it.
+ if (theCurrentReceive != nil)
+ {
+ [self failCurrentReceive:[self getReceiveTimeoutError]];
+ [self scheduleDequeueReceive];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark CF Callbacks
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)doCFSocketCallback:(CFSocketCallBackType)type
+ forSocket:(CFSocketRef)sock
+ withAddress:(NSData *)address
+ withData:(const void *)pData
+{
+ NSParameterAssert((sock == theSocket4) || (sock == theSocket6));
+
+ switch (type)
+ {
+ case kCFSocketReadCallBack:
+ if(sock == theSocket4)
+ theFlags |= kSock4HasBytesAvailable;
+ else
+ theFlags |= kSock6HasBytesAvailable;
+ [self doReceive:sock];
+ break;
+ case kCFSocketWriteCallBack:
+ if(sock == theSocket4)
+ theFlags |= kSock4CanAcceptBytes;
+ else
+ theFlags |= kSock6CanAcceptBytes;
+ [self doSend:sock];
+ break;
+ default:
+ NSLog (@"AsyncUdpSocket %p received unexpected CFSocketCallBackType %lu.", self, (unsigned long)type);
+ break;
+ }
+}
+
+/**
+ * This is the callback we setup for CFSocket.
+ * This method does nothing but forward the call to it's Objective-C counterpart
+**/
+static void MyCFSocketCallback(CFSocketRef sref, CFSocketCallBackType type, CFDataRef address, const void *pData, void *pInfo)
+{
+ @autoreleasepool {
+
+ AsyncUdpSocket *theSocket = (__bridge AsyncUdpSocket *)pInfo;
+ [theSocket doCFSocketCallback:type forSocket:sref withAddress:(__bridge NSData *)address withData:pData];
+
+ }
+}
+
+@end
diff --git a/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.h b/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.h
new file mode 100755
index 00000000..ea34ad73
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.h
@@ -0,0 +1,278 @@
+//
+// 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
+
+#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
diff --git a/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.m b/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.m
new file mode 100755
index 00000000..d529a387
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/External/UIView+AutoLayout.m
@@ -0,0 +1,1318 @@
+//
+// UIView+AutoLayout.m
+// 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 "UIView+AutoLayout.h"
+
+
+#pragma mark - UIView+AutoLayout
+
+@implementation UIView (AutoLayout)
+
+
+#pragma mark Factory & Initializer Methods
+
+/**
+ Creates and returns a new view that does not convert the autoresizing mask into constraints.
+ */
++ (instancetype)newAutoLayoutView
+{
+ UIView *view = [self new];
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ return view;
+}
+
+/**
+ Initializes and returns a new view that does not convert the autoresizing mask into constraints.
+ */
+- (instancetype)initForAutoLayout
+{
+ self = [self init];
+ if (self) {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ }
+ return self;
+}
+
+
+#pragma mark Set Constraint Priority
+
+/**
+ A global variable that determines the priority of all constraints created and added by this category.
+ Defaults to Required, will only be a different value while executing a constraints block passed into the
+ +[UIView autoSetPriority:forConstraints:] method (as that method will reset the value back to Required
+ before returning).
+ NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done
+ on the main thread).
+ */
+static UILayoutPriority _al_globalConstraintPriority = UILayoutPriorityRequired;
+
+/**
+ A global variable that is set to YES while the constraints block passed in to the
+ +[UIView autoSetPriority:forConstraints:] method is executing.
+ NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done
+ on the main thread).
+ */
+static BOOL _al_isExecutingConstraintsBlock = NO;
+
+/**
+ 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!
+
+ @param priority The layout priority to be set on all constraints in the constraints block.
+ @param block A block of method calls to the UIView+AutoLayout API that create and add constraints.
+ */
++ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block
+{
+ NSAssert(block, @"The constraints block cannot be nil.");
+ if (block) {
+ _al_globalConstraintPriority = priority;
+ _al_isExecutingConstraintsBlock = YES;
+ block();
+ _al_isExecutingConstraintsBlock = NO;
+ _al_globalConstraintPriority = UILayoutPriorityRequired;
+ }
+}
+
+
+#pragma mark Remove Constraints
+
+/**
+ Removes the given constraint from the view it has been added to.
+
+ @param constraint The constraint to remove.
+ */
++ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint
+{
+ if (constraint.secondItem) {
+ UIView *commonSuperview = [constraint.firstItem al_commonSuperviewWithView:constraint.secondItem];
+ while (commonSuperview) {
+ if ([commonSuperview.constraints containsObject:constraint]) {
+ [commonSuperview removeConstraint:constraint];
+ return;
+ }
+ commonSuperview = commonSuperview.superview;
+ }
+ }
+ else {
+ [constraint.firstItem removeConstraint:constraint];
+ return;
+ }
+ NSAssert(nil, @"Failed to remove constraint: %@", constraint);
+}
+
+/**
+ Removes the given constraints from the views they have been added to.
+
+ @param constraints The constraints to remove.
+ */
++ (void)autoRemoveConstraints:(NSArray *)constraints
+{
+ for (id object in constraints) {
+ if ([object isKindOfClass:[NSLayoutConstraint class]]) {
+ [self autoRemoveConstraint:((NSLayoutConstraint *)object)];
+ } else {
+ NSAssert(nil, @"All constraints to remove must be instances of NSLayoutConstraint.");
+ }
+ }
+}
+
+/**
+ 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.
+ It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead.
+ NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove.
+ */
+- (void)autoRemoveConstraintsAffectingView
+{
+ [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO];
+}
+
+/**
+ 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.
+ It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead.
+ NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at
+ its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these.
+
+ @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped.
+ */
+- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints
+{
+ NSMutableArray *constraintsToRemove = [NSMutableArray new];
+ UIView *startView = self;
+ do {
+ for (NSLayoutConstraint *constraint in startView.constraints) {
+ BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"];
+ if (shouldRemoveImplicitConstraints || !isImplicitConstraint) {
+ if (constraint.firstItem == self || constraint.secondItem == self) {
+ [constraintsToRemove addObject:constraint];
+ }
+ }
+ }
+ startView = startView.superview;
+ } while (startView);
+ [UIView autoRemoveConstraints:constraintsToRemove];
+}
+
+/**
+ 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.
+ It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead.
+ NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove.
+ */
+- (void)autoRemoveConstraintsAffectingViewAndSubviews
+{
+ [self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO];
+}
+
+/**
+ Recursively removes all constraints that affect 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.
+ It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead.
+ NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at
+ its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these.
+
+ @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped.
+ */
+- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints
+{
+ [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints];
+ for (UIView *subview in self.subviews) {
+ [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints];
+ }
+}
+
+
+#pragma mark Center in Superview
+
+/**
+ Centers the view in its superview.
+
+ @return An array of constraints added.
+ */
+- (NSArray *)autoCenterInSuperview
+{
+ NSMutableArray *constraints = [NSMutableArray new];
+ [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]];
+ [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]];
+ return constraints;
+}
+
+/**
+ Aligns the view to the same axis of its superview.
+
+ @param axis The axis of this view and of its superview to align.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ UIView *superview = self.superview;
+ NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
+ NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:superview attribute:attribute multiplier:1.0f constant:0.0f];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#pragma mark Pin Edges to Superview
+
+/**
+ Pins the given edge of the view to the same edge of the superview with an inset.
+
+ @param edge The edge of this view and the superview to pin.
+ @param inset The amount to inset this view's edge from the superview's edge.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset
+{
+ return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:NSLayoutRelationEqual];
+}
+
+/**
+ Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum.
+
+ @param edge The edge of this view and the superview to pin.
+ @param inset The amount to inset this view's edge from the superview's edge.
+ @param relation Whether the inset should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ UIView *superview = self.superview;
+ NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
+ if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) {
+ // The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets
+ inset = -inset;
+ if (relation == NSLayoutRelationLessThanOrEqual) {
+ relation = NSLayoutRelationGreaterThanOrEqual;
+ } else if (relation == NSLayoutRelationGreaterThanOrEqual) {
+ relation = NSLayoutRelationLessThanOrEqual;
+ }
+ }
+ return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation];
+}
+
+/**
+ Pins the edges of the view to the edges of its superview with the given edge insets.
+ The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
+
+ @param insets The insets for this view's edges from the superview's edges.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets
+{
+ NSMutableArray *constraints = [NSMutableArray new];
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
+ return constraints;
+}
+
+/**
+ Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge.
+ The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
+
+ @param insets The insets for this view's edges from the superview's edges. The inset corresponding to the excluded edge
+ will be ignored.
+ @param edge The edge of this view to exclude in pinning to the superview; this method will not apply any constraint to it.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge
+{
+ NSMutableArray *constraints = [NSMutableArray new];
+ if (edge != ALEdgeTop) {
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
+ }
+ if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
+ }
+ if (edge != ALEdgeBottom) {
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
+ }
+ if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
+ [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
+ }
+ return constraints;
+}
+
+
+#pragma mark Pin Edges
+
+/**
+ Pins an edge of the view to a given edge of another view.
+
+ @param edge The edge of this view to pin.
+ @param toEdge The edge of the peer view to pin to.
+ @param peerView The peer view to pin to. Must be in the same view hierarchy as this view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView
+{
+ return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:0.0f];
+}
+
+/**
+ Pins an edge of the view to a given edge of another view with an offset.
+
+ @param edge The edge of this view to pin.
+ @param toEdge The edge of the peer view to pin to.
+ @param peerView The peer view to pin to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the edge of this view and the edge of the peer view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset
+{
+ return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:offset relation:NSLayoutRelationEqual];
+}
+
+/**
+ Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum.
+
+ @param edge The edge of this view to pin.
+ @param toEdge The edge of the peer view to pin to.
+ @param peerView The peer view to pin to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the edge of this view and the edge of the peer view.
+ @param relation Whether the offset should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForEdge:edge];
+ NSLayoutAttribute toAttribute = [UIView al_attributeForEdge:toEdge];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#pragma mark Align Axes
+
+/**
+ Aligns an axis of the view to the same axis of another view.
+
+ @param axis The axis of this view and the peer view to align.
+ @param peerView The peer view to align to. Must be in the same view hierarchy as this view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView
+{
+ return [self autoAlignAxis:axis toSameAxisOfView:peerView withOffset:0.0f];
+}
+
+/**
+ Aligns an axis of the view to the same axis of another view with an offset.
+
+ @param axis The axis of this view and the peer view to align.
+ @param peerView The peer view to align to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the axis of this view and the axis of the peer view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:peerView attribute:attribute multiplier:1.0f constant:offset];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#pragma mark Match Dimensions
+
+/**
+ Matches a dimension of the view to a given dimension of another view.
+
+ @param dimension The dimension of this view to pin.
+ @param toDimension The dimension of the peer view to pin to.
+ @param peerView The peer view to match to. Must be in the same view hierarchy as this view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView
+{
+ return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:0.0f];
+}
+
+/**
+ Matches a dimension of the view to a given dimension of another view with an offset.
+
+ @param dimension The dimension of this view to pin.
+ @param toDimension The dimension of the peer view to pin to.
+ @param peerView The peer view to match to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the dimension of this view and the dimension of the peer view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset
+{
+ return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:offset relation:NSLayoutRelationEqual];
+}
+
+/**
+ Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum.
+
+ @param dimension The dimension of this view to pin.
+ @param toDimension The dimension of the peer view to pin to.
+ @param peerView The peer view to match to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the dimension of this view and the dimension of the peer view.
+ @param relation Whether the offset should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension];
+ NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset];
+ [constraint autoInstall];
+ return constraint;
+}
+
+/**
+ Matches a dimension of the view to a multiple of a given dimension of another view.
+
+ @param dimension The dimension of this view to pin.
+ @param toDimension The dimension of the peer view to pin to.
+ @param peerView The peer view to match to. Must be in the same view hierarchy as this view.
+ @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier
+{
+ return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual];
+}
+
+/**
+ Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum.
+
+ @param dimension The dimension of this view to pin.
+ @param toDimension The dimension of the peer view to pin to.
+ @param peerView The peer view to match to. Must be in the same view hierarchy as this view.
+ @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be.
+ @param relation Whether the multiple should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension];
+ NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#pragma mark Set Dimensions
+
+/**
+ Sets the view to a specific size.
+
+ @param size The size to set this view's dimensions to.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoSetDimensionsToSize:(CGSize)size
+{
+ NSMutableArray *constraints = [NSMutableArray new];
+ [constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]];
+ [constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]];
+ return constraints;
+}
+
+/**
+ Sets the given dimension of the view to a specific size.
+
+ @param dimension The dimension of this view to set.
+ @param size The size to set the given dimension to.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size
+{
+ return [self autoSetDimension:dimension toSize:size relation:NSLayoutRelationEqual];
+}
+
+/**
+ Sets the given dimension of the view to a specific size as a maximum or minimum.
+
+ @param dimension The dimension of this view to set.
+ @param size The size to set the given dimension to.
+ @param relation Whether the size should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:size];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#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:]
+
+ @param axis The axis to set the content compression resistance priority for.
+ */
+- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis
+{
+ NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
+ if (_al_isExecutingConstraintsBlock) {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis];
+ [self setContentCompressionResistancePriority:_al_globalConstraintPriority forAxis:constraintAxis];
+ }
+}
+
+/**
+ 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:]
+
+ @param axis The axis to set the content hugging priority for.
+ */
+- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis
+{
+ NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
+ if (_al_isExecutingConstraintsBlock) {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis];
+ [self setContentHuggingPriority:_al_globalConstraintPriority forAxis:constraintAxis];
+ }
+}
+
+
+#pragma mark Constrain Any Attributes
+
+/**
+ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view.
+ This method can be used to constrain different types of attributes across two views.
+
+ @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain.
+ @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to.
+ @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView
+{
+ return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:0.0f];
+}
+
+/**
+ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset.
+ This method can be used to constrain different types of attributes across two views.
+
+ @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain.
+ @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to.
+ @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the attribute of this view and the attribute of the peer view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset
+{
+ return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:offset relation:NSLayoutRelationEqual];
+}
+
+/**
+ 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.
+ This method can be used to constrain different types of attributes across two views.
+
+ @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain.
+ @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to.
+ @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view.
+ @param offset The offset between the attribute of this view and the attribute of the peer view.
+ @param relation Whether the offset should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute];
+ NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset];
+ [constraint autoInstall];
+ return constraint;
+}
+
+/**
+ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier.
+ This method can be used to constrain different types of attributes across two views.
+
+ @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain.
+ @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to.
+ @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view.
+ @param multiplier The multiplier between the attribute of this view and the attribute of the peer view.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier
+{
+ return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual];
+}
+
+/**
+ 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.
+ This method can be used to constrain different types of attributes across two views.
+
+ @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain.
+ @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to.
+ @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view.
+ @param multiplier The multiplier between the attribute of this view and the attribute of the peer view.
+ @param relation Whether the multiplier should be at least, at most, or exactly equal to the given value.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
+{
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute];
+ NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute];
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f];
+ [constraint autoInstall];
+ return constraint;
+}
+
+
+#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.
+ For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the top edge of
+ the view to the top edge of the given view controller's view with an inset.
+
+ @param viewController The view controller whose topLayoutGuide should be used to pin to.
+ @param inset The amount to inset this view's top edge from the layout guide.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
+{
+ if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
+ return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset];
+ } else {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0f constant:inset];
+ [viewController.view al_addConstraintUsingGlobalPriority:constraint];
+ return constraint;
+ }
+}
+
+/**
+ Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset.
+ For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the bottom edge of
+ the view to the bottom edge of the given view controller's view with an inset.
+
+ @param viewController The view controller whose bottomLayoutGuide should be used to pin to.
+ @param inset The amount to inset this view's bottom edge from the layout guide.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
+{
+ if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
+ return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:-inset];
+ } else {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0f constant:-inset];
+ [viewController.view al_addConstraintUsingGlobalPriority:constraint];
+ return constraint;
+ }
+}
+
+
+#pragma mark Internal Helper Methods
+
+/**
+ Adds the given constraint to this view after setting the constraint's priority to the global constraint priority.
+
+ This method is the only one that calls the SDK addConstraint: method directly; all other instances in this category
+ should use this method to add constraints so that the global priority is correctly set on constraints.
+
+ @param constraint The constraint to set the global priority on and then add to this view.
+ */
+- (void)al_addConstraintUsingGlobalPriority:(NSLayoutConstraint *)constraint
+{
+ constraint.priority = _al_globalConstraintPriority;
+ [self addConstraint:constraint];
+}
+
+/**
+ Returns the corresponding NSLayoutAttribute for the given ALEdge.
+
+ @return The layout attribute for the given edge.
+ */
++ (NSLayoutAttribute)al_attributeForEdge:(ALEdge)edge
+{
+ NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute;
+ switch (edge) {
+ case ALEdgeLeft:
+ attribute = NSLayoutAttributeLeft;
+ break;
+ case ALEdgeRight:
+ attribute = NSLayoutAttributeRight;
+ break;
+ case ALEdgeTop:
+ attribute = NSLayoutAttributeTop;
+ break;
+ case ALEdgeBottom:
+ attribute = NSLayoutAttributeBottom;
+ break;
+ case ALEdgeLeading:
+ attribute = NSLayoutAttributeLeading;
+ break;
+ case ALEdgeTrailing:
+ attribute = NSLayoutAttributeTrailing;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALEdge.");
+ break;
+ }
+ return attribute;
+}
+
+/**
+ Returns the corresponding NSLayoutAttribute for the given ALAxis.
+
+ @return The layout attribute for the given axis.
+ */
++ (NSLayoutAttribute)al_attributeForAxis:(ALAxis)axis
+{
+ NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute;
+ switch (axis) {
+ case ALAxisVertical:
+ attribute = NSLayoutAttributeCenterX;
+ break;
+ case ALAxisHorizontal:
+ attribute = NSLayoutAttributeCenterY;
+ break;
+ case ALAxisBaseline:
+ attribute = NSLayoutAttributeBaseline;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALAxis.");
+ break;
+ }
+ return attribute;
+}
+
+/**
+ Returns the corresponding NSLayoutAttribute for the given ALDimension.
+
+ @return The layout attribute for the given dimension.
+ */
++ (NSLayoutAttribute)al_attributeForDimension:(ALDimension)dimension
+{
+ NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute;
+ switch (dimension) {
+ case ALDimensionWidth:
+ attribute = NSLayoutAttributeWidth;
+ break;
+ case ALDimensionHeight:
+ attribute = NSLayoutAttributeHeight;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALDimension.");
+ break;
+ }
+ return attribute;
+}
+
+/**
+ Returns the corresponding NSLayoutAttribute for the given ALAttribute.
+
+ @return The layout attribute for the given ALAttribute.
+ */
++ (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute
+{
+ NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute;
+ switch (ALAttribute) {
+ case ALEdgeLeft:
+ attribute = NSLayoutAttributeLeft;
+ break;
+ case ALEdgeRight:
+ attribute = NSLayoutAttributeRight;
+ break;
+ case ALEdgeTop:
+ attribute = NSLayoutAttributeTop;
+ break;
+ case ALEdgeBottom:
+ attribute = NSLayoutAttributeBottom;
+ break;
+ case ALEdgeLeading:
+ attribute = NSLayoutAttributeLeading;
+ break;
+ case ALEdgeTrailing:
+ attribute = NSLayoutAttributeTrailing;
+ break;
+ case ALDimensionWidth:
+ attribute = NSLayoutAttributeWidth;
+ break;
+ case ALDimensionHeight:
+ attribute = NSLayoutAttributeHeight;
+ break;
+ case ALAxisVertical:
+ attribute = NSLayoutAttributeCenterX;
+ break;
+ case ALAxisHorizontal:
+ attribute = NSLayoutAttributeCenterY;
+ break;
+ case ALAxisBaseline:
+ attribute = NSLayoutAttributeBaseline;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALAttribute.");
+ break;
+ }
+ return attribute;
+}
+
+/**
+ Returns the corresponding UILayoutConstraintAxis for the given ALAxis.
+
+ @return The constraint axis for the given axis.
+ */
++ (UILayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis
+{
+ UILayoutConstraintAxis constraintAxis;
+ switch (axis) {
+ case ALAxisVertical:
+ constraintAxis = UILayoutConstraintAxisVertical;
+ break;
+ case ALAxisHorizontal:
+ case ALAxisBaseline:
+ constraintAxis = UILayoutConstraintAxisHorizontal;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALAxis.");
+ break;
+ }
+ return constraintAxis;
+}
+
+/**
+ Returns the common superview for this view and the given peer view.
+ Raises an exception if this view and the peer view do not share a common superview.
+
+ @return The common superview for the two views.
+ */
+- (UIView *)al_commonSuperviewWithView:(UIView *)peerView
+{
+ UIView *commonSuperview = nil;
+ UIView *startView = self;
+ do {
+ if ([peerView isDescendantOfView:startView]) {
+ commonSuperview = startView;
+ }
+ startView = startView.superview;
+ } while (startView && !commonSuperview);
+ NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy.");
+ return commonSuperview;
+}
+
+/**
+ Aligns this view to a peer view with an alignment option.
+
+ @param peerView The peer view to align to.
+ @param alignment The alignment option to apply to the two views.
+ @param axis The axis along which the views are distributed, used to validate the alignment option.
+ @return The constraint added.
+ */
+- (NSLayoutConstraint *)al_alignToView:(UIView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis
+{
+ NSLayoutConstraint *constraint = nil;
+ switch (alignment) {
+ case NSLayoutFormatAlignAllCenterX:
+ NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllCenterX.");
+ constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:peerView];
+ break;
+ case NSLayoutFormatAlignAllCenterY:
+ NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllCenterY.");
+ constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:peerView];
+ break;
+ case NSLayoutFormatAlignAllBaseline:
+ NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBaseline.");
+ constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:peerView];
+ break;
+ case NSLayoutFormatAlignAllTop:
+ NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllTop.");
+ constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:peerView];
+ break;
+ case NSLayoutFormatAlignAllLeft:
+ NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeft.");
+ constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:peerView];
+ break;
+ case NSLayoutFormatAlignAllBottom:
+ NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBottom.");
+ constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:peerView];
+ break;
+ case NSLayoutFormatAlignAllRight:
+ NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllRight.");
+ constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:peerView];
+ break;
+ case NSLayoutFormatAlignAllLeading:
+ NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeading.");
+ constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:peerView];
+ break;
+ case NSLayoutFormatAlignAllTrailing:
+ NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllTrailing.");
+ constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:peerView];
+ break;
+ default:
+ NSAssert(nil, @"Unsupported alignment option.");
+ break;
+ }
+ return constraint;
+}
+
+@end
+
+
+#pragma mark - NSArray+AutoLayout
+
+@implementation NSArray (AutoLayout)
+
+
+#pragma mark Constrain Multiple Views
+
+/**
+ Aligns views in this array to one another along a given edge.
+ Note: This array must contain at least 2 views, and all views must share a common superview.
+
+ @param edge The edge to which the subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge
+{
+ NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
+ NSMutableArray *constraints = [NSMutableArray new];
+ UIView *previousView = nil;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ if (previousView) {
+ [constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]];
+ }
+ previousView = view;
+ }
+ }
+ return constraints;
+}
+
+/**
+ Aligns views in this array to one another along a given axis.
+ Note: This array must contain at least 2 views, and all views must share a common superview.
+
+ @param axis The axis to which to subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis
+{
+ NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
+ NSMutableArray *constraints = [NSMutableArray new];
+ UIView *previousView = nil;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ if (previousView) {
+ [constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]];
+ }
+ previousView = view;
+ }
+ }
+ return constraints;
+}
+
+/**
+ Matches a given dimension of all the views in this array.
+ Note: This array must contain at least 2 views, and all views must share a common superview.
+
+ @param dimension The dimension to match for all of the subviews.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension
+{
+ NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
+ NSMutableArray *constraints = [NSMutableArray new];
+ UIView *previousView = nil;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ if (previousView) {
+ [constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]];
+ }
+ previousView = view;
+ }
+ }
+ return constraints;
+}
+
+/**
+ Sets the given dimension of all the views in this array to a given size.
+ Note: This array must contain at least 1 view.
+
+ @param dimension The dimension of each of the subviews to set.
+ @param size The size to set the given dimension of each subview to.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
+{
+ NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view.");
+ NSMutableArray *constraints = [NSMutableArray new];
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ [constraints addObject:[view autoSetDimension:dimension toSize:size]];
+ }
+ }
+ return constraints;
+}
+
+
+#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,
+ including from the first and last views to their superview.
+
+ @param axis The axis along which to distribute the subviews.
+ @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview.
+ @param alignment The way in which the subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment
+{
+ return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:YES alignment: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.
+ The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
+
+ @param axis The axis along which to distribute the subviews.
+ @param spacing The fixed amount of spacing between each subview.
+ @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
+ @param alignment The way in which the subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment
+{
+ NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute.");
+ ALDimension matchedDimension;
+ ALEdge firstEdge, lastEdge;
+ switch (axis) {
+ case ALAxisHorizontal:
+ case ALAxisBaseline:
+ matchedDimension = ALDimensionWidth;
+ firstEdge = ALEdgeLeading;
+ lastEdge = ALEdgeTrailing;
+ break;
+ case ALAxisVertical:
+ matchedDimension = ALDimensionHeight;
+ firstEdge = ALEdgeTop;
+ lastEdge = ALEdgeBottom;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALAxis.");
+ return nil;
+ }
+ CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
+ CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
+
+ NSMutableArray *constraints = [NSMutableArray new];
+ UIView *previousView = nil;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ if (previousView) {
+ // Second, Third, ... View
+ [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]];
+ [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]];
+ [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]];
+ }
+ else {
+ // First view
+ [constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]];
+ }
+ previousView = view;
+ }
+ }
+ if (previousView) {
+ // Last View
+ [constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]];
+ }
+ return constraints;
+}
+
+/**
+ 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,
+ including from the first and last views to their superview.
+
+ @param axis The axis along which to distribute the subviews.
+ @param size The fixed size of each subview in the dimension along the given axis.
+ @param alignment The way in which the subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment
+{
+ return [self autoDistributeViewsAlongAxis:axis withFixedSize:size insetSpacing:YES alignment: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.
+ The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
+
+ @param axis The axis along which to distribute the subviews.
+ @param size The fixed size of each subview in the dimension along the given axis.
+ @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
+ @param alignment The way in which the subviews will be aligned.
+ @return An array of constraints added.
+ */
+- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment
+{
+ NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute.");
+ ALDimension fixedDimension;
+ NSLayoutAttribute attribute;
+ switch (axis) {
+ case ALAxisHorizontal:
+ case ALAxisBaseline:
+ fixedDimension = ALDimensionWidth;
+ attribute = NSLayoutAttributeCenterX;
+ break;
+ case ALAxisVertical:
+ fixedDimension = ALDimensionHeight;
+ attribute = NSLayoutAttributeCenterY;
+ break;
+ default:
+ NSAssert(nil, @"Not a valid ALAxis.");
+ return nil;
+ }
+ BOOL isRightToLeftLanguage = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft;
+ BOOL shouldFlipOrder = isRightToLeftLanguage && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
+
+ NSMutableArray *constraints = [NSMutableArray new];
+ NSArray *views = [self al_copyViewsOnly];
+ NSUInteger numberOfViews = [views count];
+ UIView *commonSuperview = [views al_commonSuperviewOfViews];
+ UIView *previousView = nil;
+ for (NSUInteger i = 0; i < numberOfViews; i++) {
+ UIView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i];
+ view.translatesAutoresizingMaskIntoConstraints = NO;
+ [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]];
+ CGFloat multiplier, constant;
+ if (shouldSpaceInsets) {
+ multiplier = (i * 2.0f + 2.0f) / (numberOfViews + 1.0f);
+ constant = (multiplier - 1.0f) * size / 2.0f;
+ } else {
+ multiplier = (i * 2.0f) / (numberOfViews - 1.0f);
+ constant = (-multiplier + 1.0f) * size / 2.0f;
+ }
+ NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant];
+ [commonSuperview al_addConstraintUsingGlobalPriority:constraint];
+ [constraints addObject:constraint];
+ if (previousView) {
+ [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]];
+ }
+ previousView = view;
+ }
+ return constraints;
+}
+
+#pragma mark Internal Helper Methods
+
+/**
+ Returns the common superview for the views in this array.
+ Raises an exception if the views in this array do not share a common superview.
+
+ @return The common superview for the views in this array.
+ */
+- (UIView *)al_commonSuperviewOfViews
+{
+ UIView *commonSuperview = nil;
+ UIView *previousView = nil;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ UIView *view = (UIView *)object;
+ if (previousView) {
+ commonSuperview = [view al_commonSuperviewWithView:commonSuperview];
+ } else {
+ commonSuperview = view;
+ }
+ previousView = view;
+ }
+ }
+ NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
+ return commonSuperview;
+}
+
+/**
+ Determines whether this array contains a minimum number of views.
+
+ @param minimumNumberOfViews The minimum number of views to check for.
+ @return YES if this array contains at least the minimum number of views, NO otherwise.
+ */
+- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews
+{
+ NSUInteger numberOfViews = 0;
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ numberOfViews++;
+ if (numberOfViews >= minimumNumberOfViews) {
+ return YES;
+ }
+ }
+ }
+ return numberOfViews >= minimumNumberOfViews;
+}
+
+/**
+ Creates a copy of this array containing only the view objects in it.
+
+ @return A new array containing only the views that are in this array.
+ */
+- (NSArray *)al_copyViewsOnly
+{
+ NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
+ for (id object in self) {
+ if ([object isKindOfClass:[UIView class]]) {
+ [viewsOnlyArray addObject:object];
+ }
+ }
+ return viewsOnlyArray;
+}
+
+@end
+
+
+#pragma mark - NSLayoutConstraint+AutoLayout
+
+@implementation NSLayoutConstraint (AutoLayout)
+
+/**
+ Adds the constraint to the appropriate view.
+ */
+- (void)autoInstall
+{
+ NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem.");
+ if (self.firstItem) {
+ if (self.secondItem) {
+ NSAssert([self.firstItem isKindOfClass:[UIView class]] && [self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if both items are views.");
+ UIView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
+ [commonSuperview al_addConstraintUsingGlobalPriority:self];
+ } else {
+ NSAssert([self.firstItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view.");
+ [self.firstItem al_addConstraintUsingGlobalPriority:self];
+ }
+ } else {
+ NSAssert([self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view.");
+ [self.secondItem al_addConstraintUsingGlobalPriority:self];
+ }
+}
+
+/**
+ Removes the constraint from the view it has been added to.
+ */
+- (void)autoRemove
+{
+ [UIView autoRemoveConstraint:self];
+}
+
+@end
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/Call.h b/star_lock/ios/Runner/XSTalkManager/NextPage/Call.h
new file mode 100755
index 00000000..ac30255b
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/Call.h
@@ -0,0 +1,20 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseViewController.h"
+
+@interface Call : BaseViewController
+@property(nonatomic) NSString *CallTag;
+- (void)RefImg:(NSData *)data;
+- (void)setTime:(long)time0;
+- (void)UIClose;
+- (void)AnswerSucc;
+- (void)OpenDoorGo:(NSString *)pwd;
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/Call.m b/star_lock/ios/Runner/XSTalkManager/NextPage/Call.m
new file mode 100755
index 00000000..8be18c48
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/Call.m
@@ -0,0 +1,378 @@
+//
+// 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{
+ UIImage *image = [UIImage imageWithData: data];
+ //self.playerImage = [[UIImageView alloc] initWithImage:image];
+ [self.playerImage setImage:image];
+}
+
+- (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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.h b/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.h
new file mode 100755
index 00000000..e9825293
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.h
@@ -0,0 +1,25 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import
+#import "BaseViewController.h"
+#import "EquList.h"
+
+@interface EquAdd : BaseViewController
+@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
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.m b/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.m
new file mode 100755
index 00000000..1b5ee0c0
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/EquAdd.m
@@ -0,0 +1,346 @@
+//
+// 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;i0 && index
+#import
+#import "BaseViewController.h"
+
+@interface EquConfig : BaseViewController
+@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
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/EquConfig.m b/star_lock/ios/Runner/XSTalkManager/NextPage/EquConfig.m
new file mode 100755
index 00000000..9a162f10
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/EquConfig.m
@@ -0,0 +1,532 @@
+//
+// 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=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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.h b/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.h
new file mode 100755
index 00000000..00ece8d0
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.h
@@ -0,0 +1,16 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseTableViewController.h"
+
+@interface EquList : BaseTableViewController
+
+- (void)setData;
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.m b/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.m
new file mode 100755
index 00000000..fb61e7b2
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/EquList.m
@@ -0,0 +1,143 @@
+//
+// 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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.h b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.h
new file mode 100755
index 00000000..6bdc115d
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.h
@@ -0,0 +1,22 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseViewController.h"
+#import "FaceUpload.h"
+
+@interface FaceSubPage : BaseViewController
+@property(nonatomic) UILabel *hit;
+@property(nonatomic) UIButton *button;
+@property(nonatomic) UIImageView *imgView;
+@property(nonatomic) NSString *no;
+
+@property(nonatomic) FaceUpload *parent;
+
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.m b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.m
new file mode 100755
index 00000000..a62b5ee0
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceSubPage.m
@@ -0,0 +1,226 @@
+//
+// FirstViewController.m
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import "FaceSubPage.h"
+#import
+#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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.h b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.h
new file mode 100755
index 00000000..c10dba8a
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.h
@@ -0,0 +1,19 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseViewController.h"
+#import "BasePageViewController.h"
+
+@interface FaceUpload : BaseViewController
+
+@property(nonatomic) NSString *equid;
+@property(nonatomic) int index0;
+- (void)ReLoad:(int)index;
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.m b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.m
new file mode 100755
index 00000000..807a0f88
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/FaceUpload.m
@@ -0,0 +1,202 @@
+//
+// 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= _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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.h b/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.h
new file mode 100755
index 00000000..b1dc32bc
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.h
@@ -0,0 +1,21 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import
+#import "BaseViewController.h"
+
+@interface OpenPwd : BaseViewController
+@property(nonatomic) UIViewController *parent;
+
+- (void)setUI;
+- (void)focusTextField;
+
+
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.m b/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.m
new file mode 100755
index 00000000..8c017cf6
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/OpenPwd.m
@@ -0,0 +1,168 @@
+//
+// 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 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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.h b/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.h
new file mode 100755
index 00000000..c1e7afd2
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.h
@@ -0,0 +1,20 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseViewController.h"
+
+@interface P2pTest : BaseViewController
+
+- (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
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.m b/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.m
new file mode 100755
index 00000000..aeb158f3
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/P2pTest.m
@@ -0,0 +1,583 @@
+//
+// 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
+
+@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-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" 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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.h b/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.h
new file mode 100755
index 00000000..c1a372e8
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.h
@@ -0,0 +1,18 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseViewController.h"
+//#import "My.h"
+
+@interface Setting : BaseViewController
+
+//@property(nonatomic) My *parent;
+
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.m b/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.m
new file mode 100755
index 00000000..8c6b1b3b
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/Setting.m
@@ -0,0 +1,154 @@
+//
+// 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
+#import "BaseViewController.h"
+
+@interface Web : BaseViewController
+
+
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/Web.m b/star_lock/ios/Runner/XSTalkManager/NextPage/Web.m
new file mode 100755
index 00000000..51f90402
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/Web.m
@@ -0,0 +1,130 @@
+//
+// 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:@"
"];
+
+ 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
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.h b/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.h
new file mode 100755
index 00000000..46fe36d0
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.h
@@ -0,0 +1,16 @@
+//
+// FirstViewController.h
+// Talk
+//
+// Created by xuzs on 22/10/11.
+// Copyright (c) 2022年 xuzs. All rights reserved.
+//
+
+#import
+#import "BaseTableViewController.h"
+
+@interface WifiList : BaseTableViewController
+
+- (void)setData;
+@end
+
diff --git a/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.m b/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.m
new file mode 100755
index 00000000..521c29c6
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/NextPage/WifiList.m
@@ -0,0 +1,130 @@
+//
+// 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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.h b/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.h
new file mode 100755
index 00000000..dc927c4e
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.h
@@ -0,0 +1,26 @@
+//
+// HttpManager.h
+// myhome
+//
+// Created by hkh on 16/11/6.
+//
+#import
+
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.m b/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.m
new file mode 100755
index 00000000..dc549c1a
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/HttpManager.m
@@ -0,0 +1,310 @@
+//
+// 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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Msg.h b/star_lock/ios/Runner/XSTalkManager/Utils/Msg.h
new file mode 100755
index 00000000..8ca1818b
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Msg.h
@@ -0,0 +1,17 @@
+//
+// HttpManager.h
+// myhome
+//
+// Created by hkh on 16/11/6.
+//
+#import
+#import
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Msg.m b/star_lock/ios/Runner/XSTalkManager/Utils/Msg.m
new file mode 100755
index 00000000..596cc83b
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Msg.m
@@ -0,0 +1,152 @@
+//
+// 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
+#import "sysinfo.h"
+#include
+#include
+#include // Per msqr
+#include
+#import
+#import
+#import
+#import
+#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;
+@end
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Pub.m b/star_lock/ios/Runner/XSTalkManager/Utils/Pub.m
new file mode 100755
index 00000000..ead2d138
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Pub.m
@@ -0,0 +1,356 @@
+//
+// HttpManager.m
+// myhome
+//
+// Created by hkh on 16/11/6.
+//
+
+#import "Pub.h"
+#import
+
+@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> 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; iifa_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;
+}
+
+@end
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.h b/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.h
new file mode 100755
index 00000000..67e6e69d
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.h
@@ -0,0 +1,22 @@
+//
+// HttpManager.h
+// myhome
+//
+// Created by hkh on 16/11/6.
+//
+#import
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.m b/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.m
new file mode 100755
index 00000000..670b7db2
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Sformat.m
@@ -0,0 +1,127 @@
+//
+// 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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.h b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.h
new file mode 100755
index 00000000..f622f060
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.h
@@ -0,0 +1,22 @@
+//
+// IframeInfo.h
+// myhome
+//
+// Created by user on 13-2-19.
+//
+//
+
+#import
+
+@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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.m b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.m
new file mode 100755
index 00000000..bfb3037f
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/IframeInfo.m
@@ -0,0 +1,29 @@
+//
+// 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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.h b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.h
new file mode 100755
index 00000000..f2dc98f3
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.h
@@ -0,0 +1,50 @@
+//
+// playAudio.h
+// myhome
+//
+// Created by user on 12-11-20.
+// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
+//
+
+#import
+#import
+
+#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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.m b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.m
new file mode 100755
index 00000000..9661a6cc
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/playAudio.m
@@ -0,0 +1,240 @@
+//
+// 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(@"buffer_callback");
+ playAudio* player = (__bridge playAudio*)inUserData;
+ [player audioQueueOutputWithQueue:q queueBuffer:buf];
+}
+
+- (short)G711Decode_u_law_2_linear:(Byte)b {
+ //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(@"audioQueueOutputWithQueue: _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//kAudioUnitSubType
+#import
+#import
+#import
+#import
+//#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
diff --git a/star_lock/ios/Runner/XSTalkManager/Utils/Talk/recordAudio.m b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/recordAudio.m
new file mode 100755
index 00000000..8b6488b3
--- /dev/null
+++ b/star_lock/ios/Runner/XSTalkManager/Utils/Talk/recordAudio.m
@@ -0,0 +1,763 @@
+//
+// 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