diff --git a/3.4- 圈子聊天.png b/3.4- 圈子聊天.png deleted file mode 100644 index ae9fff29..00000000 Binary files a/3.4- 圈子聊天.png and /dev/null differ diff --git a/Podfile b/Podfile index 3888901c..2a3fe098 100644 --- a/Podfile +++ b/Podfile @@ -59,9 +59,8 @@ target 'QuickLocation' do pod 'WechatOpenSDK-XCFramework' #高德地图 - pod 'AMap3DMap' #3D地图SDK - pod 'AMapSearch' #地图SDK搜索功能 - pod 'AMapLocation' #定位SDK + pod 'AMapNavi-NO-IDFA' #导航SDK(含地图+搜索+导航) + pod 'AMapLocation-NO-IDFA' #定位SDK end @@ -77,8 +76,9 @@ post_install do |installer| # Xcode 15+ (arm64-only simulator) fails. Fix: remove EXCLUDED_ARCHS (so # simulator destinations appear), strip them from general OTHER_LDFLAGS, # and add them back only via OTHER_LDFLAGS[sdk=iphoneos*]. - device_only_fws = %w[MAMapKit AMapFoundationKit AMapLocationKit AMapSearchKit ZXSDK GeYanSdk GTCommonSDK] - device_only_dirs = %w[AMap3DMap AMapFoundation AMapLocation AMapSearch ZXSDK GYSDK GTCommonSDK] + device_only_fws = %w[AMapFoundationKit AMapLocationKit AMapNaviKit ZXSDK GeYanSdk GTCommonSDK] + device_only_dirs = %w[AMapFoundation-NO-IDFA AMapLocation-NO-IDFA AMapNavi-NO-IDFA ZXSDK GYSDK GTCommonSDK] + Dir.glob(File.join(installer.sandbox.root, 'Target Support Files', '**', '*.xcconfig')).each do |path| content = File.read(path) diff --git a/Podfile.lock b/Podfile.lock index 75c9e6ab..05a8ca4a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,13 +1,11 @@ PODS: - Alamofire (5.10.1) - AlipaySDK-iOS (15.8.30) - - AMap3DMap (11.1.200): - - AMapFoundation (>= 1.8.7) - - AMapFoundation (1.8.7) - - AMapLocation (2.11.1): - - AMapFoundation (>= 1.8.7) - - AMapSearch (9.7.5): - - AMapFoundation (>= 1.8.0) + - AMapFoundation-NO-IDFA (1.9.0) + - AMapLocation-NO-IDFA (2.12.0): + - AMapFoundation-NO-IDFA (>= 1.9.0) + - AMapNavi-NO-IDFA (11.2.000): + - AMapFoundation-NO-IDFA (>= 1.9.0) - CocoaLumberjack/Core (3.9.1) - CocoaLumberjack/Swift (3.9.1): - CocoaLumberjack/Core @@ -175,9 +173,8 @@ PODS: DEPENDENCIES: - AlipaySDK-iOS - - AMap3DMap - - AMapLocation - - AMapSearch + - AMapLocation-NO-IDFA + - AMapNavi-NO-IDFA - CocoaLumberjack/Swift - CocoaMQTT - GYSDK @@ -216,10 +213,9 @@ SPEC REPOS: https://gitee.com/mirrors/CocoaPods-Specs.git: - Alamofire - AlipaySDK-iOS - - AMap3DMap - - AMapFoundation - - AMapLocation - - AMapSearch + - AMapFoundation-NO-IDFA + - AMapLocation-NO-IDFA + - AMapNavi-NO-IDFA - CocoaLumberjack - CocoaMQTT - Differentiator @@ -280,10 +276,9 @@ CHECKOUT OPTIONS: SPEC CHECKSUMS: Alamofire: 840d2a1ad82355b536ec6ba5f97e5bfa54600ca3 AlipaySDK-iOS: 913a1df564c64798903e71cf3d63141d9e1904d2 - AMap3DMap: 89c17fdbca2f25e4b46d6a45a8e50346980fc799 - AMapFoundation: e99da1cc722528c60b39340b4763a95305f6c55e - AMapLocation: 6e44f50b044dc54c6b3dcb1dee5ffd6de2689e41 - AMapSearch: 29224a399b56b17da1540e4312fc4d9dc37342bb + AMapFoundation-NO-IDFA: a2e3c895398d7ee757278e1a0a8f9359da4b146e + AMapLocation-NO-IDFA: 7cd8fc837ea41edfbf4d937cd20572e277b77d18 + AMapNavi-NO-IDFA: d55b9b138c6e540f737c689975cae2c9dbd1026a CocoaLumberjack: e4ba3b414dfca8c1916c6303d37f63b3a95134c6 CocoaMQTT: 1e2fa493d57045d66fb1eba2bb5ffb8d77039c60 Differentiator: e8497ceab83c1b10ca233716d547b9af21b9344d @@ -333,6 +328,6 @@ SPEC CHECKSUMS: YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 ZXSDK: 786338c0a18e98e03eda00699c3bfd2700b97117 -PODFILE CHECKSUM: 861114200722c29adba98535aef6b0494d123b44 +PODFILE CHECKSUM: 0b13abaab81fbf89876a935ff6457fbe0baf31d2 COCOAPODS: 1.16.2 diff --git a/QuickLocation.xcodeproj/project.pbxproj b/QuickLocation.xcodeproj/project.pbxproj index 32ae989a..76d5412e 100644 --- a/QuickLocation.xcodeproj/project.pbxproj +++ b/QuickLocation.xcodeproj/project.pbxproj @@ -191,6 +191,8 @@ 30D87CDB2FDFA9EE00E958FD /* MQTTService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D87CDA2FDFA9EE00E958FD /* MQTTService.swift */; }; 30D87CDD2FDFF07500E958FD /* InteractionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D87CDC2FDFF07500E958FD /* InteractionView.swift */; }; 30D87CDF2FDFF1A100E958FD /* QuickMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D87CDE2FDFF1A100E958FD /* QuickMessageView.swift */; }; + 30D87D042FE1336300E958FD /* NavigationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D87D012FE1336300E958FD /* NavigationVC.swift */; }; + 30D87D052FE1336300E958FD /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30D87D022FE1336300E958FD /* NavigationView.swift */; }; 30DC18522FD009CD0041DCD1 /* VipExpenseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DC18512FD009CD0041DCD1 /* VipExpenseModel.swift */; }; 30DC18542FD00C4A0041DCD1 /* VipRechargeVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DC18532FD00C4A0041DCD1 /* VipRechargeVM.swift */; }; 30DC185A2FD11E7A0041DCD1 /* WebOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DC18562FD11E7A0041DCD1 /* WebOperations.swift */; }; @@ -229,7 +231,7 @@ 30EFF3E22FDA9DEE00EB35D4 /* EmergencyContactVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30EFF3E12FDA9DEE00EB35D4 /* EmergencyContactVM.swift */; }; 30EFF3E52FDAA93400EB35D4 /* PrivacyPolicyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30EFF3E42FDAA93300EB35D4 /* PrivacyPolicyVC.swift */; }; 30EFF3E72FDAA93D00EB35D4 /* PrivacyPolicyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30EFF3E62FDAA93D00EB35D4 /* PrivacyPolicyView.swift */; }; - C49B37352A45A02C28FF41BA /* Pods_QuickLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1C77B42994F352054070537 /* Pods_QuickLocation.framework */; }; + D698E9C56D6F2C152772131D /* Pods_QuickLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 475D33CAFA1E1911EB1F8D9F /* Pods_QuickLocation.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -426,6 +428,8 @@ 30D87CDA2FDFA9EE00E958FD /* MQTTService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MQTTService.swift; sourceTree = ""; }; 30D87CDC2FDFF07500E958FD /* InteractionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteractionView.swift; sourceTree = ""; }; 30D87CDE2FDFF1A100E958FD /* QuickMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickMessageView.swift; sourceTree = ""; }; + 30D87D012FE1336300E958FD /* NavigationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationVC.swift; sourceTree = ""; }; + 30D87D022FE1336300E958FD /* NavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationView.swift; sourceTree = ""; }; 30DC18512FD009CD0041DCD1 /* VipExpenseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VipExpenseModel.swift; sourceTree = ""; }; 30DC18532FD00C4A0041DCD1 /* VipRechargeVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VipRechargeVM.swift; sourceTree = ""; }; 30DC18552FD11E7A0041DCD1 /* NavigationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTitleView.swift; sourceTree = ""; }; @@ -467,19 +471,23 @@ 30EFF3E42FDAA93300EB35D4 /* PrivacyPolicyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicyVC.swift; sourceTree = ""; }; 30EFF3E62FDAA93D00EB35D4 /* PrivacyPolicyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicyView.swift; sourceTree = ""; }; 3E4359082FC48D26003470A5 /* QuickLocation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QuickLocation.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 93647DF3683AA5E71EC2FB1A /* Pods-QuickLocation.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickLocation.release.xcconfig"; path = "Target Support Files/Pods-QuickLocation/Pods-QuickLocation.release.xcconfig"; sourceTree = ""; }; - D1C77B42994F352054070537 /* Pods_QuickLocation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_QuickLocation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - E7FB0BC3883A7FF0C8CC59A7 /* Pods-QuickLocation.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickLocation.debug.xcconfig"; path = "Target Support Files/Pods-QuickLocation/Pods-QuickLocation.debug.xcconfig"; sourceTree = ""; }; + 475D33CAFA1E1911EB1F8D9F /* Pods_QuickLocation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_QuickLocation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DA16D49AA46D4F6838340B55 /* Pods-QuickLocation.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickLocation.debug.xcconfig"; path = "Target Support Files/Pods-QuickLocation/Pods-QuickLocation.debug.xcconfig"; sourceTree = ""; }; + E483B9929C03809ADEDE8341 /* Pods-QuickLocation.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickLocation.release.xcconfig"; path = "Target Support Files/Pods-QuickLocation/Pods-QuickLocation.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFileSystemSynchronizedRootGroup section */ 3070777D2FD2A214004C37CC /* lotties */ = { isa = PBXFileSystemSynchronizedRootGroup; + exceptions = ( + ); path = lotties; sourceTree = ""; }; 30D87CEF2FDFF52100E958FD /* TTGTagCollectionView */ = { isa = PBXFileSystemSynchronizedRootGroup; + exceptions = ( + ); path = TTGTagCollectionView; sourceTree = ""; }; @@ -490,21 +498,13 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - C49B37352A45A02C28FF41BA /* Pods_QuickLocation.framework in Frameworks */, + D698E9C56D6F2C152772131D /* Pods_QuickLocation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 03E642910A4324FD76561DF2 /* Frameworks */ = { - isa = PBXGroup; - children = ( - D1C77B42994F352054070537 /* Pods_QuickLocation.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; 305A74C92FCA8C7000227D26 /* RxMoya */ = { isa = PBXGroup; children = ( @@ -892,6 +892,7 @@ 305A76352FCA8C7000227D26 /* Map */ = { isa = PBXGroup; children = ( + 30D87D032FE1336300E958FD /* Navigation */, 305A76322FCA8C7000227D26 /* CircleMember.swift */, 305A76332FCA8C7000227D26 /* MemberAnnotation.swift */, 305A76342FCA8C7000227D26 /* MemberAnnotationView.swift */, @@ -1197,6 +1198,15 @@ path = MQTT; sourceTree = ""; }; + 30D87D032FE1336300E958FD /* Navigation */ = { + isa = PBXGroup; + children = ( + 30D87D012FE1336300E958FD /* NavigationVC.swift */, + 30D87D022FE1336300E958FD /* NavigationView.swift */, + ); + path = Navigation; + sourceTree = ""; + }; 30DC18582FD11E7A0041DCD1 /* Controller */ = { isa = PBXGroup; children = ( @@ -1295,7 +1305,7 @@ 305A76872FCA8C7000227D26 /* QuickLocation */, 3E4359092FC48D26003470A5 /* Products */, B07D45692FCECE07570D9B73 /* Pods */, - 03E642910A4324FD76561DF2 /* Frameworks */, + 47CD8471BE2146A2656CF27E /* Frameworks */, ); sourceTree = ""; }; @@ -1307,11 +1317,19 @@ name = Products; sourceTree = ""; }; + 47CD8471BE2146A2656CF27E /* Frameworks */ = { + isa = PBXGroup; + children = ( + 475D33CAFA1E1911EB1F8D9F /* Pods_QuickLocation.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; B07D45692FCECE07570D9B73 /* Pods */ = { isa = PBXGroup; children = ( - E7FB0BC3883A7FF0C8CC59A7 /* Pods-QuickLocation.debug.xcconfig */, - 93647DF3683AA5E71EC2FB1A /* Pods-QuickLocation.release.xcconfig */, + DA16D49AA46D4F6838340B55 /* Pods-QuickLocation.debug.xcconfig */, + E483B9929C03809ADEDE8341 /* Pods-QuickLocation.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -1323,12 +1341,12 @@ isa = PBXNativeTarget; buildConfigurationList = 3E43591B2FC48D2B003470A5 /* Build configuration list for PBXNativeTarget "QuickLocation" */; buildPhases = ( - 02AAC6F447C63D6CFFF520A5 /* [CP] Check Pods Manifest.lock */, + 172CEDCF3BA87AA2578C673A /* [CP] Check Pods Manifest.lock */, 3E4359042FC48D26003470A5 /* Sources */, 3E4359052FC48D26003470A5 /* Frameworks */, 3E4359062FC48D26003470A5 /* Resources */, - 995DC2C35EFC977973355A8D /* [CP] Embed Pods Frameworks */, - DA8D65EB369916390C2EFAEE /* [CP] Copy Pods Resources */, + 22E76BAEDC74B6177770F922 /* [CP] Embed Pods Frameworks */, + 84E518A2C7E1AE699B07AC0D /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -1397,7 +1415,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 02AAC6F447C63D6CFFF520A5 /* [CP] Check Pods Manifest.lock */ = { + 172CEDCF3BA87AA2578C673A /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1419,7 +1437,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 995DC2C35EFC977973355A8D /* [CP] Embed Pods Frameworks */ = { + 22E76BAEDC74B6177770F922 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1427,20 +1445,16 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - DA8D65EB369916390C2EFAEE /* [CP] Copy Pods Resources */ = { + 84E518A2C7E1AE699B07AC0D /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1448,14 +1462,10 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-resources-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-QuickLocation/Pods-QuickLocation-resources.sh\"\n"; @@ -1505,6 +1515,8 @@ 30EFF3C42FDA431D00EB35D4 /* ChangePhoneVC.swift in Sources */, 305A769E2FCA8C7000227D26 /* TextArrowCell.swift in Sources */, 305A769F2FCA8C7000227D26 /* TextContentArrowCell.swift in Sources */, + 30D87D042FE1336300E958FD /* NavigationVC.swift in Sources */, + 30D87D052FE1336300E958FD /* NavigationView.swift in Sources */, 305A76A02FCA8C7000227D26 /* TextTableViewCell.swift in Sources */, 305A76A12FCA8C7000227D26 /* UIButton+RTL.m in Sources */, 30EFF3A62FD7C5AF00EB35D4 /* GroupSettingVC.swift in Sources */, @@ -1710,7 +1722,7 @@ /* Begin XCBuildConfiguration section */ 3E43591C2FC48D2B003470A5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = E7FB0BC3883A7FF0C8CC59A7 /* Pods-QuickLocation.debug.xcconfig */; + baseConfigurationReference = DA16D49AA46D4F6838340B55 /* Pods-QuickLocation.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; @@ -1759,7 +1771,7 @@ }; 3E43591D2FC48D2B003470A5 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 93647DF3683AA5E71EC2FB1A /* Pods-QuickLocation.release.xcconfig */; + baseConfigurationReference = E483B9929C03809ADEDE8341 /* Pods-QuickLocation.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; diff --git a/QuickLocation.xcworkspace/xcuserdata/yanghong.xcuserdatad/UserInterfaceState.xcuserstate b/QuickLocation.xcworkspace/xcuserdata/yanghong.xcuserdatad/UserInterfaceState.xcuserstate index 5638b491..7fdc3906 100644 Binary files a/QuickLocation.xcworkspace/xcuserdata/yanghong.xcuserdatad/UserInterfaceState.xcuserstate and b/QuickLocation.xcworkspace/xcuserdata/yanghong.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Contents.json b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Contents.json new file mode 100644 index 00000000..4292187e --- /dev/null +++ b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Rectangle 932@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Rectangle 932@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@2x.png b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@2x.png new file mode 100644 index 00000000..fd9c4762 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@2x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@3x.png b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@3x.png new file mode 100644 index 00000000..9fce4462 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_bg.imageset/Rectangle 932@3x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Contents.json b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Contents.json new file mode 100644 index 00000000..64185b25 --- /dev/null +++ b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Group_1515@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Group_1515@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@2x.png b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@2x.png new file mode 100644 index 00000000..d187eff9 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@2x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@3x.png b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@3x.png new file mode 100644 index 00000000..bd40b7f8 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_interest.imageset/Group_1515@3x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Contents.json b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Contents.json new file mode 100644 index 00000000..1c62303c --- /dev/null +++ b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Group 1679@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Group 1679@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@2x.png b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@2x.png new file mode 100644 index 00000000..7f0e2763 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@2x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@3x.png b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@3x.png new file mode 100644 index 00000000..e6be29be Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_lock.imageset/Group 1679@3x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Contents.json b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Contents.json new file mode 100644 index 00000000..b4aba57e --- /dev/null +++ b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Group_1516@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Group_1516@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@2x.png b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@2x.png new file mode 100644 index 00000000..07e63059 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@2x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@3x.png b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@3x.png new file mode 100644 index 00000000..3ded2c96 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/emoji_normal.imageset/Group_1516@3x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/lock.imageset/Contents.json b/QuickLocation/Assets.xcassets/Home/lock.imageset/Contents.json new file mode 100644 index 00000000..6a4d508b --- /dev/null +++ b/QuickLocation/Assets.xcassets/Home/lock.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Vector@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Vector@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@2x.png b/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@2x.png new file mode 100644 index 00000000..3614b420 Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@2x.png differ diff --git a/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@3x.png b/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@3x.png new file mode 100644 index 00000000..df672e6c Binary files /dev/null and b/QuickLocation/Assets.xcassets/Home/lock.imageset/Vector@3x.png differ diff --git a/QuickLocation/Assets.xcassets/Map/Contents.json b/QuickLocation/Assets.xcassets/Map/Contents.json new file mode 100644 index 00000000..6e965652 --- /dev/null +++ b/QuickLocation/Assets.xcassets/Map/Contents.json @@ -0,0 +1,9 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "provides-namespace" : true + } +} diff --git a/QuickLocation/Info.plist b/QuickLocation/Info.plist index d5ba1065..5febac2a 100644 --- a/QuickLocation/Info.plist +++ b/QuickLocation/Info.plist @@ -17,10 +17,13 @@ LSApplicationQueriesSchemes - alipays - weixin - weixinULAPI - weixinURLParamsAPI + alipays + baidumap + qqmap + iosamap + weixin + weixinULAPI + weixinURLParamsAPI NSAppTransportSecurity diff --git a/QuickLocation/Manager/App/RouterManager.swift b/QuickLocation/Manager/App/RouterManager.swift index a919f2c0..ba3d412a 100644 --- a/QuickLocation/Manager/App/RouterManager.swift +++ b/QuickLocation/Manager/App/RouterManager.swift @@ -219,7 +219,7 @@ extension AppRouter: AppRouterProtocol { vc.isNeedLogin = true return vc } - + // MARK: - 更换手机号 AppRouter.register(Route.changePhone) { url, parameters in let vc = ChangePhoneVC() diff --git a/QuickLocation/Model/GroupModel.swift b/QuickLocation/Model/GroupModel.swift index 6e79c05e..1385102a 100644 --- a/QuickLocation/Model/GroupModel.swift +++ b/QuickLocation/Model/GroupModel.swift @@ -185,12 +185,28 @@ struct GroupMemberModel: Mappable, Equatable { } /// 是否在线 var is_online: Bool = false - /// 最后在线文本(MQTT 计算) - var lastUpdateText: String = "" /// 设备电量 var battery: String = "" /// 最后在线时间 - var last_active_time: Int = 0 + var last_active_time: Int64 = 0 + /// 最后在线文本(MQTT 计算) + var lastUpdateText: String { + let nowMs = Date().timeIntervalSince1970 + let msgTimeMs = Double(last_active_time) + let diffSec = nowMs - msgTimeMs + let isOnline = diffSec < 60 + let lastUpdateText: String + if isOnline { + lastUpdateText = "" + } else if diffSec < 3600 { + lastUpdateText = "\(Int(diffSec / 60))分钟前" + } else if diffSec < 86400 { + lastUpdateText = "\(Int(diffSec / 3600))小时前" + } else { + lastUpdateText = "\(Int(diffSec / 86400))天前" + } + return lastUpdateText + } /// 最后位置 var last_position: String = "" var lastLocation: String { @@ -211,7 +227,7 @@ struct GroupMemberModel: Mappable, Equatable { battery <- map["battery"] last_position <- map["last_position"] is_online <- map["is_online"] - + last_active_time <- map["last_active_time"] } } diff --git a/QuickLocation/Section/Group/GroupChat/GroupChatVC.swift b/QuickLocation/Section/Group/GroupChat/GroupChatVC.swift index 01f05c76..a2b8e93b 100644 --- a/QuickLocation/Section/Group/GroupChat/GroupChatVC.swift +++ b/QuickLocation/Section/Group/GroupChat/GroupChatVC.swift @@ -137,7 +137,7 @@ final class GroupChatVC: BaseViewController { }) .disposed(by: disposeBag) - let emojiItems = UITableViewCell.emojiFileNames.map { $0 } + let emojiItems = UIView.emojiFileNames.map { $0 } Observable.just([SectionModel(model: "", items: emojiItems)]) .bind(to: rootView.emojiCollectionView.rx.items(dataSource: emojiDataSource)) .disposed(by: disposeBag) @@ -160,6 +160,7 @@ final class GroupChatVC: BaseViewController { let cell: EmojiPanelCell = collectionView.dequeueReusableCell(for: indexPath) if let path = Bundle.main.path(forResource: name, ofType: "json") { cell.configure(path: path) + cell.playAnimation() } return cell } @@ -240,7 +241,7 @@ final class GroupChatVC: BaseViewController { // 表情面板点击 rootView.emojiCollectionView.rx.modelSelected(String.self) .subscribe(onNext: { [weak self] name in - guard let self = self, let idx = UITableViewCell.emojiFileNames.firstIndex(of: name) else { return } + guard let self = self, let idx = UIView.emojiFileNames.firstIndex(of: name) else { return } self.viewModel.input.sendMessage.onNext("js_emoji:\(idx)") }) .disposed(by: disposeBag) @@ -306,7 +307,6 @@ final class GroupChatVC: BaseViewController { if show { self.rootView.textField.resignFirstResponder() - EmojiPanelCell.preloadAnimations() } } diff --git a/QuickLocation/Section/Group/GroupChat/GroupChatView.swift b/QuickLocation/Section/Group/GroupChat/GroupChatView.swift index 9c597bfa..cb4adcb9 100644 --- a/QuickLocation/Section/Group/GroupChat/GroupChatView.swift +++ b/QuickLocation/Section/Group/GroupChat/GroupChatView.swift @@ -480,7 +480,7 @@ class GroupChatView: UIView { lazy var emojiPageControl: UIPageControl = { let pc = UIPageControl() - pc.numberOfPages = (UITableViewCell.emojiFileNames.count + Self.emojiPerPage - 1) / Self.emojiPerPage + pc.numberOfPages = (UIView.emojiFileNames.count + Self.emojiPerPage - 1) / Self.emojiPerPage pc.currentPageIndicatorTintColor = UIColor(hexStr: "#16B3FF") pc.pageIndicatorTintColor = UIColor(hexStr: "#D0D0D0") return pc @@ -779,17 +779,6 @@ final class NotificationMsgCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } } -// MARK: - 表情文件列表(共用) -extension UITableViewCell { - static var emojiFileNames: [String] = { - let paths = Bundle.main.paths(forResourcesOfType: "json", inDirectory: nil) - return paths - .compactMap { $0.components(separatedBy: "/").last } - .filter { $0.hasPrefix("normal_") && $0.hasSuffix(".json") } - .map { $0.replacingOccurrences(of: ".json", with: "") } - .sorted() - }() -} // MARK: - 发送的表情消息 final class EmojiSendMsgCell: UITableViewCell { @@ -973,56 +962,7 @@ extension GroupChatView: UICollectionViewDelegate { } } -// MARK: - EmojiPanelCell -final class EmojiPanelCell: UICollectionViewCell { - private static var animationCache: [String: LottieAnimation] = [:] - - static func preloadAnimations() { - DispatchQueue.global(qos: .userInitiated).async { - for name in UITableViewCell.emojiFileNames { - guard animationCache[name] == nil, - let path = Bundle.main.path(forResource: name, ofType: "json"), - let anim = LottieAnimation.filepath(path) else { continue } - animationCache[name] = anim - } - } - } - - private let lottieView: LottieAnimationView = { - let v = LottieAnimationView() - v.contentMode = .scaleAspectFit - v.loopMode = .loop - return v - }() - - override init(frame: CGRect) { - super.init(frame: frame) - contentView.addSubview(lottieView) - lottieView.layoutChain.edges() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func configure(path: String) { - lottieView.stop() - if let cached = Self.animationCache[path] { - lottieView.animation = cached - } else { - lottieView.animation = LottieAnimation.filepath(path) - } - lottieView.currentProgress = 0 - lottieView.play() - } - - override func prepareForReuse() { - super.prepareForReuse() - lottieView.stop() - lottieView.animation = nil - } -} // MARK: - 发送的语音消息 final class VoiceSendMsgCell: UITableViewCell, VoicePlaybackView { @@ -1057,7 +997,7 @@ final class VoiceSendMsgCell: UITableViewCell, VoicePlaybackView { if let path = Bundle.main.path(forResource: "message_voice_play", ofType: "json") { v.animation = LottieAnimation.filepath(path) } - v.loopMode = .loop +// v.loopMode = .loop v.contentMode = .scaleAspectFit return v }() diff --git a/QuickLocation/Section/Home/GroupMemberView.swift b/QuickLocation/Section/Home/GroupMemberView.swift index c33446ea..11deccad 100644 --- a/QuickLocation/Section/Home/GroupMemberView.swift +++ b/QuickLocation/Section/Home/GroupMemberView.swift @@ -165,10 +165,14 @@ class GroupMemberCell: UITableViewCell { nameLab.textColor = UIColor(hexStr: isCurrentUser ? "#16B3FF" : "#0F2846") - // 电量 16是电池图标宽度,右边有电池造型需要减去 - let batteryPercent = min(CGFloat(model.battery.int), 100) - batteryView.layoutChain.width(CGFloat(16 - 1) * batteryPercent / 100.0) - batteryLab.text = "\(model.battery)%" + // 会员权益 + if AppContextManager.shared.vip > 1, model.is_online { + batteryInfoView.isHidden = model.battery.int == 0 + // 电量 16是电池图标宽度,右边有电池造型需要减去 + let batteryPercent = min(CGFloat(model.battery.int), 100) + batteryView.layoutChain.width(CGFloat(16 - 1) * batteryPercent / 100.0) + batteryLab.text = "\(model.battery)%" + } // 在线状态 if model.is_online { @@ -292,6 +296,7 @@ class GroupMemberCell: UITableViewCell { view.layer.shadowOffset = CGSize(width: 0, height: 2) view.layer.shadowOpacity = 1 view.layer.shadowRadius = 6 + view.isHidden = true return view }() diff --git a/QuickLocation/Section/Home/HomeView.swift b/QuickLocation/Section/Home/HomeView.swift index cfdff26b..cb96f51d 100644 --- a/QuickLocation/Section/Home/HomeView.swift +++ b/QuickLocation/Section/Home/HomeView.swift @@ -10,7 +10,7 @@ import RxSwift import RxCocoa import Lottie #if !targetEnvironment(simulator) -import MAMapKit +import AMapNaviKit #endif class HomeView: UIView { @@ -76,6 +76,7 @@ class HomeView: UIView { }) .disposed(by: disposeBag) + // tableView 到达顶部继续下拉时,改由 GroupMemberView 的 pan 手势接管 groupMemberView.tableView.rx.contentOffset .subscribe(onNext: { [weak self] offset in diff --git a/QuickLocation/Section/Home/HomeViewController.swift b/QuickLocation/Section/Home/HomeViewController.swift index adf40e44..62b774fc 100644 --- a/QuickLocation/Section/Home/HomeViewController.swift +++ b/QuickLocation/Section/Home/HomeViewController.swift @@ -13,7 +13,7 @@ import CoreLocation import SwiftyUserDefaults #if !targetEnvironment(simulator) -import MAMapKit +import AMapNaviKit import CocoaMQTT #endif @@ -43,6 +43,10 @@ class HomeViewController: BaseViewController { private var subscribedMemberIds: [String] = [] /// 底部成员面板是否显示 private var isMemberPanelShown = false + /// 记录每个成员最后一次收到位置的时间(MQTT userId → Date) + private var lastUpdateTimes: [String: Date] = [:] + /// 离线检测定时器 + private var offlineCheckTimer: Timer? override func loadView() { #if !targetEnvironment(simulator) @@ -66,6 +70,7 @@ class HomeViewController: BaseViewController { // MQTT 位置上报 UIDevice.current.isBatteryMonitoringEnabled = true startLocationTimer() + startOfflineCheckTimer() } // MARK: - MQTT 位置上报 @@ -101,6 +106,25 @@ class HomeViewController: BaseViewController { } } + private func startOfflineCheckTimer() { + offlineCheckTimer?.invalidate() + offlineCheckTimer = Timer.scheduledTimer(withTimeInterval: 30, repeats: true) { [weak self] _ in + self?.checkOfflineMembers() + } + } + + /// 检查超时未更新的成员,标记离线 + private func checkOfflineMembers() { + let now = Date() + for (userId, lastTime) in lastUpdateTimes { + guard userId != AppContextManager.shared.userId, + now.timeIntervalSince(lastTime) > 60 else { continue } + viewModel.setMemberOffline(userId: userId) + removeAnnotation(userId: userId) + updateOnlineCount() + } + } + private func publishLocation(coord: CLLocationCoordinate2D, address: String, loc: CLLocation) { MQTTService.shared.reportLocation( lat: coord.latitude, @@ -159,9 +183,24 @@ class HomeViewController: BaseViewController { (self?.tabBarController as? MainTabBarController)?.setTabBarHidden(false) } + // 导航按钮回调 + rootView.interactionView.onNavigate = { [weak self] in + guard let self = self, let member = self.rootView.interactionView.currentMember else { return } + let userCoord = self.lastLocation?.coordinate + let groupName = self.viewModel.groupName + let model = self.viewModel.groupModel + let iconIndex = model?.groups.first(where: { $0.group_key == model?.default_group_key })?.icon_index ?? 1 + let vc = NavigationVC(member: member, currentUserCoord: userCoord, groupName: groupName, groupIcon: "\(iconIndex)") + self.navigationController?.pushViewController(vc, animated: true) + } + // MQTT 接收 - MQTTService.shared.onMessageReceived = { message, id, properties in - print("收到消息: \(message.string ?? "")") + MQTTService.shared.subscribe(topic: "smartdrive/") { message in + guard let msgStr = message.string, + let data = msgStr.data(using: .utf8), + let msg = try? JSONDecoder().decode(MqttIncomingMessage.self, from: data) + else { return } + print("📩 收到消息 -> 主题:\(message.topic),内容:\(msg)") } } @@ -239,7 +278,7 @@ class HomeViewController: BaseViewController { GroupService.groupInfo().subscribe { response in guard let model = response.model else { return } self.viewModel.groupModel = model - self.rootView.groupMemberView.setupCountData(self.viewModel.memberCount, self.viewModel.memberOnlineCount) + self.rootView.groupMemberView.setupCountData(self.viewModel.memberCount, 1) self.rootView.groupNameLab.text = self.viewModel.groupName self.syncMemberAnnotations(model.select_group_employee) self.refreshMQTTSubscriptions(model.select_group_employee) @@ -321,6 +360,11 @@ class HomeViewController: BaseViewController { } let currentUserId = AppContextManager.shared.userId + var lastUpdateTime: Int64 = 0 + if let currentModel = list.first(where: { $0.user_id == AppContextManager.shared.userId }) { + lastUpdateTime = currentModel.last_active_time + } + // 当前用户始终由 GPS 定位,单独注入 let me = CircleMember( id: "current", @@ -331,7 +375,7 @@ class HomeViewController: BaseViewController { coordinate: kCLLocationCoordinate2DInvalid, address: "", heading: 0, - lastUpdateText: "在线", + lastUpdateTime: lastUpdateTime, battery: "" ) @@ -346,16 +390,18 @@ class HomeViewController: BaseViewController { let newMembers = others + [me] members = newMembers currentUserMember = me + // 从 members 中过滤出在线成员用于地图标注 + let onlineMembers = newMembers.filter { $0.isOnline } let mapView = rootView.mapView let existing = mapView.annotations?.compactMap { $0 as? MemberAnnotation } ?? [] let existingIDs = Set(existing.map { $0.member.id }) - let newIDs = Set(newMembers.map { $0.id }) + let onlineIDs = Set(onlineMembers.map { $0.id }) - let toRemove = existing.filter { !newIDs.contains($0.member.id) } + let toRemove = existing.filter { !onlineIDs.contains($0.member.id) } mapView.removeAnnotations(toRemove) - let toAdd = newMembers.filter { !existingIDs.contains($0.id) } + let toAdd = onlineMembers.filter { !existingIDs.contains($0.id) } let annotations = toAdd.map { MemberAnnotation(member: $0) } mapView.addAnnotations(annotations) #endif @@ -376,17 +422,16 @@ class HomeViewController: BaseViewController { // MARK: - MQTT extension HomeViewController { - /// 切换圈子时刷新 MQTT 订阅(排除当前用户) + /// 切换圈子时刷新 MQTT 订阅 private func refreshMQTTSubscriptions(_ members: [GroupMemberModel]) { - let currentId = AppContextManager.shared.userId - let newIds = members.map { $0.user_id }.filter { $0 != currentId } +// let currentId = AppContextManager.shared.userId + let newIds = members.map { $0.user_id }//.filter { $0 != currentId } // 排除当前用户 let toUnsub = subscribedMemberIds.filter { !newIds.contains($0) } MQTTService.shared.unsubscribeGroupMembers(toUnsub) let toSub = newIds.filter { !subscribedMemberIds.contains($0) } for memberId in toSub { let topic = "smartdrive/\(memberId)" MQTTService.shared.subscribe(topic: topic) { [weak self] message in - self?.handleMemberLocation(topic: message.topic, payload: message.string) } } @@ -410,31 +455,46 @@ extension HomeViewController { let msgTimeMs = Double(firstPoint.time) let diffSec = (nowMs - msgTimeMs) / 1000 let isOnline = diffSec < 60 - let lastUpdateText: String - if isOnline { - lastUpdateText = "" - } else if diffSec < 3600 { - lastUpdateText = "\(Int(diffSec / 60))分钟前" - } else if diffSec < 86400 { - lastUpdateText = "\(Int(diffSec / 3600))小时前" - } else { - lastUpdateText = "\(Int(diffSec / 86400))天前" - } let battery = msg.data?.battery ?? "" DispatchQueue.main.async { [weak self] in guard let self = self else { return } + // 记录更新时间 + self.lastUpdateTimes[userId] = Date() // 更新列表(地址、电量、在线状态) self.viewModel.updateMemberLocation( userId: userId, lat: firstPoint.lat, lon: firstPoint.lon, address: firstPoint.addr, battery: battery, - isOnline: isOnline, lastUpdateText: lastUpdateText + isOnline: isOnline, lastUpdateTime: firstPoint.time ) - // 更新地图标注位置 - self.updateAnnotation(userId: userId, coordinate: coord, address: firstPoint.addr) + updateOnlineCount() + // 更新地图标注位置(离线则不显示标注) + if isOnline { + self.updateAnnotation(userId: userId, coordinate: coord, address: firstPoint.addr) + } else { + self.removeAnnotation(userId: userId) + } } } + /// 更新成员在线计数显示 + private func updateOnlineCount() { + let total = viewModel.memberCount + let online = viewModel.memberList.filter { $0.is_online }.count + rootView.groupMemberView.setupCountData(total, online) + } + + /// 移除指定成员的标注 + private func removeAnnotation(userId: String) { + #if !targetEnvironment(simulator) + let mapView = rootView.mapView + let toRemove = mapView.annotations?.compactMap({ $0 as? MemberAnnotation }).filter { $0.member.id == userId } + if let remove = toRemove, !remove.isEmpty { + mapView.removeAnnotations(remove) + } + #endif + } + /// 更新指定成员的标注位置(只更新坐标,头像/名称不变) private func updateAnnotation(userId: String, coordinate: CLLocationCoordinate2D, address: String) { #if !targetEnvironment(simulator) @@ -445,17 +505,22 @@ extension HomeViewController { id: old.id, name: old.name, avatar: old.avatar, isOnline: true, isOwner: old.isOwner, coordinate: coordinate, address: address, - heading: old.heading, lastUpdateText: "在线", + heading: old.heading, lastUpdateTime: old.lastUpdateTime, battery: old.battery ) } - // 更新地图标注坐标 + + // 更新地图标注 let mapView = rootView.mapView - for ann in mapView.annotations?.compactMap({ $0 as? MemberAnnotation }) ?? [] { - if ann.member.id == userId { - ann.coordinate = coordinate - break + if let oldMember = members.first(where: { $0.id == userId }), oldMember.isOnline { + // 先移除旧标注,再添加新标注 + let toRemove = mapView.annotations?.compactMap({ $0 as? MemberAnnotation }).filter { $0.member.id == userId } + if let remove = toRemove, !remove.isEmpty { + mapView.removeAnnotations(remove) } + let newAnn = MemberAnnotation(member: oldMember) + mapView.addAnnotation(newAnn) + print("📌 updateAnnotation userId=\(userId) coord=\(coordinate.latitude),\(coordinate.longitude)") } #endif } diff --git a/QuickLocation/Section/Home/HomeViewModel.swift b/QuickLocation/Section/Home/HomeViewModel.swift index 6dcd9fd9..219c4684 100644 --- a/QuickLocation/Section/Home/HomeViewModel.swift +++ b/QuickLocation/Section/Home/HomeViewModel.swift @@ -83,18 +83,6 @@ class HomeViewModel { var memberList: [GroupMemberModel] = [] { didSet { var tempList = memberList - - // 当前用户的电量 -// if var model = memberList.first(where: { $0.user_id == AppContextManager.shared.userId }), -// let idx = memberList.firstIndex(where: { $0.user_id == AppContextManager.shared.userId }) { -// let battery = UIDevice.current.batteryLevel > 0 -// ? Int(UIDevice.current.batteryLevel * 100) -// : 0 -// model.battery = battery.string -// model.is_online = true -// tempList[idx] = model -// } - tempList.moveToFirst { $0.user_id == AppContextManager.shared.userId } tempList.moveToFirst { isGroupOwn(id: $0.user_id) } memberList = tempList @@ -102,14 +90,22 @@ class HomeViewModel { } } + /// 标记成员离线(保留 last_active_time 用于显示"X分钟前") + func setMemberOffline(userId: String) { + guard let idx = memberList.firstIndex(where: { $0.user_id == userId }) else { return } + var updated = memberList + updated[idx].is_online = false + memberList = updated + } + /// MQTT 位置更新后刷新成员的地址、电量、在线状态 - func updateMemberLocation(userId: String, lat: Double, lon: Double, address: String, battery: String, isOnline: Bool, lastUpdateText: String) { + func updateMemberLocation(userId: String, lat: Double, lon: Double, address: String, battery: String, isOnline: Bool, lastUpdateTime: Int64) { guard let idx = memberList.firstIndex(where: { $0.user_id == userId }) else { return } var updated = memberList updated[idx].last_position = "\(lat):\(lon):\(address)" updated[idx].battery = battery updated[idx].is_online = isOnline - updated[idx].lastUpdateText = lastUpdateText + updated[idx].last_active_time = lastUpdateTime memberList = updated // 触发 didSet → 排序 + 重发 sectionedItems } diff --git a/QuickLocation/Section/Home/InteractionView.swift b/QuickLocation/Section/Home/InteractionView.swift index 9b635230..cc6afca2 100644 --- a/QuickLocation/Section/Home/InteractionView.swift +++ b/QuickLocation/Section/Home/InteractionView.swift @@ -6,24 +6,99 @@ // import UIKit +import RxSwift +import RxCocoa +import RxDataSources +import Lottie class InteractionView: UIView { + var disposeBag = DisposeBag() + + private static let emojiCols = 4 + private static let emojiRows = 3 + private static let emojiPerPage = emojiCols * emojiRows + func configure(member: CircleMember) { + self.currentMember = member avaterImgView.image = UIImage(named: "UserIcon/\(member.avatar)") nameLab.text = member.name locationLab.text = member.address - // 电量 - let batteryInt = Int(member.battery) ?? 0 - let batteryPercent = min(CGFloat(batteryInt), 100) - batteryView.layoutChain.width(CGFloat(16 - 1) * batteryPercent / 100.0) - batteryLab.text = "\(member.battery)%" + + // 会员权益 + if AppContextManager.shared.vip > 1 { + batteryInfoView.isHidden = member.battery.int == 0 + // 电量 + let batteryInt = Int(member.battery) ?? 0 + let batteryPercent = min(CGFloat(batteryInt), 100) + batteryView.layoutChain.width(CGFloat(16 - 1) * batteryPercent / 100.0) + batteryLab.text = "\(member.battery)%" + + // 趣味表情 + lockView.isHidden = true + } + else { + batteryInfoView.isHidden = true + lockView.isHidden = false + } } + /// 当前表情列表(normal / fun) + private let emojiRelay = BehaviorRelay<[String]>(value: UIView.emojiFileNames) + private func setupRx() { + // 切换表情分类 + emojiNormalBtn.rx.tap + .subscribe(onNext: { [weak self] _ in + self?.normalBg.isHidden = true + self?.interestBg.isHidden = false + self?.emojiRelay.accept(UIView.emojiFileNames) + }) + .disposed(by: disposeBag) + emojiFunBtn.rx.tap + .subscribe(onNext: { [weak self] _ in + self?.normalBg.isHidden = false + self?.interestBg.isHidden = true + self?.emojiRelay.accept(UIView.funEmojiFileNames) + }) + .disposed(by: disposeBag) + + navigateBtn.rx.tap + .subscribe(onNext: { [weak self] _ in + self?.onNavigate?() + }) + .disposed(by: disposeBag) + + // 绑定表情数据到 collectionView + emojiRelay + .map { [SectionModel(model: "", items: $0)] } + .bind(to: emojiCollectionView.rx.items(dataSource: dataSource)) + .disposed(by: disposeBag) + + // 切换时更新 pageControl + emojiRelay + .subscribe(onNext: { [weak self] items in + guard let self = self else { return } + let pages = (items.count + InteractionView.emojiPerPage - 1) / InteractionView.emojiPerPage + self.emojiPageControl.numberOfPages = max(pages, 1) + self.emojiPageControl.currentPage = 0 + self.emojiCollectionView.setContentOffset(.zero, animated: false) + }) + .disposed(by: disposeBag) } + private lazy var dataSource: RxCollectionViewSectionedReloadDataSource> = { + RxCollectionViewSectionedReloadDataSource> { _, collectionView, indexPath, name in + let cell: EmojiPanelCell = collectionView.dequeueReusableCell(for: indexPath) + if let path = Bundle.main.path(forResource: name, ofType: "json") { + cell.configure(path: path) + cell.playAnimation() + } + return cell + } + }() + private func setupUI() { addSubview(infoView) infoView.addSubview(headerBgView) @@ -38,6 +113,11 @@ class InteractionView: UIView { infoView.addSubview(locationLab) infoView.addSubview(navigateBtn) infoView.addSubview(shareBtn) + infoView.addSubview(emojiView) + emojiView.addSubview(emojiBgView) + emojiView.addSubview(segmentView) + emojiView.addSubview(emojiCollectionView) + emojiView.addSubview(emojiPageControl) infoView.layoutChain.edges() @@ -100,6 +180,27 @@ class InteractionView: UIView { .centerY(avaterImgView) .width(30) .height(30) + + emojiView.layoutChain + .topToBottomOfView(batteryInfoView, offset: 21) + .edgesHorzontal(15) + .height(276) + + emojiBgView.layoutChain.edges() + + segmentView.layoutChain + .edges(excludingEdge: .bottom) + .height(56) + + emojiPageControl.layoutChain + .centerX() + .height(28) + .bottom(13) + + emojiCollectionView.layoutChain + .top(51) + .edgesHorzontal() + .height(180) } lazy var infoView: UIView = { @@ -135,6 +236,7 @@ class InteractionView: UIView { view.layer.shadowOffset = CGSize(width: 0, height: 2) view.layer.shadowOpacity = 1 view.layer.shadowRadius = 6 + view.isHidden = true return view }() @@ -195,9 +297,168 @@ class InteractionView: UIView { return btn }() + lazy var emojiView: UIView = { + let view = UIView() + view.backgroundColor = UIColor(hexStr: "#E3F7FE")//.clear + view.cornerRadius = 15 + return view + }() + + lazy var emojiBgView: UIView = { + let view = UIImageView()//UIImageView(image: UIImage(named: "Home/emoji_bg")) + view.contentMode = .scaleAspectFill + return view + }() + + lazy var segmentView: UIView = { + let view = UIView() + view.backgroundColor = UIColor(hexStr: "#E3F7FE") + + view.addSubview(normalBg) + view.addSubview(interestBg) + normalBg.layoutChain + .top().left() + .height(56) + .widthToHeight(220/56) + + interestBg.layoutChain + .top().right() + .height(56) + .widthToHeight(220/56) + + let normalLab = UILabel() + normalLab.text = "常规表情" + normalLab.font = .systemFont(ofSize: 12, weight: .semibold) + normalLab.textColor = .black + normalLab.textAlignment = .center + view.addSubview(normalLab) + normalLab.layoutChain + .top(11) + .left().rightToCenterXOfView(view) + + let interesView = UIView() + interesView.backgroundColor = .clear + view.addSubview(interesView) + interesView.layoutChain + .top(11) + .right().leftToCenterXOfView(view) + .height(18) + + let interestLab = UILabel() + interestLab.text = "趣味表情" + interestLab.font = .systemFont(ofSize: 12, weight: .semibold) + interestLab.textColor = .black + interestLab.textAlignment = .center + + interesView.addSubview(interestLab) + interestLab.layoutChain + .top() + .centerX() + + interesView.addSubview(lockView) + lockView.layoutChain + .leftToRightOfView(interestLab, offset: 4) + .centerY(interestLab) + .width(18) + .height(18) + + view.addSubview(emojiNormalBtn) + emojiNormalBtn.layoutChain + .top() + .left() + .rightToCenterXOfView(view) + .height(40) + + view.addSubview(emojiFunBtn) + emojiFunBtn.layoutChain + .top() + .right() + .leftToCenterXOfView(view) + .height(40) + + return view + }() + + lazy var normalBg: UIImageView = { + let view = UIImageView(image: UIImage(named: "Home/emoji_normal")) + view.contentMode = .scaleAspectFill + view.isHidden = true + return view + }() + + lazy var interestBg: UIImageView = { + let view = UIImageView(image: UIImage(named: "Home/emoji_interest")) + view.contentMode = .scaleAspectFill + return view + }() + + lazy var emojiNormalBtn: UIButton = { + let btn = UIButton() + btn.backgroundColor = .clear + return btn + }() + + lazy var emojiFunBtn: UIButton = { + let btn = UIButton() + btn.backgroundColor = .clear + return btn + }() + + lazy var lockView: UIView = { + let view = UIView() + view.backgroundColor = .white + view.cornerRadius = 9 + + let icon = UIImageView(image: UIImage(named: "Home/lock")) + view.addSubview(icon) + icon.layoutChain + .centerX() + .centerY() + + return view + }() + + lazy var emojiCollectionView: UICollectionView = { + let layout = CollectionHFlowLayout() + let hSpacing: CGFloat = (kScreenWidth - 30 - CGFloat(InteractionView.emojiCols) * 50) / CGFloat(InteractionView.emojiCols + 1) + let vSpacing: CGFloat = (180 - CGFloat(InteractionView.emojiRows) * 50) / CGFloat(InteractionView.emojiRows + 1) + layout.rows = InteractionView.emojiRows + layout.colums = InteractionView.emojiCols + layout.itemSize = CGSize(width: 50, height: 50) + layout.hSpacing = hSpacing + layout.vSpacing = vSpacing + layout.sectionInset = UIEdgeInsets(top: 0, left: hSpacing, bottom: 0, right: hSpacing) + let cv = UICollectionView(frame: .zero, collectionViewLayout: layout) + cv.backgroundColor = .clear + cv.isPagingEnabled = true + cv.bounces = false + cv.showsHorizontalScrollIndicator = false + cv.register(EmojiPanelCell.self) + cv.delegate = self + return cv + }() + + var onNavigate: (() -> Void)? + var currentMember: CircleMember? + + lazy var emojiPageControl: UIPageControl = { + let pc = UIPageControl() + pc.numberOfPages = (UIView.emojiFileNames.count + InteractionView.emojiPerPage - 1) / InteractionView.emojiPerPage + pc.currentPageIndicatorTintColor = UIColor(hexStr: "#16B3FF") + pc.pageIndicatorTintColor = UIColor(hexStr: "#7AD6FF", alpha: 0.4) + return pc + }() + override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .clear + // 同步预加载 fun 表情到缓存,避免首次切换卡顿 + for name in UIView.funEmojiFileNames { + guard EmojiPanelCell.animationCache[name] == nil, + let path = Bundle.main.path(forResource: name, ofType: "json"), + let anim = LottieAnimation.filepath(path) else { continue } + EmojiPanelCell.animationCache[name] = anim + } setupUI() setupRx() } @@ -212,3 +473,101 @@ class InteractionView: UIView { infoView.setCornerRadius(corners: [.topLeft ,.topRight], withCornerRadii: CGSize(width: 20, height: 20)) } } + +// MARK: - UICollectionViewDelegate (page control) +extension InteractionView: UICollectionViewDelegate { + func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { + guard scrollView == emojiCollectionView else { return } + let page = Int(scrollView.contentOffset.x / scrollView.bounds.width) + emojiPageControl.currentPage = page + } +} + +// MARK: - EmojiPanelCell +final class EmojiPanelCell: UICollectionViewCell { + + static var animationCache: [String: LottieAnimation] = [:] + + private let lottieView: LottieAnimationView = { + let v = LottieAnimationView() + v.contentMode = .scaleAspectFit +// v.loopMode = .loop + return v + }() + + lazy var lockView: UIView = { + let view = UIView() + view.backgroundColor = .clear + view.isHidden = true + + let icon = UIImageView(image: UIImage(named: "Home/emoji_lock")) + view.addSubview(icon) + icon.layoutChain + .edges() + + return view + }() + + override init(frame: CGRect) { + super.init(frame: frame) + contentView.addSubview(lottieView) + contentView.addSubview(lockView) + lottieView.layoutChain.edges() + lockView.layoutChain + .right() + .bottom() + .width(14) + .height(14) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func configure(path: String) { + lottieView.stop() + if let cached = Self.animationCache[path] { + lottieView.animation = cached + } else { + lottieView.animation = LottieAnimation.filepath(path) + } + lottieView.currentProgress = 0 + + lockView.isHidden = AppContextManager.shared.vip > 1 + } + + func playAnimation() { + lottieView.play() + } + + func stopAnimation() { + lottieView.stop() + } + + override func prepareForReuse() { + super.prepareForReuse() + lottieView.stop() + lottieView.animation = nil + } +} + +// MARK: - 表情文件列表(共用) +extension UIView { + static var emojiFileNames: [String] = { + let paths = Bundle.main.paths(forResourcesOfType: "json", inDirectory: nil) + return paths + .compactMap { $0.components(separatedBy: "/").last } + .filter { $0.hasPrefix("normal_") && $0.hasSuffix(".json") } + .map { $0.replacingOccurrences(of: ".json", with: "") } + .sorted() + }() + + static var funEmojiFileNames: [String] = { + let paths = Bundle.main.paths(forResourcesOfType: "json", inDirectory: nil) + return paths + .compactMap { $0.components(separatedBy: "/").last } + .filter { $0.hasPrefix("fun_") && $0.hasSuffix(".json") } + .map { $0.replacingOccurrences(of: ".json", with: "") } + .sorted() + }() +} diff --git a/QuickLocation/Section/Map/CircleMember.swift b/QuickLocation/Section/Map/CircleMember.swift index 3e50b510..6032a319 100644 --- a/QuickLocation/Section/Map/CircleMember.swift +++ b/QuickLocation/Section/Map/CircleMember.swift @@ -15,7 +15,7 @@ struct CircleMember { let coordinate: CLLocationCoordinate2D let address: String let heading: Double - let lastUpdateText: String + let lastUpdateTime: Int64 let battery: String var isCurrentUser: Bool { id == "current" } @@ -33,7 +33,7 @@ extension CircleMember { coordinate = coord address = addr heading = 0 - lastUpdateText = member.is_online ? "在线" : "离线" + lastUpdateTime = member.last_active_time battery = member.battery } diff --git a/QuickLocation/Section/Map/MemberAnnotation.swift b/QuickLocation/Section/Map/MemberAnnotation.swift index 70ea1703..e6ff690d 100644 --- a/QuickLocation/Section/Map/MemberAnnotation.swift +++ b/QuickLocation/Section/Map/MemberAnnotation.swift @@ -5,7 +5,7 @@ import Foundation #if !targetEnvironment(simulator) -import MAMapKit +import AMapNaviKit final class MemberAnnotation: NSObject, MAAnnotation { let member: CircleMember diff --git a/QuickLocation/Section/Map/MemberAnnotationView.swift b/QuickLocation/Section/Map/MemberAnnotationView.swift index f39d57b2..56e2140f 100644 --- a/QuickLocation/Section/Map/MemberAnnotationView.swift +++ b/QuickLocation/Section/Map/MemberAnnotationView.swift @@ -5,7 +5,7 @@ import Foundation #if !targetEnvironment(simulator) -import MAMapKit +import AMapNaviKit final class MemberAnnotationView: MAAnnotationView { diff --git a/QuickLocation/Section/Map/Navigation/NavigationVC.swift b/QuickLocation/Section/Map/Navigation/NavigationVC.swift new file mode 100644 index 00000000..9ac5a7ec --- /dev/null +++ b/QuickLocation/Section/Map/Navigation/NavigationVC.swift @@ -0,0 +1,306 @@ +// +// NavigationVC.swift +// QuickLocation +// +// Created by 八条 on 2026/6/16. +// + +import UIKit +import RxSwift +import RxCocoa +import CoreLocation +#if !targetEnvironment(simulator) +import AMapNaviKit +import MapKit +#endif + +class NavigationVC: BaseViewController { + + override var isNavigationBarHidden: Bool { true } + + fileprivate var rootView: NavigationView! + private let member: CircleMember + private let currentUserCoord: CLLocationCoordinate2D? + private let groupName: String + private let groupIconIndex: String + + #if !targetEnvironment(simulator) + private var routeOverlay: MAPolyline? + #endif + + init(member: CircleMember, currentUserCoord: CLLocationCoordinate2D?, groupName: String = "", groupIcon: String = "") { + self.member = member + self.currentUserCoord = currentUserCoord + self.groupName = groupName + self.groupIconIndex = groupIcon + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func loadView() { + rootView = NavigationView(frame: UIScreen.main.bounds) + view = rootView + } + + override func viewDidLoad() { + super.viewDidLoad() + rootView.configure(member: member, groupName: groupName, groupIcon: groupIconIndex) + reactiveAction() + setupMap() + calculateDistance() + requestRoute() + } + + // MARK: - Actions + private func reactiveAction() { + rootView.navigationBtn.rx.tap.subscribe(onNext: { _ in + self.touchGoMap() + }).disposed(by: disposeBag) + } + + private func setupMap() { + #if !targetEnvironment(simulator) + rootView.mapView.delegate = self + rootView.mapView.showsUserLocation = true + #endif + } + + private func requestRoute() { + #if !targetEnvironment(simulator) + guard let from = currentUserCoord, + CLLocationCoordinate2DIsValid(from), + CLLocationCoordinate2DIsValid(member.coordinate) else { return } + + let naviManager = AMapNaviDriveManager.sharedInstance() + naviManager.delegate = self + + guard let startPoint = AMapNaviPoint.location(withLatitude: CGFloat(from.latitude), longitude: CGFloat(from.longitude)), + let endPoint = AMapNaviPoint.location(withLatitude: CGFloat(member.coordinate.latitude), longitude: CGFloat(member.coordinate.longitude)) else { return } + + naviManager.calculateDriveRoute(withStart: [startPoint], end: [endPoint], wayPoints: nil, drivingStrategy: .drivingStrategySingleDefault) + #endif + } + + private func calculateDistance() { + guard CLLocationCoordinate2DIsValid(member.coordinate) else { return } + let memberLoc = CLLocation(latitude: member.coordinate.latitude, longitude: member.coordinate.longitude) + guard let userLoc = currentUserCoord.map({ CLLocation(latitude: $0.latitude, longitude: $0.longitude) }) else { + rootView.distanceLab.text = "" + return + } + let dist = memberLoc.distance(from: userLoc) + if dist < 1000 { + rootView.distanceLab.text = "距离 \(Int(dist)) 米" + } else { + rootView.distanceLab.text = "距离 \(String(format: "%.1f", dist / 1000)) 公里" + } + } + + func touchGoMap() { + let coortitle = "目的地" + let latitute = member.coordinate.latitude + let longitute = member.coordinate.longitude + // "请选择导航应用程序" + let alert = UIAlertController(title: "请选择导航应用程序", message: nil, preferredStyle: .actionSheet) + + if canOpenUrl("iosamap://") {//高德 + alert.addAction(UIAlertAction(title: "高德地图", style: .default, handler: { _ in + self.amap(dlat: latitute, dlon: longitute, dname: coortitle, way: 0) + })) + } + + if canOpenUrl("baidumap://") {//百度 + alert.addAction(UIAlertAction(title: "百度地图", style: .default, handler: { _ in + self.baidumap(endAddress: coortitle, way: "driving", lat: latitute,lng: longitute) + })) + } + + if canOpenUrl("qqmap://") {//腾讯 + alert.addAction(UIAlertAction(title: "腾讯地图", style: .default, handler: { _ in + self.qqmap(endAddress: coortitle, way: "driving", lat: latitute,lng: longitute) + })) + } + + alert.addAction(UIAlertAction(title: "Apple 地图", style: .default, handler: { _ in + self.appleMap(lat:latitute , lng:longitute, destination: coortitle) + })) + + alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil)) + self.present(alert, animated: true, completion: nil) + } +} + +#if !targetEnvironment(simulator) +// MARK: - AMapNaviDriveManagerDelegate +extension NavigationVC: AMapNaviDriveManagerDelegate { + func driveManager(onCalculateRouteSuccess driveManager: AMapNaviDriveManager) { + guard let route = driveManager.naviRoute else { return } + + if let overlay = routeOverlay { + rootView.mapView.remove(overlay) + } + + let coords = route.routeCoordinates.compactMap { point -> CLLocationCoordinate2D in + return CLLocationCoordinate2D(latitude: Double(point.latitude), longitude: Double(point.longitude)) + }.filter { CLLocationCoordinate2DIsValid($0) } + + guard coords.count > 1 else { return } + + var mutableCoords = coords + if let polyline = MAPolyline(coordinates: &mutableCoords, count: UInt(coords.count)) { + rootView.mapView.add(polyline) + routeOverlay = polyline + rootView.mapView.setVisibleMapRect(polyline.boundingMapRect, animated: true) + } + + let distM = Int(route.routeLength) + if distM < 1000 { + rootView.distanceLab.text = "距离 \(distM) 米" + } else { + rootView.distanceLab.text = "距离 \(String(format: "%.1f", Double(distM) / 1000)) 公里" + } + + let endAnn = MAPointAnnotation() + endAnn.coordinate = member.coordinate + endAnn.title = member.name + rootView.mapView.addAnnotation(endAnn) + } + + func driveManager(_ driveManager: AMapNaviDriveManager, onCalculateRouteFailure error: Error) { + print("Navi route failed: \(error.localizedDescription)") + } +} + +// MARK: - MAMapViewDelegate +extension NavigationVC: MAMapViewDelegate { + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation is MAUserLocation { return nil } + let identifier = "NavPin" + var view = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MAPinAnnotationView + if view == nil { + view = MAPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) + } else { + view?.annotation = annotation + } +// view?.pinColor = .red +// view?.canShowCallout = true + return view + } + + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if let polyline = overlay as? MAPolyline { + let renderer = MAPolylineRenderer(polyline: polyline) + renderer?.strokeColor = UIColor(hexStr: "34B824") + renderer?.lineWidth = 6 + return renderer + } + return nil + } +} +#endif + + +// MARK: - 地图导航 +extension NavigationVC { + // 打开苹果地图 + func appleMap(lat: Double, lng: Double, destination: String) { + let loc = CLLocationCoordinate2DMake(lat, lng) + let currentLocation = MKMapItem.forCurrentLocation() + let toLocation = MKMapItem(placemark:MKPlacemark(coordinate:loc,addressDictionary:nil)) + toLocation.name = destination + let boo = MKMapItem.openMaps(with: [currentLocation,toLocation], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: NSNumber(value: true)]) + print(boo) + + } + + // 打开高德地图 + func amap(dlat: Double, dlon: Double, dname: String, way: Int) { + let appName = "极速定位" + let urlString = "iosamap://path?sourceApplication=\(appName)&dname=\(dname)&dlat=\(dlat)&dlon=\(dlon)&t=\(way)" as String + if self.openMap(urlString) == false { + print("您还没有安装高德地图") + let urlString = "itms-apps://itunes.apple.com/app/id452186370" + self.openURL(urlString: urlString) + } + } + + // 打开腾讯地图 + func qqmap(endAddress: String, way: String, lat: Double, lng: Double) { + + let urlString = "qqmap://map/routeplan?type=\(way)&from=&fromcoord=CurrentLocation&to=\(endAddress)&tocoord=\(lat),\(lng)&referer=腾讯需要申请APPkey" + let str = urlString as String + + if self.openMap(str) == false { + print("您还没有安装腾讯地图") + let urlString = "itms-apps://itunes.apple.com/app/id481623196" + self.openURL(urlString: urlString) + } + } + + // 打开百度地图 + func baidumap(endAddress: String, way: String, lat: Double, lng: Double) { + + let coordinate = CLLocationCoordinate2DMake(lat, lng) + + // 将高德的经纬度转为百度的经纬度 + let baiduCoordinate = getBaiDuCoordinateByGaoDeCoordinate(coordinate: coordinate) + + let destination = "\(baiduCoordinate.latitude),\(baiduCoordinate.longitude)" + + let urlString = "baidumap://map/direction?" + "&destination=" + endAddress + "&mode=" + way + "&destination=" + destination + + let str = urlString as String + + if self.openMap(str) == false { + print("您还没有安装百度地图") + let urlString = "itms-apps://itunes.apple.com/app/id452186370" as String + self.openURL(urlString: urlString) + } + } + + // 打开第三方地图 + private func openMap(_ urlString: String) -> Bool { + let urlstr = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? "" + guard let url = URL(string: urlstr) else { + return false + } + if UIApplication.shared.canOpenURL(url) == true { + self.openURL(urlString: urlString as String) + return true + } else { + return false + } + } + + func openURL(urlString:String) { + let urlstr = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? "" + + guard let url = URL(string:urlstr) else { + return + } + //根据iOS系统版本,分别处理 + if #available(iOS 10, *) { + UIApplication.shared.open(url , options: [:], + completionHandler: { (success) in + + }) + } else { + UIApplication.shared.openURL(url ) + } + } + + // 高德经纬度转为百度地图经纬度 + // 百度经纬度转为高德经纬度,减掉相应的值就可以了。 + func getBaiDuCoordinateByGaoDeCoordinate(coordinate:CLLocationCoordinate2D) -> CLLocationCoordinate2D { + return CLLocationCoordinate2DMake(coordinate.latitude + 0.006, coordinate.longitude + 0.0065) + } + + func canOpenUrl(_ urlString: String) -> Bool { + guard let url = URL(string: urlString) else { return false } + print("\(url) \(UIApplication.shared.canOpenURL(url))") + return UIApplication.shared.canOpenURL(url) + } +} diff --git a/QuickLocation/Section/Map/Navigation/NavigationView.swift b/QuickLocation/Section/Map/Navigation/NavigationView.swift new file mode 100644 index 00000000..fe08df91 --- /dev/null +++ b/QuickLocation/Section/Map/Navigation/NavigationView.swift @@ -0,0 +1,258 @@ +// +// NavigationView.swift +// QuickLocation +// +// Created by 八条 on 2026/6/16. +// + +import UIKit +import RxSwift +import RxCocoa +#if !targetEnvironment(simulator) +import AMapNaviKit +#endif + +class NavigationView: UIView { + + var disposeBag = DisposeBag() + + private func setupRx() { + backBtn.rx.tap.subscribe(onNext: { _ in + AppRouter.shared.popOrDismiss() + }).disposed(by: disposeBag) + } + + private func setupUI() { +// addSubview(navBgView) + + #if !targetEnvironment(simulator) + addSubview(mapView) + #endif + + addSubview(navBarView) + navBarView.addSubview(backBtn) + navBarView.addSubview(navTitleLabel) + + addSubview(bottomView) + bottomView.addSubview(avatarImgView) + bottomView.addSubview(nameLab) + bottomView.addSubview(locationLab) + bottomView.addSubview(distanceLab) + bottomView.addSubview(lineView) + bottomView.addSubview(groupTitleLab) + bottomView.addSubview(groupIconView) + bottomView.addSubview(groupNameLab) + bottomView.addSubview(navigationBtn) + +// navBgView.layoutChain +// .edges(excludingEdge: .bottom) +// .height(kNaviHeight) + + navBarView.layoutChain + .edges(excludingEdge: .bottom) + .height(kNaviHeight) + + backBtn.layoutChain + .centerY(navTitleLabel) + .left(15) + .width(24).height(24) + + navTitleLabel.layoutChain + .top(kStatusBarHeight + 12) + .centerX() + + #if !targetEnvironment(simulator) + mapView.layoutChain + .top() + .edgesHorzontal() + .bottom() + #endif + + bottomView.layoutChain + .edgesHorzontal(15) + .bottom(kSafeBottomMargin + 25) + .height(190) + + avatarImgView.layoutChain + .top(15) + .left(15) + .width(30) + .height(30) + + nameLab.layoutChain + .centerY(avatarImgView) + .leftToRightOfView(avatarImgView, offset: 8) + + locationLab.layoutChain + .topToBottomOfView(avatarImgView, offset: 10) + .leftToView(avatarImgView) + .rightToLeftOfView(navigationBtn, offset: -8) + + navigationBtn.layoutChain + .right(15) + .width(83) + .height(40) + .centerY(locationLab) + + distanceLab.layoutChain + .topToBottomOfView(locationLab, offset: 2) + .leftToView(locationLab) + + lineView.layoutChain + .topToBottomOfView(distanceLab, offset: 12) + .edgesHorzontal(15) + .height(0.5) + + groupTitleLab.layoutChain + .topToBottomOfView(lineView, offset: 15) + .left(15) + + groupIconView.layoutChain + .topToBottomOfView(groupTitleLab, offset: 10) + .left(15) + .width(30) + .height(30) + + groupNameLab.layoutChain + .leftToRightOfView(groupIconView, offset: 10) + .centerY(groupIconView) + } + + func configure(member: CircleMember, groupName: String = "", groupIcon: String = "") { + avatarImgView.image = UIImage(named: "UserIcon/\(member.avatar)") + nameLab.text = member.name + locationLab.text = member.address + groupIconView.image = UIImage(named: "GroupIcon/\(groupIcon)") + groupNameLab.text = groupName + } + + // MARK: - Views + lazy var navBgView: UIImageView = { + let iv = UIImageView() + iv.image = UIImage(named: "Common/navBar_bg_2") + iv.contentMode = .scaleAspectFill + return iv + }() + + lazy var navBarView: UIView = { + let v = UIView() + v.backgroundColor = .clear + return v + }() + + lazy var backBtn: UIButton = { + let btn = UIButton(type: .custom) + btn.setImage(UIImage(named: "Common/back"), for: .normal) + btn.extendEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 30) + return btn + }() + + lazy var navTitleLabel: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 18, weight: .medium) + label.textColor = ThemeManager.shared.color.titleAuxColor + label.text = "查看位置" + return label + }() + + #if !targetEnvironment(simulator) + lazy var mapView: MAMapView = { + let mv = MAMapView() + mv.zoomLevel = 14 + mv.showsUserLocation = false + mv.showsCompass = false + mv.userTrackingMode = .none + return mv + }() + #endif + + lazy var bottomView: UIView = { + let v = UIView() + v.backgroundColor = .white + v.layer.cornerRadius = 20 +// v.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] + v.layer.shadowColor = UIColor.black.withAlphaComponent(0.1).cgColor + v.layer.shadowOffset = CGSize(width: 0, height: -2) + v.layer.shadowRadius = 10 + v.layer.shadowOpacity = 1 + return v + }() + + lazy var lineView: UIView = { + let v = UIView() + v.backgroundColor = ThemeManager.shared.color.lineColor + return v + }() + + lazy var avatarImgView: UIImageView = { + let iv = UIImageView() + iv.contentMode = .scaleAspectFill + iv.cornerRadius = 15 + iv.clipsToBounds = true + iv.backgroundColor = UIColor(hexStr: "#E0E0E0") + return iv + }() + + lazy var nameLab: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 16, weight: .semibold) + label.textColor = UIColor(hexStr: "#0F2846") + return label + }() + + lazy var locationLab: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 12) + label.textColor = UIColor(hexStr: "#333333") + return label + }() + + lazy var distanceLab: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 12) + label.textColor = UIColor(hexStr: "#999999") + return label + }() + + lazy var navigationBtn: UIButton = { + let btn = UIButton(type: .custom) + btn.setTitle("开始导航", for: .normal) + btn.setTitleColor(.white, for: .normal) + btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) + btn.backgroundColor = UIColor(hexStr: "#16B3FF") + btn.cornerRadius = 6 + return btn + }() + + lazy var groupTitleLab: UILabel = { + let label = UILabel() + label.text = "所在圈子" + label.font = .systemFont(ofSize: 16, weight: .medium) + label.textColor = .black + return label + }() + + lazy var groupIconView: UIImageView = { + let iv = UIImageView() + iv.contentMode = .scaleAspectFill + return iv + }() + + lazy var groupNameLab: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 14, weight: .medium) + label.textColor = UIColor(hexStr: "#333333") + return label + }() + + override init(frame: CGRect) { + super.init(frame: frame) + backgroundColor = .clear + setupUI() + setupRx() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/QuickLocation/UIKit/CollectionHFlowLayout.swift b/QuickLocation/UIKit/CollectionHFlowLayout.swift index b8341c8a..46cd6c77 100644 --- a/QuickLocation/UIKit/CollectionHFlowLayout.swift +++ b/QuickLocation/UIKit/CollectionHFlowLayout.swift @@ -38,7 +38,7 @@ class CollectionHFlowLayout: UICollectionViewLayout { page = index / pageTotal var x = ((itemSize.width + hSpacing) * CGFloat((index % pageTotal % colums)) + sectionInset.left) - x = x + CGFloat(page) * UIScreen.main.bounds.size.width + x = x + CGFloat(page) * (collectionView?.bounds.width ?? UIScreen.main.bounds.width) let y = (itemSize.height + vSpacing) * CGFloat((index % pageTotal / colums)) + sectionInset.top attributes.frame = CGRect(origin: CGPoint(x: x, y: y), size: itemSize) attributesArr.append(attributes) @@ -65,6 +65,6 @@ class CollectionHFlowLayout: UICollectionViewLayout { override var collectionViewContentSize: CGSize { var height = itemSize.height * CGFloat(rows) height = height + CGFloat(rows - 1) * vSpacing + sectionInset.top + sectionInset.bottom - return CGSize(width: CGFloat(page + 1) * kScreenWidth, height: height) + return CGSize(width: CGFloat(page + 1) * (collectionView?.bounds.width ?? UIScreen.main.bounds.width), height: height) } }