├── LICENSE ├── README.md ├── WKWebViewH5ObjCDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── huangyibiao.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── huangyibiao.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── WKWebViewH5ObjCDemo.xcscheme │ └── xcschememanagement.plist ├── WKWebViewH5ObjCDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── main.m └── test.html └── WKWebViewH5ObjCDemoTests ├── Info.plist └── WKWebViewH5ObjCDemoTests.m /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 JackyHuang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WKWebViewH5ObjCDemo 2 | 3 | 学习如何使用OC实现WKWebView与H5交互,并学习其API使用 4 | 5 | 6 | #文章讲解 7 | 8 | [WKWebView与JS交互](http://www.huangyibiao.com/wkwebview-js-h5-oc/) 9 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 693BF9E01CA1469600222529 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 693BF9DF1CA1469600222529 /* main.m */; }; 11 | 693BF9E31CA1469600222529 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 693BF9E21CA1469600222529 /* AppDelegate.m */; }; 12 | 693BF9E61CA1469600222529 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 693BF9E51CA1469600222529 /* ViewController.m */; }; 13 | 693BF9E91CA1469600222529 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 693BF9E71CA1469600222529 /* Main.storyboard */; }; 14 | 693BF9EB1CA1469600222529 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 693BF9EA1CA1469600222529 /* Assets.xcassets */; }; 15 | 693BF9EE1CA1469600222529 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 693BF9EC1CA1469600222529 /* LaunchScreen.storyboard */; }; 16 | 693BF9F91CA1469600222529 /* WKWebViewH5ObjCDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 693BF9F81CA1469600222529 /* WKWebViewH5ObjCDemoTests.m */; }; 17 | 693BFA041CA1471C00222529 /* test.html in Resources */ = {isa = PBXBuildFile; fileRef = 693BFA031CA1471C00222529 /* test.html */; }; 18 | 693BFA051CA1471C00222529 /* test.html in Resources */ = {isa = PBXBuildFile; fileRef = 693BFA031CA1471C00222529 /* test.html */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 693BF9F51CA1469600222529 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 693BF9D31CA1469600222529 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 693BF9DA1CA1469600222529; 27 | remoteInfo = WKWebViewH5ObjCDemo; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 693BF9DB1CA1469600222529 /* WKWebViewH5ObjCDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WKWebViewH5ObjCDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 693BF9DF1CA1469600222529 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | 693BF9E11CA1469600222529 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | 693BF9E21CA1469600222529 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | 693BF9E41CA1469600222529 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | 693BF9E51CA1469600222529 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | 693BF9E81CA1469600222529 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 693BF9EA1CA1469600222529 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 693BF9ED1CA1469600222529 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 693BF9EF1CA1469600222529 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 693BF9F41CA1469600222529 /* WKWebViewH5ObjCDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WKWebViewH5ObjCDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 693BF9F81CA1469600222529 /* WKWebViewH5ObjCDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WKWebViewH5ObjCDemoTests.m; sourceTree = ""; }; 44 | 693BF9FA1CA1469600222529 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 693BFA031CA1471C00222529 /* test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = test.html; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | 693BF9D81CA1469600222529 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | 693BF9F11CA1469600222529 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | 693BF9D21CA1469600222529 = { 67 | isa = PBXGroup; 68 | children = ( 69 | 693BF9DD1CA1469600222529 /* WKWebViewH5ObjCDemo */, 70 | 693BF9F71CA1469600222529 /* WKWebViewH5ObjCDemoTests */, 71 | 693BF9DC1CA1469600222529 /* Products */, 72 | ); 73 | sourceTree = ""; 74 | }; 75 | 693BF9DC1CA1469600222529 /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 693BF9DB1CA1469600222529 /* WKWebViewH5ObjCDemo.app */, 79 | 693BF9F41CA1469600222529 /* WKWebViewH5ObjCDemoTests.xctest */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | 693BF9DD1CA1469600222529 /* WKWebViewH5ObjCDemo */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 693BF9E11CA1469600222529 /* AppDelegate.h */, 88 | 693BF9E21CA1469600222529 /* AppDelegate.m */, 89 | 693BF9E41CA1469600222529 /* ViewController.h */, 90 | 693BF9E51CA1469600222529 /* ViewController.m */, 91 | 693BF9E71CA1469600222529 /* Main.storyboard */, 92 | 693BF9EA1CA1469600222529 /* Assets.xcassets */, 93 | 693BF9EC1CA1469600222529 /* LaunchScreen.storyboard */, 94 | 693BF9EF1CA1469600222529 /* Info.plist */, 95 | 693BF9DE1CA1469600222529 /* Supporting Files */, 96 | 693BFA031CA1471C00222529 /* test.html */, 97 | ); 98 | path = WKWebViewH5ObjCDemo; 99 | sourceTree = ""; 100 | }; 101 | 693BF9DE1CA1469600222529 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 693BF9DF1CA1469600222529 /* main.m */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | 693BF9F71CA1469600222529 /* WKWebViewH5ObjCDemoTests */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 693BF9F81CA1469600222529 /* WKWebViewH5ObjCDemoTests.m */, 113 | 693BF9FA1CA1469600222529 /* Info.plist */, 114 | ); 115 | path = WKWebViewH5ObjCDemoTests; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | 693BF9DA1CA1469600222529 /* WKWebViewH5ObjCDemo */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = 693BF9FD1CA1469600222529 /* Build configuration list for PBXNativeTarget "WKWebViewH5ObjCDemo" */; 124 | buildPhases = ( 125 | 693BF9D71CA1469600222529 /* Sources */, 126 | 693BF9D81CA1469600222529 /* Frameworks */, 127 | 693BF9D91CA1469600222529 /* Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = WKWebViewH5ObjCDemo; 134 | productName = WKWebViewH5ObjCDemo; 135 | productReference = 693BF9DB1CA1469600222529 /* WKWebViewH5ObjCDemo.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | 693BF9F31CA1469600222529 /* WKWebViewH5ObjCDemoTests */ = { 139 | isa = PBXNativeTarget; 140 | buildConfigurationList = 693BFA001CA1469600222529 /* Build configuration list for PBXNativeTarget "WKWebViewH5ObjCDemoTests" */; 141 | buildPhases = ( 142 | 693BF9F01CA1469600222529 /* Sources */, 143 | 693BF9F11CA1469600222529 /* Frameworks */, 144 | 693BF9F21CA1469600222529 /* Resources */, 145 | ); 146 | buildRules = ( 147 | ); 148 | dependencies = ( 149 | 693BF9F61CA1469600222529 /* PBXTargetDependency */, 150 | ); 151 | name = WKWebViewH5ObjCDemoTests; 152 | productName = WKWebViewH5ObjCDemoTests; 153 | productReference = 693BF9F41CA1469600222529 /* WKWebViewH5ObjCDemoTests.xctest */; 154 | productType = "com.apple.product-type.bundle.unit-test"; 155 | }; 156 | /* End PBXNativeTarget section */ 157 | 158 | /* Begin PBXProject section */ 159 | 693BF9D31CA1469600222529 /* Project object */ = { 160 | isa = PBXProject; 161 | attributes = { 162 | LastUpgradeCheck = 0720; 163 | ORGANIZATIONNAME = huangyibiao; 164 | TargetAttributes = { 165 | 693BF9DA1CA1469600222529 = { 166 | CreatedOnToolsVersion = 7.2.1; 167 | }; 168 | 693BF9F31CA1469600222529 = { 169 | CreatedOnToolsVersion = 7.2.1; 170 | TestTargetID = 693BF9DA1CA1469600222529; 171 | }; 172 | }; 173 | }; 174 | buildConfigurationList = 693BF9D61CA1469600222529 /* Build configuration list for PBXProject "WKWebViewH5ObjCDemo" */; 175 | compatibilityVersion = "Xcode 3.2"; 176 | developmentRegion = English; 177 | hasScannedForEncodings = 0; 178 | knownRegions = ( 179 | en, 180 | Base, 181 | ); 182 | mainGroup = 693BF9D21CA1469600222529; 183 | productRefGroup = 693BF9DC1CA1469600222529 /* Products */; 184 | projectDirPath = ""; 185 | projectRoot = ""; 186 | targets = ( 187 | 693BF9DA1CA1469600222529 /* WKWebViewH5ObjCDemo */, 188 | 693BF9F31CA1469600222529 /* WKWebViewH5ObjCDemoTests */, 189 | ); 190 | }; 191 | /* End PBXProject section */ 192 | 193 | /* Begin PBXResourcesBuildPhase section */ 194 | 693BF9D91CA1469600222529 /* Resources */ = { 195 | isa = PBXResourcesBuildPhase; 196 | buildActionMask = 2147483647; 197 | files = ( 198 | 693BFA041CA1471C00222529 /* test.html in Resources */, 199 | 693BF9EE1CA1469600222529 /* LaunchScreen.storyboard in Resources */, 200 | 693BF9EB1CA1469600222529 /* Assets.xcassets in Resources */, 201 | 693BF9E91CA1469600222529 /* Main.storyboard in Resources */, 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | 693BF9F21CA1469600222529 /* Resources */ = { 206 | isa = PBXResourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | 693BFA051CA1471C00222529 /* test.html in Resources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | /* End PBXResourcesBuildPhase section */ 214 | 215 | /* Begin PBXSourcesBuildPhase section */ 216 | 693BF9D71CA1469600222529 /* Sources */ = { 217 | isa = PBXSourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | 693BF9E61CA1469600222529 /* ViewController.m in Sources */, 221 | 693BF9E31CA1469600222529 /* AppDelegate.m in Sources */, 222 | 693BF9E01CA1469600222529 /* main.m in Sources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | 693BF9F01CA1469600222529 /* Sources */ = { 227 | isa = PBXSourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 693BF9F91CA1469600222529 /* WKWebViewH5ObjCDemoTests.m in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | /* End PBXSourcesBuildPhase section */ 235 | 236 | /* Begin PBXTargetDependency section */ 237 | 693BF9F61CA1469600222529 /* PBXTargetDependency */ = { 238 | isa = PBXTargetDependency; 239 | target = 693BF9DA1CA1469600222529 /* WKWebViewH5ObjCDemo */; 240 | targetProxy = 693BF9F51CA1469600222529 /* PBXContainerItemProxy */; 241 | }; 242 | /* End PBXTargetDependency section */ 243 | 244 | /* Begin PBXVariantGroup section */ 245 | 693BF9E71CA1469600222529 /* Main.storyboard */ = { 246 | isa = PBXVariantGroup; 247 | children = ( 248 | 693BF9E81CA1469600222529 /* Base */, 249 | ); 250 | name = Main.storyboard; 251 | sourceTree = ""; 252 | }; 253 | 693BF9EC1CA1469600222529 /* LaunchScreen.storyboard */ = { 254 | isa = PBXVariantGroup; 255 | children = ( 256 | 693BF9ED1CA1469600222529 /* Base */, 257 | ); 258 | name = LaunchScreen.storyboard; 259 | sourceTree = ""; 260 | }; 261 | /* End PBXVariantGroup section */ 262 | 263 | /* Begin XCBuildConfiguration section */ 264 | 693BF9FB1CA1469600222529 /* Debug */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | ALWAYS_SEARCH_USER_PATHS = NO; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_WARN_BOOL_CONVERSION = YES; 273 | CLANG_WARN_CONSTANT_CONVERSION = YES; 274 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 275 | CLANG_WARN_EMPTY_BODY = YES; 276 | CLANG_WARN_ENUM_CONVERSION = YES; 277 | CLANG_WARN_INT_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = dwarf; 284 | ENABLE_STRICT_OBJC_MSGSEND = YES; 285 | ENABLE_TESTABILITY = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu99; 287 | GCC_DYNAMIC_NO_PIC = NO; 288 | GCC_NO_COMMON_BLOCKS = YES; 289 | GCC_OPTIMIZATION_LEVEL = 0; 290 | GCC_PREPROCESSOR_DEFINITIONS = ( 291 | "DEBUG=1", 292 | "$(inherited)", 293 | ); 294 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 295 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 296 | GCC_WARN_UNDECLARED_SELECTOR = YES; 297 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 298 | GCC_WARN_UNUSED_FUNCTION = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 301 | MTL_ENABLE_DEBUG_INFO = YES; 302 | ONLY_ACTIVE_ARCH = YES; 303 | SDKROOT = iphoneos; 304 | }; 305 | name = Debug; 306 | }; 307 | 693BF9FC1CA1469600222529 /* Release */ = { 308 | isa = XCBuildConfiguration; 309 | buildSettings = { 310 | ALWAYS_SEARCH_USER_PATHS = NO; 311 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 312 | CLANG_CXX_LIBRARY = "libc++"; 313 | CLANG_ENABLE_MODULES = YES; 314 | CLANG_ENABLE_OBJC_ARC = YES; 315 | CLANG_WARN_BOOL_CONVERSION = YES; 316 | CLANG_WARN_CONSTANT_CONVERSION = YES; 317 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 318 | CLANG_WARN_EMPTY_BODY = YES; 319 | CLANG_WARN_ENUM_CONVERSION = YES; 320 | CLANG_WARN_INT_CONVERSION = YES; 321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 322 | CLANG_WARN_UNREACHABLE_CODE = YES; 323 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 324 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 325 | COPY_PHASE_STRIP = NO; 326 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 327 | ENABLE_NS_ASSERTIONS = NO; 328 | ENABLE_STRICT_OBJC_MSGSEND = YES; 329 | GCC_C_LANGUAGE_STANDARD = gnu99; 330 | GCC_NO_COMMON_BLOCKS = YES; 331 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 332 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 333 | GCC_WARN_UNDECLARED_SELECTOR = YES; 334 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 335 | GCC_WARN_UNUSED_FUNCTION = YES; 336 | GCC_WARN_UNUSED_VARIABLE = YES; 337 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 338 | MTL_ENABLE_DEBUG_INFO = NO; 339 | SDKROOT = iphoneos; 340 | VALIDATE_PRODUCT = YES; 341 | }; 342 | name = Release; 343 | }; 344 | 693BF9FE1CA1469600222529 /* Debug */ = { 345 | isa = XCBuildConfiguration; 346 | buildSettings = { 347 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 348 | INFOPLIST_FILE = WKWebViewH5ObjCDemo/Info.plist; 349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 350 | PRODUCT_BUNDLE_IDENTIFIER = com.huangyibiao.WKWebViewH5ObjCDemo; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | }; 353 | name = Debug; 354 | }; 355 | 693BF9FF1CA1469600222529 /* Release */ = { 356 | isa = XCBuildConfiguration; 357 | buildSettings = { 358 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 359 | INFOPLIST_FILE = WKWebViewH5ObjCDemo/Info.plist; 360 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 361 | PRODUCT_BUNDLE_IDENTIFIER = com.huangyibiao.WKWebViewH5ObjCDemo; 362 | PRODUCT_NAME = "$(TARGET_NAME)"; 363 | }; 364 | name = Release; 365 | }; 366 | 693BFA011CA1469600222529 /* Debug */ = { 367 | isa = XCBuildConfiguration; 368 | buildSettings = { 369 | BUNDLE_LOADER = "$(TEST_HOST)"; 370 | INFOPLIST_FILE = WKWebViewH5ObjCDemoTests/Info.plist; 371 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 372 | PRODUCT_BUNDLE_IDENTIFIER = com.huangyibiao.WKWebViewH5ObjCDemoTests; 373 | PRODUCT_NAME = "$(TARGET_NAME)"; 374 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WKWebViewH5ObjCDemo.app/WKWebViewH5ObjCDemo"; 375 | }; 376 | name = Debug; 377 | }; 378 | 693BFA021CA1469600222529 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | BUNDLE_LOADER = "$(TEST_HOST)"; 382 | INFOPLIST_FILE = WKWebViewH5ObjCDemoTests/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 384 | PRODUCT_BUNDLE_IDENTIFIER = com.huangyibiao.WKWebViewH5ObjCDemoTests; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WKWebViewH5ObjCDemo.app/WKWebViewH5ObjCDemo"; 387 | }; 388 | name = Release; 389 | }; 390 | /* End XCBuildConfiguration section */ 391 | 392 | /* Begin XCConfigurationList section */ 393 | 693BF9D61CA1469600222529 /* Build configuration list for PBXProject "WKWebViewH5ObjCDemo" */ = { 394 | isa = XCConfigurationList; 395 | buildConfigurations = ( 396 | 693BF9FB1CA1469600222529 /* Debug */, 397 | 693BF9FC1CA1469600222529 /* Release */, 398 | ); 399 | defaultConfigurationIsVisible = 0; 400 | defaultConfigurationName = Release; 401 | }; 402 | 693BF9FD1CA1469600222529 /* Build configuration list for PBXNativeTarget "WKWebViewH5ObjCDemo" */ = { 403 | isa = XCConfigurationList; 404 | buildConfigurations = ( 405 | 693BF9FE1CA1469600222529 /* Debug */, 406 | 693BF9FF1CA1469600222529 /* Release */, 407 | ); 408 | defaultConfigurationIsVisible = 0; 409 | }; 410 | 693BFA001CA1469600222529 /* Build configuration list for PBXNativeTarget "WKWebViewH5ObjCDemoTests" */ = { 411 | isa = XCConfigurationList; 412 | buildConfigurations = ( 413 | 693BFA011CA1469600222529 /* Debug */, 414 | 693BFA021CA1469600222529 /* Release */, 415 | ); 416 | defaultConfigurationIsVisible = 0; 417 | }; 418 | /* End XCConfigurationList section */ 419 | }; 420 | rootObject = 693BF9D31CA1469600222529 /* Project object */; 421 | } 422 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/project.xcworkspace/xcuserdata/huangyibiao.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoderJackyHuang/WKWebViewH5ObjCDemo/4e7af7db6f4403283adae8c736f72cf779fbe624/WKWebViewH5ObjCDemo.xcodeproj/project.xcworkspace/xcuserdata/huangyibiao.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/xcuserdata/huangyibiao.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/xcuserdata/huangyibiao.xcuserdatad/xcschemes/WKWebViewH5ObjCDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo.xcodeproj/xcuserdata/huangyibiao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | WKWebViewH5ObjCDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 693BF9DA1CA1469600222529 16 | 17 | primary 18 | 19 | 20 | 693BF9F31CA1469600222529 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WKWebViewH5ObjCDemo 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. 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 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WKWebViewH5ObjCDemo 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. 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 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/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 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WKWebViewH5ObjCDemo 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WKWebViewH5ObjCDemo 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import 11 | 12 | @interface ViewController () 13 | 14 | @property (nonatomic, strong) WKWebView *webView; 15 | @property (nonatomic, strong) UIProgressView *progressView; 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | 24 | self.edgesForExtendedLayout = UIRectEdgeNone; 25 | self.automaticallyAdjustsScrollViewInsets = NO; 26 | 27 | WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; 28 | 29 | // 设置偏好设置 30 | config.preferences = [[WKPreferences alloc] init]; 31 | // 默认为0 32 | config.preferences.minimumFontSize = 10; 33 | // 默认认为YES 34 | config.preferences.javaScriptEnabled = YES; 35 | // 在iOS上默认为NO,表示不能自动通过窗口打开 36 | config.preferences.javaScriptCanOpenWindowsAutomatically = NO; 37 | 38 | // web内容处理池 39 | config.processPool = [[WKProcessPool alloc] init]; 40 | 41 | // 通过JS与webview内容交互 42 | config.userContentController = [[WKUserContentController alloc] init]; 43 | // 注入JS对象名称AppModel,当JS通过AppModel来调用时, 44 | // 我们可以在WKScriptMessageHandler代理中接收到 45 | [config.userContentController addScriptMessageHandler:self name:@"AppModel"]; 46 | 47 | self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds 48 | configuration:config]; 49 | NSURL *path = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"html"]; 50 | [self.webView loadRequest:[NSURLRequest requestWithURL:path]]; 51 | [self.view addSubview:self.webView]; 52 | 53 | // 导航代理 54 | self.webView.navigationDelegate = self; 55 | // 与webview UI交互代理 56 | self.webView.UIDelegate = self; 57 | 58 | // 添加KVO监听 59 | [self.webView addObserver:self 60 | forKeyPath:@"loading" 61 | options:NSKeyValueObservingOptionNew 62 | context:nil]; 63 | [self.webView addObserver:self 64 | forKeyPath:@"title" 65 | options:NSKeyValueObservingOptionNew 66 | context:nil]; 67 | [self.webView addObserver:self 68 | forKeyPath:@"estimatedProgress" 69 | options:NSKeyValueObservingOptionNew 70 | context:nil]; 71 | 72 | // 添加进入条 73 | self.progressView = [[UIProgressView alloc] init]; 74 | self.progressView.frame = self.view.bounds; 75 | [self.view addSubview:self.progressView]; 76 | self.progressView.backgroundColor = [UIColor redColor]; 77 | 78 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"后退" style:UIBarButtonItemStyleDone target:self action:@selector(goback)]; 79 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"前进" style:UIBarButtonItemStyleDone target:self action:@selector(gofarward)]; 80 | } 81 | 82 | - (void)goback { 83 | if ([self.webView canGoBack]) { 84 | [self.webView goBack]; 85 | } 86 | } 87 | 88 | - (void)gofarward { 89 | if ([self.webView canGoForward]) { 90 | [self.webView goForward]; 91 | } 92 | } 93 | 94 | #pragma mark - WKScriptMessageHandler 95 | - (void)userContentController:(WKUserContentController *)userContentController 96 | didReceiveScriptMessage:(WKScriptMessage *)message { 97 | if ([message.name isEqualToString:@"AppModel"]) { 98 | // 打印所传过来的参数,只支持NSNumber, NSString, NSDate, NSArray, 99 | // NSDictionary, and NSNull类型 100 | NSLog(@"%@", message.body); 101 | } 102 | } 103 | 104 | #pragma mark - KVO 105 | - (void)observeValueForKeyPath:(NSString *)keyPath 106 | ofObject:(id)object 107 | change:(NSDictionary *)change 108 | context:(void *)context { 109 | if ([keyPath isEqualToString:@"loading"]) { 110 | NSLog(@"loading"); 111 | } else if ([keyPath isEqualToString:@"title"]) { 112 | self.title = self.webView.title; 113 | } else if ([keyPath isEqualToString:@"estimatedProgress"]) { 114 | NSLog(@"progress: %f", self.webView.estimatedProgress); 115 | self.progressView.progress = self.webView.estimatedProgress; 116 | } 117 | 118 | // 加载完成 119 | if (!self.webView.loading) { 120 | // 手动调用JS代码 121 | // 每次页面完成都弹出来,大家可以在测试时再打开 122 | NSString *js = @"callJsAlert()"; 123 | [self.webView evaluateJavaScript:js completionHandler:^(id _Nullable response, NSError * _Nullable error) { 124 | NSLog(@"response: %@ error: %@", response, error); 125 | NSLog(@"call js alert by native"); 126 | }]; 127 | 128 | [UIView animateWithDuration:0.5 animations:^{ 129 | self.progressView.alpha = 0; 130 | }]; 131 | } 132 | } 133 | 134 | #pragma mark - WKNavigationDelegate 135 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 136 | NSString *hostname = navigationAction.request.URL.host.lowercaseString; 137 | if (navigationAction.navigationType == WKNavigationTypeLinkActivated 138 | && ![hostname containsString:@".baidu.com"]) { 139 | // 对于跨域,需要手动跳转 140 | [[UIApplication sharedApplication] openURL:navigationAction.request.URL]; 141 | 142 | // 不允许web内跳转 143 | decisionHandler(WKNavigationActionPolicyCancel); 144 | } else { 145 | self.progressView.alpha = 1.0; 146 | decisionHandler(WKNavigationActionPolicyAllow); 147 | } 148 | 149 | NSLog(@"%s", __FUNCTION__); 150 | } 151 | 152 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { 153 | decisionHandler(WKNavigationResponsePolicyAllow); 154 | NSLog(@"%s", __FUNCTION__); 155 | } 156 | 157 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { 158 | NSLog(@"%s", __FUNCTION__); 159 | } 160 | 161 | - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation { 162 | NSLog(@"%s", __FUNCTION__); 163 | } 164 | 165 | - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { 166 | NSLog(@"%s", __FUNCTION__); 167 | } 168 | 169 | - (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation { 170 | NSLog(@"%s", __FUNCTION__); 171 | } 172 | 173 | - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation { 174 | NSLog(@"%s", __FUNCTION__); 175 | } 176 | 177 | - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { 178 | 179 | } 180 | 181 | - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler { 182 | NSLog(@"%s", __FUNCTION__); 183 | completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); 184 | } 185 | 186 | - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { 187 | NSLog(@"%s", __FUNCTION__); 188 | } 189 | 190 | #pragma mark - WKUIDelegate 191 | - (void)webViewDidClose:(WKWebView *)webView { 192 | NSLog(@"%s", __FUNCTION__); 193 | } 194 | 195 | - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler { 196 | NSLog(@"%s", __FUNCTION__); 197 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"alert" message:@"JS调用alert" preferredStyle:UIAlertControllerStyleAlert]; 198 | [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 199 | completionHandler(); 200 | }]]; 201 | 202 | [self presentViewController:alert animated:YES completion:NULL]; 203 | NSLog(@"%@", message); 204 | } 205 | 206 | - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler { 207 | NSLog(@"%s", __FUNCTION__); 208 | 209 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"confirm" message:@"JS调用confirm" preferredStyle:UIAlertControllerStyleAlert]; 210 | [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 211 | completionHandler(YES); 212 | }]]; 213 | [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 214 | completionHandler(NO); 215 | }]]; 216 | [self presentViewController:alert animated:YES completion:NULL]; 217 | 218 | NSLog(@"%@", message); 219 | } 220 | 221 | - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler { 222 | NSLog(@"%s", __FUNCTION__); 223 | 224 | NSLog(@"%@", prompt); 225 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"textinput" message:@"JS调用输入框" preferredStyle:UIAlertControllerStyleAlert]; 226 | [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 227 | textField.textColor = [UIColor redColor]; 228 | }]; 229 | 230 | [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 231 | completionHandler([[alert.textFields lastObject] text]); 232 | }]]; 233 | 234 | [self presentViewController:alert animated:YES completion:NULL]; 235 | } 236 | 237 | @end 238 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WKWebViewH5ObjCDemo 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. 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 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemo/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | iOS and Js 5 | 10 | 11 | 12 | 13 | 14 |
15 |

Test how to use objective-c call js


16 |
17 |
18 |

19 |
20 |
21 |
22 |

23 |
Click me here: Jump to Baidu
24 |
25 | 26 |
27 |
28 | 29 |
30 | 31 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemoTests/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /WKWebViewH5ObjCDemoTests/WKWebViewH5ObjCDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WKWebViewH5ObjCDemoTests.m 3 | // WKWebViewH5ObjCDemoTests 4 | // 5 | // Created by huangyibiao on 16/3/22. 6 | // Copyright © 2016年 huangyibiao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WKWebViewH5ObjCDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WKWebViewH5ObjCDemoTests 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 | --------------------------------------------------------------------------------