├── .gitignore ├── LICENSE ├── README.md ├── hookViewId.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── xiulian.yin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── xiulian.yin.xcuserdatad │ └── xcschemes │ ├── hookViewId.xcscheme │ └── xcschememanagement.plist ├── hookViewId ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── UIResponder+UIAutoTest.h ├── UIResponder+UIAutoTest.m ├── UIView+UIAutoTest.h ├── UIView+UIAutoTest.m ├── ViewController.h ├── ViewController.m └── main.m ├── hookViewIdTests ├── Info.plist └── hookViewIdTests.m └── hookViewIdUITests ├── Info.plist └── hookViewIdUITests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | # Normal 20 | .project 21 | .settings 22 | node_modules/ 23 | logs/ 24 | Carthage/ 25 | Cartfile.resolved 26 | UserInterfaceState.xcuserstate 27 | *.sw* 28 | *.un~ 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT LICENSE 2 | 3 | Copyright (c) 2017 Alibaba Group Holding Limited and other contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iosHookViewId 2 | 3 | --- 4 | 5 | A solution for ios hook view id(给iOS应用自动生成控件id) 6 | 7 | # 特别说明 8 | 本思路来源于yulingtianxia的博客 http://yulingtianxia.com/blog/2016/03/28/Add-UITest-Label-for-UIAutomation/ 9 | 后期得知作者已将源码开源,地址如下,大家也可以直接引用源码: 10 | https://github.com/yulingtianxia/TBUIAutoTest 11 | 12 | ps: 感谢原作者的分享及开源 13 | 14 | # 使用说明 15 | 16 | 将如下四个文件拖进iOS项目目录下并参与编译即可生效(利用了OC的category特性) 17 | 18 | ```objc 19 | iosHookViewId/hookViewId/UIResponder+UIAutoTest.h 20 | iosHookViewId/hookViewId/UIResponder+UIAutoTest.m 21 | iosHookViewId/hookViewId/UIView+UIAutoTest.h 22 | iosHookViewId/hookViewId/UIView+UIAutoTest.m 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /hookViewId.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D5FE32241DFC057500562EB4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32231DFC057500562EB4 /* main.m */; }; 11 | D5FE32271DFC057500562EB4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32261DFC057500562EB4 /* AppDelegate.m */; }; 12 | D5FE322A1DFC057500562EB4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32291DFC057500562EB4 /* ViewController.m */; }; 13 | D5FE322D1DFC057500562EB4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5FE322B1DFC057500562EB4 /* Main.storyboard */; }; 14 | D5FE322F1DFC057500562EB4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D5FE322E1DFC057500562EB4 /* Assets.xcassets */; }; 15 | D5FE32321DFC057500562EB4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5FE32301DFC057500562EB4 /* LaunchScreen.storyboard */; }; 16 | D5FE323D1DFC057600562EB4 /* hookViewIdTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE323C1DFC057600562EB4 /* hookViewIdTests.m */; }; 17 | D5FE32481DFC057600562EB4 /* hookViewIdUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32471DFC057600562EB4 /* hookViewIdUITests.m */; }; 18 | D5FE325A1DFC059500562EB4 /* UIResponder+UIAutoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32571DFC059500562EB4 /* UIResponder+UIAutoTest.m */; }; 19 | D5FE325B1DFC059500562EB4 /* UIView+UIAutoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D5FE32591DFC059500562EB4 /* UIView+UIAutoTest.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | D5FE32391DFC057600562EB4 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = D5FE32171DFC057500562EB4 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = D5FE321E1DFC057500562EB4; 28 | remoteInfo = hookViewId; 29 | }; 30 | D5FE32441DFC057600562EB4 /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = D5FE32171DFC057500562EB4 /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = D5FE321E1DFC057500562EB4; 35 | remoteInfo = hookViewId; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | D5FE321F1DFC057500562EB4 /* hookViewId.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = hookViewId.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | D5FE32231DFC057500562EB4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 42 | D5FE32251DFC057500562EB4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 43 | D5FE32261DFC057500562EB4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 44 | D5FE32281DFC057500562EB4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 45 | D5FE32291DFC057500562EB4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 46 | D5FE322C1DFC057500562EB4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 47 | D5FE322E1DFC057500562EB4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 48 | D5FE32311DFC057500562EB4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 49 | D5FE32331DFC057500562EB4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | D5FE32381DFC057600562EB4 /* hookViewIdTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = hookViewIdTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | D5FE323C1DFC057600562EB4 /* hookViewIdTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = hookViewIdTests.m; sourceTree = ""; }; 52 | D5FE323E1DFC057600562EB4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | D5FE32431DFC057600562EB4 /* hookViewIdUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = hookViewIdUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | D5FE32471DFC057600562EB4 /* hookViewIdUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = hookViewIdUITests.m; sourceTree = ""; }; 55 | D5FE32491DFC057600562EB4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | D5FE32561DFC059500562EB4 /* UIResponder+UIAutoTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIResponder+UIAutoTest.h"; sourceTree = ""; }; 57 | D5FE32571DFC059500562EB4 /* UIResponder+UIAutoTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIResponder+UIAutoTest.m"; sourceTree = ""; }; 58 | D5FE32581DFC059500562EB4 /* UIView+UIAutoTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+UIAutoTest.h"; sourceTree = ""; }; 59 | D5FE32591DFC059500562EB4 /* UIView+UIAutoTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+UIAutoTest.m"; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | D5FE321C1DFC057500562EB4 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | D5FE32351DFC057600562EB4 /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | D5FE32401DFC057600562EB4 /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | D5FE32161DFC057500562EB4 = { 88 | isa = PBXGroup; 89 | children = ( 90 | D5FE32211DFC057500562EB4 /* hookViewId */, 91 | D5FE323B1DFC057600562EB4 /* hookViewIdTests */, 92 | D5FE32461DFC057600562EB4 /* hookViewIdUITests */, 93 | D5FE32201DFC057500562EB4 /* Products */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | D5FE32201DFC057500562EB4 /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | D5FE321F1DFC057500562EB4 /* hookViewId.app */, 101 | D5FE32381DFC057600562EB4 /* hookViewIdTests.xctest */, 102 | D5FE32431DFC057600562EB4 /* hookViewIdUITests.xctest */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | D5FE32211DFC057500562EB4 /* hookViewId */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | D5FE32551DFC058100562EB4 /* hook */, 111 | D5FE32251DFC057500562EB4 /* AppDelegate.h */, 112 | D5FE32261DFC057500562EB4 /* AppDelegate.m */, 113 | D5FE32281DFC057500562EB4 /* ViewController.h */, 114 | D5FE32291DFC057500562EB4 /* ViewController.m */, 115 | D5FE322B1DFC057500562EB4 /* Main.storyboard */, 116 | D5FE322E1DFC057500562EB4 /* Assets.xcassets */, 117 | D5FE32301DFC057500562EB4 /* LaunchScreen.storyboard */, 118 | D5FE32331DFC057500562EB4 /* Info.plist */, 119 | D5FE32221DFC057500562EB4 /* Supporting Files */, 120 | ); 121 | path = hookViewId; 122 | sourceTree = ""; 123 | }; 124 | D5FE32221DFC057500562EB4 /* Supporting Files */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | D5FE32231DFC057500562EB4 /* main.m */, 128 | ); 129 | name = "Supporting Files"; 130 | sourceTree = ""; 131 | }; 132 | D5FE323B1DFC057600562EB4 /* hookViewIdTests */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | D5FE323C1DFC057600562EB4 /* hookViewIdTests.m */, 136 | D5FE323E1DFC057600562EB4 /* Info.plist */, 137 | ); 138 | path = hookViewIdTests; 139 | sourceTree = ""; 140 | }; 141 | D5FE32461DFC057600562EB4 /* hookViewIdUITests */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | D5FE32471DFC057600562EB4 /* hookViewIdUITests.m */, 145 | D5FE32491DFC057600562EB4 /* Info.plist */, 146 | ); 147 | path = hookViewIdUITests; 148 | sourceTree = ""; 149 | }; 150 | D5FE32551DFC058100562EB4 /* hook */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | D5FE32561DFC059500562EB4 /* UIResponder+UIAutoTest.h */, 154 | D5FE32571DFC059500562EB4 /* UIResponder+UIAutoTest.m */, 155 | D5FE32581DFC059500562EB4 /* UIView+UIAutoTest.h */, 156 | D5FE32591DFC059500562EB4 /* UIView+UIAutoTest.m */, 157 | ); 158 | name = hook; 159 | sourceTree = ""; 160 | }; 161 | /* End PBXGroup section */ 162 | 163 | /* Begin PBXNativeTarget section */ 164 | D5FE321E1DFC057500562EB4 /* hookViewId */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = D5FE324C1DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewId" */; 167 | buildPhases = ( 168 | D5FE321B1DFC057500562EB4 /* Sources */, 169 | D5FE321C1DFC057500562EB4 /* Frameworks */, 170 | D5FE321D1DFC057500562EB4 /* Resources */, 171 | ); 172 | buildRules = ( 173 | ); 174 | dependencies = ( 175 | ); 176 | name = hookViewId; 177 | productName = hookViewId; 178 | productReference = D5FE321F1DFC057500562EB4 /* hookViewId.app */; 179 | productType = "com.apple.product-type.application"; 180 | }; 181 | D5FE32371DFC057600562EB4 /* hookViewIdTests */ = { 182 | isa = PBXNativeTarget; 183 | buildConfigurationList = D5FE324F1DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewIdTests" */; 184 | buildPhases = ( 185 | D5FE32341DFC057600562EB4 /* Sources */, 186 | D5FE32351DFC057600562EB4 /* Frameworks */, 187 | D5FE32361DFC057600562EB4 /* Resources */, 188 | ); 189 | buildRules = ( 190 | ); 191 | dependencies = ( 192 | D5FE323A1DFC057600562EB4 /* PBXTargetDependency */, 193 | ); 194 | name = hookViewIdTests; 195 | productName = hookViewIdTests; 196 | productReference = D5FE32381DFC057600562EB4 /* hookViewIdTests.xctest */; 197 | productType = "com.apple.product-type.bundle.unit-test"; 198 | }; 199 | D5FE32421DFC057600562EB4 /* hookViewIdUITests */ = { 200 | isa = PBXNativeTarget; 201 | buildConfigurationList = D5FE32521DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewIdUITests" */; 202 | buildPhases = ( 203 | D5FE323F1DFC057600562EB4 /* Sources */, 204 | D5FE32401DFC057600562EB4 /* Frameworks */, 205 | D5FE32411DFC057600562EB4 /* Resources */, 206 | ); 207 | buildRules = ( 208 | ); 209 | dependencies = ( 210 | D5FE32451DFC057600562EB4 /* PBXTargetDependency */, 211 | ); 212 | name = hookViewIdUITests; 213 | productName = hookViewIdUITests; 214 | productReference = D5FE32431DFC057600562EB4 /* hookViewIdUITests.xctest */; 215 | productType = "com.apple.product-type.bundle.ui-testing"; 216 | }; 217 | /* End PBXNativeTarget section */ 218 | 219 | /* Begin PBXProject section */ 220 | D5FE32171DFC057500562EB4 /* Project object */ = { 221 | isa = PBXProject; 222 | attributes = { 223 | LastUpgradeCheck = 0810; 224 | ORGANIZATIONNAME = opensource; 225 | TargetAttributes = { 226 | D5FE321E1DFC057500562EB4 = { 227 | CreatedOnToolsVersion = 8.1; 228 | ProvisioningStyle = Automatic; 229 | }; 230 | D5FE32371DFC057600562EB4 = { 231 | CreatedOnToolsVersion = 8.1; 232 | ProvisioningStyle = Automatic; 233 | TestTargetID = D5FE321E1DFC057500562EB4; 234 | }; 235 | D5FE32421DFC057600562EB4 = { 236 | CreatedOnToolsVersion = 8.1; 237 | ProvisioningStyle = Automatic; 238 | TestTargetID = D5FE321E1DFC057500562EB4; 239 | }; 240 | }; 241 | }; 242 | buildConfigurationList = D5FE321A1DFC057500562EB4 /* Build configuration list for PBXProject "hookViewId" */; 243 | compatibilityVersion = "Xcode 3.2"; 244 | developmentRegion = English; 245 | hasScannedForEncodings = 0; 246 | knownRegions = ( 247 | en, 248 | Base, 249 | ); 250 | mainGroup = D5FE32161DFC057500562EB4; 251 | productRefGroup = D5FE32201DFC057500562EB4 /* Products */; 252 | projectDirPath = ""; 253 | projectRoot = ""; 254 | targets = ( 255 | D5FE321E1DFC057500562EB4 /* hookViewId */, 256 | D5FE32371DFC057600562EB4 /* hookViewIdTests */, 257 | D5FE32421DFC057600562EB4 /* hookViewIdUITests */, 258 | ); 259 | }; 260 | /* End PBXProject section */ 261 | 262 | /* Begin PBXResourcesBuildPhase section */ 263 | D5FE321D1DFC057500562EB4 /* Resources */ = { 264 | isa = PBXResourcesBuildPhase; 265 | buildActionMask = 2147483647; 266 | files = ( 267 | D5FE32321DFC057500562EB4 /* LaunchScreen.storyboard in Resources */, 268 | D5FE322F1DFC057500562EB4 /* Assets.xcassets in Resources */, 269 | D5FE322D1DFC057500562EB4 /* Main.storyboard in Resources */, 270 | ); 271 | runOnlyForDeploymentPostprocessing = 0; 272 | }; 273 | D5FE32361DFC057600562EB4 /* Resources */ = { 274 | isa = PBXResourcesBuildPhase; 275 | buildActionMask = 2147483647; 276 | files = ( 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | D5FE32411DFC057600562EB4 /* Resources */ = { 281 | isa = PBXResourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | /* End PBXResourcesBuildPhase section */ 288 | 289 | /* Begin PBXSourcesBuildPhase section */ 290 | D5FE321B1DFC057500562EB4 /* Sources */ = { 291 | isa = PBXSourcesBuildPhase; 292 | buildActionMask = 2147483647; 293 | files = ( 294 | D5FE322A1DFC057500562EB4 /* ViewController.m in Sources */, 295 | D5FE325A1DFC059500562EB4 /* UIResponder+UIAutoTest.m in Sources */, 296 | D5FE32271DFC057500562EB4 /* AppDelegate.m in Sources */, 297 | D5FE32241DFC057500562EB4 /* main.m in Sources */, 298 | D5FE325B1DFC059500562EB4 /* UIView+UIAutoTest.m in Sources */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | D5FE32341DFC057600562EB4 /* Sources */ = { 303 | isa = PBXSourcesBuildPhase; 304 | buildActionMask = 2147483647; 305 | files = ( 306 | D5FE323D1DFC057600562EB4 /* hookViewIdTests.m in Sources */, 307 | ); 308 | runOnlyForDeploymentPostprocessing = 0; 309 | }; 310 | D5FE323F1DFC057600562EB4 /* Sources */ = { 311 | isa = PBXSourcesBuildPhase; 312 | buildActionMask = 2147483647; 313 | files = ( 314 | D5FE32481DFC057600562EB4 /* hookViewIdUITests.m in Sources */, 315 | ); 316 | runOnlyForDeploymentPostprocessing = 0; 317 | }; 318 | /* End PBXSourcesBuildPhase section */ 319 | 320 | /* Begin PBXTargetDependency section */ 321 | D5FE323A1DFC057600562EB4 /* PBXTargetDependency */ = { 322 | isa = PBXTargetDependency; 323 | target = D5FE321E1DFC057500562EB4 /* hookViewId */; 324 | targetProxy = D5FE32391DFC057600562EB4 /* PBXContainerItemProxy */; 325 | }; 326 | D5FE32451DFC057600562EB4 /* PBXTargetDependency */ = { 327 | isa = PBXTargetDependency; 328 | target = D5FE321E1DFC057500562EB4 /* hookViewId */; 329 | targetProxy = D5FE32441DFC057600562EB4 /* PBXContainerItemProxy */; 330 | }; 331 | /* End PBXTargetDependency section */ 332 | 333 | /* Begin PBXVariantGroup section */ 334 | D5FE322B1DFC057500562EB4 /* Main.storyboard */ = { 335 | isa = PBXVariantGroup; 336 | children = ( 337 | D5FE322C1DFC057500562EB4 /* Base */, 338 | ); 339 | name = Main.storyboard; 340 | sourceTree = ""; 341 | }; 342 | D5FE32301DFC057500562EB4 /* LaunchScreen.storyboard */ = { 343 | isa = PBXVariantGroup; 344 | children = ( 345 | D5FE32311DFC057500562EB4 /* Base */, 346 | ); 347 | name = LaunchScreen.storyboard; 348 | sourceTree = ""; 349 | }; 350 | /* End PBXVariantGroup section */ 351 | 352 | /* Begin XCBuildConfiguration section */ 353 | D5FE324A1DFC057600562EB4 /* Debug */ = { 354 | isa = XCBuildConfiguration; 355 | buildSettings = { 356 | ALWAYS_SEARCH_USER_PATHS = NO; 357 | CLANG_ANALYZER_NONNULL = YES; 358 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 359 | CLANG_CXX_LIBRARY = "libc++"; 360 | CLANG_ENABLE_MODULES = YES; 361 | CLANG_ENABLE_OBJC_ARC = YES; 362 | CLANG_WARN_BOOL_CONVERSION = YES; 363 | CLANG_WARN_CONSTANT_CONVERSION = YES; 364 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 365 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 366 | CLANG_WARN_EMPTY_BODY = YES; 367 | CLANG_WARN_ENUM_CONVERSION = YES; 368 | CLANG_WARN_INFINITE_RECURSION = YES; 369 | CLANG_WARN_INT_CONVERSION = YES; 370 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 371 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 372 | CLANG_WARN_UNREACHABLE_CODE = YES; 373 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 374 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 375 | COPY_PHASE_STRIP = NO; 376 | DEBUG_INFORMATION_FORMAT = dwarf; 377 | ENABLE_STRICT_OBJC_MSGSEND = YES; 378 | ENABLE_TESTABILITY = YES; 379 | GCC_C_LANGUAGE_STANDARD = gnu99; 380 | GCC_DYNAMIC_NO_PIC = NO; 381 | GCC_NO_COMMON_BLOCKS = YES; 382 | GCC_OPTIMIZATION_LEVEL = 0; 383 | GCC_PREPROCESSOR_DEFINITIONS = ( 384 | "DEBUG=1", 385 | "$(inherited)", 386 | ); 387 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 388 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 389 | GCC_WARN_UNDECLARED_SELECTOR = YES; 390 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 391 | GCC_WARN_UNUSED_FUNCTION = YES; 392 | GCC_WARN_UNUSED_VARIABLE = YES; 393 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 394 | MTL_ENABLE_DEBUG_INFO = YES; 395 | ONLY_ACTIVE_ARCH = YES; 396 | SDKROOT = iphoneos; 397 | TARGETED_DEVICE_FAMILY = "1,2"; 398 | }; 399 | name = Debug; 400 | }; 401 | D5FE324B1DFC057600562EB4 /* Release */ = { 402 | isa = XCBuildConfiguration; 403 | buildSettings = { 404 | ALWAYS_SEARCH_USER_PATHS = NO; 405 | CLANG_ANALYZER_NONNULL = YES; 406 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 407 | CLANG_CXX_LIBRARY = "libc++"; 408 | CLANG_ENABLE_MODULES = YES; 409 | CLANG_ENABLE_OBJC_ARC = YES; 410 | CLANG_WARN_BOOL_CONVERSION = YES; 411 | CLANG_WARN_CONSTANT_CONVERSION = YES; 412 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 413 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 414 | CLANG_WARN_EMPTY_BODY = YES; 415 | CLANG_WARN_ENUM_CONVERSION = YES; 416 | CLANG_WARN_INFINITE_RECURSION = YES; 417 | CLANG_WARN_INT_CONVERSION = YES; 418 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 419 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 420 | CLANG_WARN_UNREACHABLE_CODE = YES; 421 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 422 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 423 | COPY_PHASE_STRIP = NO; 424 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 425 | ENABLE_NS_ASSERTIONS = NO; 426 | ENABLE_STRICT_OBJC_MSGSEND = YES; 427 | GCC_C_LANGUAGE_STANDARD = gnu99; 428 | GCC_NO_COMMON_BLOCKS = YES; 429 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 430 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 431 | GCC_WARN_UNDECLARED_SELECTOR = YES; 432 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 433 | GCC_WARN_UNUSED_FUNCTION = YES; 434 | GCC_WARN_UNUSED_VARIABLE = YES; 435 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 436 | MTL_ENABLE_DEBUG_INFO = NO; 437 | SDKROOT = iphoneos; 438 | TARGETED_DEVICE_FAMILY = "1,2"; 439 | VALIDATE_PRODUCT = YES; 440 | }; 441 | name = Release; 442 | }; 443 | D5FE324D1DFC057600562EB4 /* Debug */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 447 | INFOPLIST_FILE = hookViewId/Info.plist; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewId; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | }; 452 | name = Debug; 453 | }; 454 | D5FE324E1DFC057600562EB4 /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 458 | INFOPLIST_FILE = hookViewId/Info.plist; 459 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 460 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewId; 461 | PRODUCT_NAME = "$(TARGET_NAME)"; 462 | }; 463 | name = Release; 464 | }; 465 | D5FE32501DFC057600562EB4 /* Debug */ = { 466 | isa = XCBuildConfiguration; 467 | buildSettings = { 468 | BUNDLE_LOADER = "$(TEST_HOST)"; 469 | INFOPLIST_FILE = hookViewIdTests/Info.plist; 470 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 471 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewIdTests; 472 | PRODUCT_NAME = "$(TARGET_NAME)"; 473 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/hookViewId.app/hookViewId"; 474 | }; 475 | name = Debug; 476 | }; 477 | D5FE32511DFC057600562EB4 /* Release */ = { 478 | isa = XCBuildConfiguration; 479 | buildSettings = { 480 | BUNDLE_LOADER = "$(TEST_HOST)"; 481 | INFOPLIST_FILE = hookViewIdTests/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 483 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewIdTests; 484 | PRODUCT_NAME = "$(TARGET_NAME)"; 485 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/hookViewId.app/hookViewId"; 486 | }; 487 | name = Release; 488 | }; 489 | D5FE32531DFC057600562EB4 /* Debug */ = { 490 | isa = XCBuildConfiguration; 491 | buildSettings = { 492 | INFOPLIST_FILE = hookViewIdUITests/Info.plist; 493 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 494 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewIdUITests; 495 | PRODUCT_NAME = "$(TARGET_NAME)"; 496 | TEST_TARGET_NAME = hookViewId; 497 | }; 498 | name = Debug; 499 | }; 500 | D5FE32541DFC057600562EB4 /* Release */ = { 501 | isa = XCBuildConfiguration; 502 | buildSettings = { 503 | INFOPLIST_FILE = hookViewIdUITests/Info.plist; 504 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 505 | PRODUCT_BUNDLE_IDENTIFIER = opensource.hookViewIdUITests; 506 | PRODUCT_NAME = "$(TARGET_NAME)"; 507 | TEST_TARGET_NAME = hookViewId; 508 | }; 509 | name = Release; 510 | }; 511 | /* End XCBuildConfiguration section */ 512 | 513 | /* Begin XCConfigurationList section */ 514 | D5FE321A1DFC057500562EB4 /* Build configuration list for PBXProject "hookViewId" */ = { 515 | isa = XCConfigurationList; 516 | buildConfigurations = ( 517 | D5FE324A1DFC057600562EB4 /* Debug */, 518 | D5FE324B1DFC057600562EB4 /* Release */, 519 | ); 520 | defaultConfigurationIsVisible = 0; 521 | defaultConfigurationName = Release; 522 | }; 523 | D5FE324C1DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewId" */ = { 524 | isa = XCConfigurationList; 525 | buildConfigurations = ( 526 | D5FE324D1DFC057600562EB4 /* Debug */, 527 | D5FE324E1DFC057600562EB4 /* Release */, 528 | ); 529 | defaultConfigurationIsVisible = 0; 530 | }; 531 | D5FE324F1DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewIdTests" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | D5FE32501DFC057600562EB4 /* Debug */, 535 | D5FE32511DFC057600562EB4 /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | }; 539 | D5FE32521DFC057600562EB4 /* Build configuration list for PBXNativeTarget "hookViewIdUITests" */ = { 540 | isa = XCConfigurationList; 541 | buildConfigurations = ( 542 | D5FE32531DFC057600562EB4 /* Debug */, 543 | D5FE32541DFC057600562EB4 /* Release */, 544 | ); 545 | defaultConfigurationIsVisible = 0; 546 | }; 547 | /* End XCConfigurationList section */ 548 | }; 549 | rootObject = D5FE32171DFC057500562EB4 /* Project object */; 550 | } 551 | -------------------------------------------------------------------------------- /hookViewId.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /hookViewId.xcodeproj/project.xcworkspace/xcuserdata/xiulian.yin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macacajs/iosHookViewId/5978b6235593f2f3278cf6e0015ef8d4832505e1/hookViewId.xcodeproj/project.xcworkspace/xcuserdata/xiulian.yin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /hookViewId.xcodeproj/xcuserdata/xiulian.yin.xcuserdatad/xcschemes/hookViewId.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /hookViewId.xcodeproj/xcuserdata/xiulian.yin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | hookViewId.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | D5FE321E1DFC057500562EB4 16 | 17 | primary 18 | 19 | 20 | D5FE32371DFC057600562EB4 21 | 22 | primary 23 | 24 | 25 | D5FE32421DFC057600562EB4 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /hookViewId/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // hookViewId 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /hookViewId/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // hookViewId 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /hookViewId/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /hookViewId/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /hookViewId/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /hookViewId/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /hookViewId/UIResponder+UIAutoTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIResponder+UIAutoTest.h 3 | // AFWealth 4 | // 5 | // Created by Yinxl on 11/1/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIResponder (UIAutoTest) 12 | 13 | - (NSString *)findNameWithInstance:(UIView *) instance; 14 | @end 15 | -------------------------------------------------------------------------------- /hookViewId/UIResponder+UIAutoTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIResponder+UIAutoTest.m 3 | // AFWealth 4 | // 5 | // Created by Yinxl on 11/1/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import "UIResponder+UIAutoTest.h" 10 | #import 11 | 12 | @implementation UIResponder (UIAutoTest) 13 | 14 | -(NSString *)nameWithInstance:(id)instance { 15 | unsigned int numIvars = 0; 16 | NSString *key=nil; 17 | Ivar * ivars = class_copyIvarList([self class], &numIvars); 18 | for(int i = 0; i < numIvars; i++) { 19 | Ivar thisIvar = ivars[i]; 20 | const char *type = ivar_getTypeEncoding(thisIvar); 21 | NSString *stringType = [NSString stringWithCString:type encoding:NSUTF8StringEncoding]; 22 | if (![stringType hasPrefix:@"@"]) { 23 | continue; 24 | } 25 | if ((object_getIvar(self, thisIvar) == instance)) {//此处 crash 不要慌! 26 | key = [NSString stringWithUTF8String:ivar_getName(thisIvar)]; 27 | break; 28 | } 29 | } 30 | free(ivars); 31 | return key; 32 | } 33 | 34 | - (NSString *)findNameWithInstance:(UIView *) instance 35 | { 36 | id nextResponder = [self nextResponder]; 37 | NSString *name = [self nameWithInstance:instance]; 38 | if (!name) { 39 | return [nextResponder findNameWithInstance:instance]; 40 | } 41 | if ([name hasPrefix:@"_"]) { //去掉变量名的下划线前缀 42 | name = [name substringFromIndex:1]; 43 | } 44 | return name; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /hookViewId/UIView+UIAutoTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+UIAutoTest.h 3 | // AFWealth 4 | // 5 | // Created by Yinxl on 11/1/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (UIAutoTest) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /hookViewId/UIView+UIAutoTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+UIAutoTest.m 3 | // AFWealth 4 | // 5 | // Created by Yinxl on 11/1/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import "UIView+UIAutoTest.h" 10 | #import "UIResponder+UIAutoTest.h" 11 | #import 12 | #define IDTAG @"id_" 13 | 14 | @implementation UIView (UIAutoTest) 15 | 16 | 17 | + (void)load { 18 | static dispatch_once_t onceToken; 19 | dispatch_once(&onceToken, ^{ 20 | [self swizzleSelector:@selector(accessibilityIdentifier) withAnotherSelector:@selector(tb_accessibilityIdentifier)]; 21 | [self swizzleSelector:@selector(accessibilityLabel) withAnotherSelector:@selector(tb_accessibilityLabel)]; 22 | }); 23 | } 24 | 25 | + (void)swizzleSelector:(SEL)originalSelector withAnotherSelector:(SEL)swizzledSelector 26 | { 27 | Class aClass = [self class]; 28 | 29 | Method originalMethod = class_getInstanceMethod(aClass, originalSelector); 30 | Method swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector); 31 | 32 | BOOL didAddMethod = 33 | class_addMethod(aClass, 34 | originalSelector, 35 | method_getImplementation(swizzledMethod), 36 | method_getTypeEncoding(swizzledMethod)); 37 | 38 | if (didAddMethod) { 39 | class_replaceMethod(aClass, 40 | swizzledSelector, 41 | method_getImplementation(originalMethod), 42 | method_getTypeEncoding(originalMethod)); 43 | } else { 44 | method_exchangeImplementations(originalMethod, swizzledMethod); 45 | } 46 | } 47 | 48 | #pragma mark - Method Swizzling 49 | 50 | - (NSString *)tb_accessibilityIdentifier 51 | { 52 | NSString *accessibilityIdentifier = [self tb_accessibilityIdentifier]; 53 | if (accessibilityIdentifier.length > 0 && [[accessibilityIdentifier substringToIndex:3] isEqualToString:IDTAG]) { 54 | return accessibilityIdentifier; 55 | } 56 | else if ([accessibilityIdentifier isEqualToString:@"null"]) { 57 | accessibilityIdentifier = @""; 58 | } 59 | 60 | NSString *labelStr = [self.superview findNameWithInstance:self]; 61 | 62 | if (labelStr && ![labelStr isEqualToString:@""]) { 63 | labelStr = [NSString stringWithFormat:@"%@%@",IDTAG,labelStr]; 64 | } 65 | else { 66 | if ([self isKindOfClass:[UILabel class]]) {//UILabel 使用 text 67 | labelStr = [NSString stringWithFormat:@"%@%@",IDTAG,((UILabel *)self).text?:@""]; 68 | } 69 | else if ([self isKindOfClass:[UIImageView class]]) {//UIImageView 使用 image 的 imageName 70 | labelStr = [NSString stringWithFormat:@"%@%@",IDTAG,((UIImageView *)self).image.accessibilityIdentifier?:[NSString stringWithFormat:@"image%ld",(long)((UIImageView *)self).tag]]; 71 | } 72 | else if ([self isKindOfClass:[UIButton class]]) {//UIButton 使用 button 的 text 和 image 73 | labelStr = [NSString stringWithFormat:@"%@%@%@",IDTAG,((UIButton *)self).titleLabel.text?:@"",((UIButton *)self).imageView.image.accessibilityIdentifier?:@""]; 74 | } 75 | else if (accessibilityIdentifier) {// 已有 label,则在此基础上再次添加更多信息 76 | labelStr = [NSString stringWithFormat:@"%@%@",IDTAG,accessibilityIdentifier]; 77 | } 78 | if ([self isKindOfClass:[UIButton class]]) { 79 | self.accessibilityValue = [NSString stringWithFormat:@"%@%@",IDTAG,((UIButton *)self).currentBackgroundImage.accessibilityIdentifier?:@""]; 80 | } 81 | } 82 | if ([labelStr isEqualToString:IDTAG] || [labelStr isEqualToString:[NSString stringWithFormat:@"%@null",IDTAG ]]) { 83 | labelStr = @""; 84 | } 85 | [self setAccessibilityIdentifier:labelStr]; 86 | return labelStr; 87 | } 88 | 89 | - (NSString *)tb_accessibilityLabel 90 | { 91 | if ([self isKindOfClass:[UIImageView class]]) {//UIImageView 特殊处理 92 | NSString *name = [self.superview findNameWithInstance:self]; 93 | if (name) { 94 | self.accessibilityIdentifier = [NSString stringWithFormat:@"%@%@",IDTAG,name]; 95 | } 96 | else { 97 | self.accessibilityIdentifier = [NSString stringWithFormat:@"%@%@",IDTAG,((UIImageView *)self).image.accessibilityIdentifier?:[NSString stringWithFormat:@"image%ld",(long)((UIImageView *)self).tag]]; 98 | } 99 | } 100 | if ([self isKindOfClass:[UITableViewCell class]]) {//UITableViewCell 特殊处理 101 | self.accessibilityIdentifier = [NSString stringWithFormat:@"%@%@",IDTAG,((UITableViewCell *)self).reuseIdentifier]; 102 | } 103 | return [self tb_accessibilityLabel]; 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /hookViewId/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // hookViewId 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /hookViewId/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // hookViewId 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /hookViewId/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // hookViewId 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /hookViewIdTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /hookViewIdTests/hookViewIdTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // hookViewIdTests.m 3 | // hookViewIdTests 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface hookViewIdTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation hookViewIdTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /hookViewIdUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /hookViewIdUITests/hookViewIdUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // hookViewIdUITests.m 3 | // hookViewIdUITests 4 | // 5 | // Created by Yinxl on 12/10/16. 6 | // Copyright © 2016 opensource. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface hookViewIdUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation hookViewIdUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------