From 2cc5eeda48f6e9c7066a76286852688d8ba02fff Mon Sep 17 00:00:00 2001 From: hikui Date: Wed, 9 Apr 2014 22:17:41 +0800 Subject: [PATCH] init --- .gitignore | 30 ++ MHGJavascriptCore.xcodeproj/project.pbxproj | 465 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../AppIcon.appiconset/Contents.json | 23 + .../LaunchImage.launchimage/Contents.json | 23 + MHGJavascriptCore/MHGAppDelegate.h | 15 + MHGJavascriptCore/MHGAppDelegate.m | 64 +++ MHGJavascriptCore/MHGJavascriptBridge.h | 23 + MHGJavascriptCore/MHGJavascriptBridge.js | 24 + MHGJavascriptCore/MHGJavascriptBridge.m | 153 ++++++ .../MHGJavascriptCore-Info.plist | 38 ++ .../MHGJavascriptCore-Prefix.pch | 16 + MHGJavascriptCore/en.lproj/InfoPlist.strings | 2 + MHGJavascriptCore/main.m | 18 + .../MHGJavascriptCoreTests-Info.plist | 22 + .../MHGJavascriptCoreTests.m | 34 ++ .../en.lproj/InfoPlist.strings | 2 + 17 files changed, 959 insertions(+) create mode 100644 .gitignore create mode 100644 MHGJavascriptCore.xcodeproj/project.pbxproj create mode 100644 MHGJavascriptCore.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 MHGJavascriptCore/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 MHGJavascriptCore/Images.xcassets/LaunchImage.launchimage/Contents.json create mode 100644 MHGJavascriptCore/MHGAppDelegate.h create mode 100644 MHGJavascriptCore/MHGAppDelegate.m create mode 100644 MHGJavascriptCore/MHGJavascriptBridge.h create mode 100644 MHGJavascriptCore/MHGJavascriptBridge.js create mode 100644 MHGJavascriptCore/MHGJavascriptBridge.m create mode 100644 MHGJavascriptCore/MHGJavascriptCore-Info.plist create mode 100644 MHGJavascriptCore/MHGJavascriptCore-Prefix.pch create mode 100644 MHGJavascriptCore/en.lproj/InfoPlist.strings create mode 100644 MHGJavascriptCore/main.m create mode 100644 MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist create mode 100644 MHGJavascriptCoreTests/MHGJavascriptCoreTests.m create mode 100644 MHGJavascriptCoreTests/en.lproj/InfoPlist.strings diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6484958 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Created by http://www.gitignore.io + +### Xcode ### +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +profile +*.moved-aside +DerivedData +*.hmap +*.ipa + + + +### Objective-C ### +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control? +# +# Pods/ \ No newline at end of file diff --git a/MHGJavascriptCore.xcodeproj/project.pbxproj b/MHGJavascriptCore.xcodeproj/project.pbxproj new file mode 100644 index 0000000..6223150 --- /dev/null +++ b/MHGJavascriptCore.xcodeproj/project.pbxproj @@ -0,0 +1,465 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + A463416118F5735E00B0284E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463416018F5735E00B0284E /* Foundation.framework */; }; + A463416318F5735E00B0284E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463416218F5735E00B0284E /* CoreGraphics.framework */; }; + A463416518F5735E00B0284E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463416418F5735E00B0284E /* UIKit.framework */; }; + A463416B18F5735E00B0284E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A463416918F5735E00B0284E /* InfoPlist.strings */; }; + A463416D18F5735E00B0284E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A463416C18F5735E00B0284E /* main.m */; }; + A463417118F5735E00B0284E /* MHGAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A463417018F5735E00B0284E /* MHGAppDelegate.m */; }; + A463417318F5735E00B0284E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A463417218F5735E00B0284E /* Images.xcassets */; }; + A463417A18F5735E00B0284E /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463417918F5735E00B0284E /* XCTest.framework */; }; + A463417B18F5735E00B0284E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463416018F5735E00B0284E /* Foundation.framework */; }; + A463417C18F5735E00B0284E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A463416418F5735E00B0284E /* UIKit.framework */; }; + A463418418F5735E00B0284E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A463418218F5735E00B0284E /* InfoPlist.strings */; }; + A463418618F5735E00B0284E /* MHGJavascriptCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A463418518F5735E00B0284E /* MHGJavascriptCoreTests.m */; }; + A463419118F5740200B0284E /* MHGJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = A463419018F5740200B0284E /* MHGJavascriptBridge.m */; }; + A463419318F58BE200B0284E /* MHGJavascriptBridge.js in Sources */ = {isa = PBXBuildFile; fileRef = A463419218F58BE200B0284E /* MHGJavascriptBridge.js */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + A463417D18F5735E00B0284E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A463415518F5735E00B0284E /* Project object */; + proxyType = 1; + remoteGlobalIDString = A463415C18F5735E00B0284E; + remoteInfo = MHGJavascriptCore; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + A463415D18F5735E00B0284E /* MHGJavascriptCore.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MHGJavascriptCore.app; sourceTree = BUILT_PRODUCTS_DIR; }; + A463416018F5735E00B0284E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + A463416218F5735E00B0284E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + A463416418F5735E00B0284E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + A463416818F5735E00B0284E /* MHGJavascriptCore-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MHGJavascriptCore-Info.plist"; sourceTree = ""; }; + A463416A18F5735E00B0284E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + A463416C18F5735E00B0284E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + A463416E18F5735E00B0284E /* MHGJavascriptCore-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MHGJavascriptCore-Prefix.pch"; sourceTree = ""; }; + A463416F18F5735E00B0284E /* MHGAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MHGAppDelegate.h; sourceTree = ""; }; + A463417018F5735E00B0284E /* MHGAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MHGAppDelegate.m; sourceTree = ""; }; + A463417218F5735E00B0284E /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + A463417818F5735E00B0284E /* MHGJavascriptCoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MHGJavascriptCoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + A463417918F5735E00B0284E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + A463418118F5735E00B0284E /* MHGJavascriptCoreTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MHGJavascriptCoreTests-Info.plist"; sourceTree = ""; }; + A463418318F5735E00B0284E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + A463418518F5735E00B0284E /* MHGJavascriptCoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MHGJavascriptCoreTests.m; sourceTree = ""; }; + A463418F18F5740200B0284E /* MHGJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHGJavascriptBridge.h; sourceTree = ""; }; + A463419018F5740200B0284E /* MHGJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHGJavascriptBridge.m; sourceTree = ""; }; + A463419218F58BE200B0284E /* MHGJavascriptBridge.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = MHGJavascriptBridge.js; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + A463415A18F5735E00B0284E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A463416318F5735E00B0284E /* CoreGraphics.framework in Frameworks */, + A463416518F5735E00B0284E /* UIKit.framework in Frameworks */, + A463416118F5735E00B0284E /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + A463417518F5735E00B0284E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A463417A18F5735E00B0284E /* XCTest.framework in Frameworks */, + A463417C18F5735E00B0284E /* UIKit.framework in Frameworks */, + A463417B18F5735E00B0284E /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + A463415418F5735E00B0284E = { + isa = PBXGroup; + children = ( + A463416618F5735E00B0284E /* MHGJavascriptCore */, + A463417F18F5735E00B0284E /* MHGJavascriptCoreTests */, + A463415F18F5735E00B0284E /* Frameworks */, + A463415E18F5735E00B0284E /* Products */, + ); + sourceTree = ""; + }; + A463415E18F5735E00B0284E /* Products */ = { + isa = PBXGroup; + children = ( + A463415D18F5735E00B0284E /* MHGJavascriptCore.app */, + A463417818F5735E00B0284E /* MHGJavascriptCoreTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + A463415F18F5735E00B0284E /* Frameworks */ = { + isa = PBXGroup; + children = ( + A463416018F5735E00B0284E /* Foundation.framework */, + A463416218F5735E00B0284E /* CoreGraphics.framework */, + A463416418F5735E00B0284E /* UIKit.framework */, + A463417918F5735E00B0284E /* XCTest.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + A463416618F5735E00B0284E /* MHGJavascriptCore */ = { + isa = PBXGroup; + children = ( + A463416F18F5735E00B0284E /* MHGAppDelegate.h */, + A463417018F5735E00B0284E /* MHGAppDelegate.m */, + A463417218F5735E00B0284E /* Images.xcassets */, + A463416718F5735E00B0284E /* Supporting Files */, + A463418F18F5740200B0284E /* MHGJavascriptBridge.h */, + A463419018F5740200B0284E /* MHGJavascriptBridge.m */, + A463419218F58BE200B0284E /* MHGJavascriptBridge.js */, + ); + path = MHGJavascriptCore; + sourceTree = ""; + }; + A463416718F5735E00B0284E /* Supporting Files */ = { + isa = PBXGroup; + children = ( + A463416818F5735E00B0284E /* MHGJavascriptCore-Info.plist */, + A463416918F5735E00B0284E /* InfoPlist.strings */, + A463416C18F5735E00B0284E /* main.m */, + A463416E18F5735E00B0284E /* MHGJavascriptCore-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + A463417F18F5735E00B0284E /* MHGJavascriptCoreTests */ = { + isa = PBXGroup; + children = ( + A463418518F5735E00B0284E /* MHGJavascriptCoreTests.m */, + A463418018F5735E00B0284E /* Supporting Files */, + ); + path = MHGJavascriptCoreTests; + sourceTree = ""; + }; + A463418018F5735E00B0284E /* Supporting Files */ = { + isa = PBXGroup; + children = ( + A463418118F5735E00B0284E /* MHGJavascriptCoreTests-Info.plist */, + A463418218F5735E00B0284E /* InfoPlist.strings */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + A463415C18F5735E00B0284E /* MHGJavascriptCore */ = { + isa = PBXNativeTarget; + buildConfigurationList = A463418918F5735F00B0284E /* Build configuration list for PBXNativeTarget "MHGJavascriptCore" */; + buildPhases = ( + A463415918F5735E00B0284E /* Sources */, + A463415A18F5735E00B0284E /* Frameworks */, + A463415B18F5735E00B0284E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MHGJavascriptCore; + productName = MHGJavascriptCore; + productReference = A463415D18F5735E00B0284E /* MHGJavascriptCore.app */; + productType = "com.apple.product-type.application"; + }; + A463417718F5735E00B0284E /* MHGJavascriptCoreTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = A463418C18F5735F00B0284E /* Build configuration list for PBXNativeTarget "MHGJavascriptCoreTests" */; + buildPhases = ( + A463417418F5735E00B0284E /* Sources */, + A463417518F5735E00B0284E /* Frameworks */, + A463417618F5735E00B0284E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + A463417E18F5735E00B0284E /* PBXTargetDependency */, + ); + name = MHGJavascriptCoreTests; + productName = MHGJavascriptCoreTests; + productReference = A463417818F5735E00B0284E /* MHGJavascriptCoreTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + A463415518F5735E00B0284E /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = MHG; + LastUpgradeCheck = 0510; + ORGANIZATIONNAME = Hokuang; + TargetAttributes = { + A463417718F5735E00B0284E = { + TestTargetID = A463415C18F5735E00B0284E; + }; + }; + }; + buildConfigurationList = A463415818F5735E00B0284E /* Build configuration list for PBXProject "MHGJavascriptCore" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = A463415418F5735E00B0284E; + productRefGroup = A463415E18F5735E00B0284E /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + A463415C18F5735E00B0284E /* MHGJavascriptCore */, + A463417718F5735E00B0284E /* MHGJavascriptCoreTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + A463415B18F5735E00B0284E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A463416B18F5735E00B0284E /* InfoPlist.strings in Resources */, + A463417318F5735E00B0284E /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + A463417618F5735E00B0284E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A463418418F5735E00B0284E /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + A463415918F5735E00B0284E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A463419118F5740200B0284E /* MHGJavascriptBridge.m in Sources */, + A463419318F58BE200B0284E /* MHGJavascriptBridge.js in Sources */, + A463416D18F5735E00B0284E /* main.m in Sources */, + A463417118F5735E00B0284E /* MHGAppDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + A463417418F5735E00B0284E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A463418618F5735E00B0284E /* MHGJavascriptCoreTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + A463417E18F5735E00B0284E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = A463415C18F5735E00B0284E /* MHGJavascriptCore */; + targetProxy = A463417D18F5735E00B0284E /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + A463416918F5735E00B0284E /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + A463416A18F5735E00B0284E /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + A463418218F5735E00B0284E /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + A463418318F5735E00B0284E /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + A463418718F5735F00B0284E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + A463418818F5735F00B0284E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + A463418A18F5735F00B0284E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "MHGJavascriptCore/MHGJavascriptCore-Prefix.pch"; + INFOPLIST_FILE = "MHGJavascriptCore/MHGJavascriptCore-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + A463418B18F5735F00B0284E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "MHGJavascriptCore/MHGJavascriptCore-Prefix.pch"; + INFOPLIST_FILE = "MHGJavascriptCore/MHGJavascriptCore-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; + A463418D18F5735F00B0284E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MHGJavascriptCore.app/MHGJavascriptCore"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "MHGJavascriptCore/MHGJavascriptCore-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; + WRAPPER_EXTENSION = xctest; + }; + name = Debug; + }; + A463418E18F5735F00B0284E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MHGJavascriptCore.app/MHGJavascriptCore"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "MHGJavascriptCore/MHGJavascriptCore-Prefix.pch"; + INFOPLIST_FILE = "MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; + WRAPPER_EXTENSION = xctest; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + A463415818F5735E00B0284E /* Build configuration list for PBXProject "MHGJavascriptCore" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A463418718F5735F00B0284E /* Debug */, + A463418818F5735F00B0284E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A463418918F5735F00B0284E /* Build configuration list for PBXNativeTarget "MHGJavascriptCore" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A463418A18F5735F00B0284E /* Debug */, + A463418B18F5735F00B0284E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A463418C18F5735F00B0284E /* Build configuration list for PBXNativeTarget "MHGJavascriptCoreTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A463418D18F5735F00B0284E /* Debug */, + A463418E18F5735F00B0284E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = A463415518F5735E00B0284E /* Project object */; +} diff --git a/MHGJavascriptCore.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MHGJavascriptCore.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..0aadc6e --- /dev/null +++ b/MHGJavascriptCore.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MHGJavascriptCore/Images.xcassets/AppIcon.appiconset/Contents.json b/MHGJavascriptCore/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..a396706 --- /dev/null +++ b/MHGJavascriptCore/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/MHGJavascriptCore/Images.xcassets/LaunchImage.launchimage/Contents.json b/MHGJavascriptCore/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..c79ebd3 --- /dev/null +++ b/MHGJavascriptCore/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "subtype" : "retina4", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/MHGJavascriptCore/MHGAppDelegate.h b/MHGJavascriptCore/MHGAppDelegate.h new file mode 100644 index 0000000..d38c3bf --- /dev/null +++ b/MHGJavascriptCore/MHGAppDelegate.h @@ -0,0 +1,15 @@ +// +// MHGAppDelegate.h +// MHGJavascriptCore +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import + +@interface MHGAppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end diff --git a/MHGJavascriptCore/MHGAppDelegate.m b/MHGJavascriptCore/MHGAppDelegate.m new file mode 100644 index 0000000..789e4cb --- /dev/null +++ b/MHGJavascriptCore/MHGAppDelegate.m @@ -0,0 +1,64 @@ +// +// MHGAppDelegate.m +// MHGJavascriptCore +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import "MHGAppDelegate.h" +#import "MHGJavascriptBridge.h" + +@implementation MHGAppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + + MHGJavascriptBridge *bridge = [[MHGJavascriptBridge alloc]init]; + + MHGNativeCodeBlock b = ^(NSArray *params){ + NSLog(@"%@",params); + }; + + bridge.nativeBlocks[@"hahaha"] = [b copy]; + + NSURL *url = [NSURL URLWithString:@"mhgjavascriptbridge://mhgjavascriptbridge.herkuang.info/call_native_block/hahaha/?params=%5B1%2C2%2C3%2C4%2C5%2C%7B%22aaa%22%3A%22dddd%22%7D%5D"]; + NSURLRequest *req = [[NSURLRequest alloc]initWithURL:url]; + + [bridge interceptRequest:req]; + + // Override point for customization after application launch. + self.window.backgroundColor = [UIColor whiteColor]; + [self.window makeKeyAndVisible]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // 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. + // 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. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // 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. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // 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. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // 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. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/MHGJavascriptCore/MHGJavascriptBridge.h b/MHGJavascriptCore/MHGJavascriptBridge.h new file mode 100644 index 0000000..f558f38 --- /dev/null +++ b/MHGJavascriptCore/MHGJavascriptBridge.h @@ -0,0 +1,23 @@ +// +// MHGJavascirptCore.h +// MHGJavascriptCore +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import + +typedef void(^MHGNativeCodeBlock)(NSArray *); + +@interface MHGJavascriptBridge : NSObject + +@property (nonatomic, unsafe_unretained) UIWebView *webView; + +@property (nonatomic, strong) NSMutableDictionary *nativeBlocks; + +- (BOOL)interceptRequest:(NSURLRequest *)request; + +- (NSString *)callJavascriptFunction:(NSString *)functionName withParams:(NSArray *)params; + +@end diff --git a/MHGJavascriptCore/MHGJavascriptBridge.js b/MHGJavascriptCore/MHGJavascriptBridge.js new file mode 100644 index 0000000..e10cd0e --- /dev/null +++ b/MHGJavascriptCore/MHGJavascriptBridge.js @@ -0,0 +1,24 @@ +var MHGJavascriptBridge = (function(){ + var scheme = "mhgjavascriptbridge"; + var host = "mhgjavascriptbridge.herkuang.info"; + var action = "call_native_block"; + var makeURL = function(funcName, arguments) { + var URL = scheme+"://"+host+"/"+action+"/"+funcName+"/"; + var argsArray = Array.prototype.slice.call(arguments); + var argsString = encodeURIComponent(JSON.stringify(argsArray)); + URL += "?params="+argsString; + return URL; + }; + + return { + callNativeBlock: function(funcName, arguments) { + return makeURL(funcName, arguments); + } + }; + +})(); + + +var test = MHGJavascriptBridge.callNativeBlock("hahaha",[1,2,3,4,5,{"aaa":"dddd"}]); + +console.log(test); diff --git a/MHGJavascriptCore/MHGJavascriptBridge.m b/MHGJavascriptCore/MHGJavascriptBridge.m new file mode 100644 index 0000000..e3d3390 --- /dev/null +++ b/MHGJavascriptCore/MHGJavascriptBridge.m @@ -0,0 +1,153 @@ +// +// MHGJavascirptCore.m +// MHGJavascriptCore +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import "MHGJavascriptBridge.h" + +@interface MHGJavascripBridgeUtility : NSObject + ++ (NSDictionary *)dictionaryWithURLArgumentsString:(NSString *)args; ++ (NSString *)URLArgumentsStringFromDictionary:(NSDictionary *)dict; + ++ (NSString *)stringByURLEncoding:(NSString *)str; ++ (NSString *)stringByURLDecoding:(NSString *)str; + +@end + +@implementation MHGJavascripBridgeUtility + ++ (NSDictionary *)dictionaryWithURLArgumentsString:(NSString *)args +{ + NSMutableDictionary *ret = [NSMutableDictionary dictionary]; + NSArray *components = [args componentsSeparatedByString:@"&"]; + [components enumerateObjectsUsingBlock:^(NSString *component, NSUInteger idx, BOOL *stop) { + if (component.length == 0) { + return; + } + NSRange pos = [component rangeOfString:@"="]; + NSString *key; + NSString *val; + if (pos.location == NSNotFound) { + key = [self stringByURLDecoding:component]; + val = @""; + } else { + key = [self stringByURLDecoding:[component substringToIndex:pos.location]]; + val = [self stringByURLDecoding:[component substringFromIndex:pos.location + pos.length]]; + if (!key) key = @""; + if (!val) val = @""; + [ret setObject:val forKey:key]; + } + }]; + return ret; +} + ++ (NSString *)URLArgumentsStringFromDictionary:(NSDictionary *)dict +{ + __block NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:dict.count]; + [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + NSString *encodedKey = [self stringByURLEncoding:key]; + NSString *value = [dict objectForKey:key]; + NSString *encodedValue = [self stringByURLEncoding:[value description]]; + NSString *kvPair = [NSString stringWithFormat:@"%@=%@", encodedKey, encodedValue]; + [arguments addObject:kvPair]; + }]; + return [arguments componentsJoinedByString:@"&"]; +} + ++ (NSString *)stringByURLEncoding:(NSString *)str +{ + NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)str,NULL, + (CFStringRef)@";/?:@&=$+{}<>,",kCFStringEncodingUTF8)); + return result; +} + ++ (NSString *)stringByURLDecoding:(NSString *)str +{ + NSMutableString *outputStr = [NSMutableString stringWithString:str]; + [outputStr replaceOccurrencesOfString:@"+" + withString:@" " + options:NSLiteralSearch + range:NSMakeRange(0, [outputStr length])]; + + return [outputStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; +} + +@end + +@implementation MHGJavascriptBridge + +- (id)init +{ + self = [super init]; + if (self) { + _nativeBlocks = [[NSMutableDictionary alloc]init]; + } + return self; +} + +- (BOOL)interceptRequest:(NSURLRequest *)request +{ + // 格式:mhgjavascriptbridge://call_native_block/blockName?params=[1,2,{"xx":"yy"},"mmm"] + + static NSString *scheme = @"mhgjavascriptbridge"; + NSURL *url = request.URL; + if (![url.scheme isEqualToString:scheme]) { + return NO; + } + + + NSArray *pathComponents = url.pathComponents; + if (![pathComponents[1] isEqualToString:@"call_native_block"]) { + return NO; + } + + NSString *blockName = pathComponents[2]; + MHGNativeCodeBlock block = self.nativeBlocks[blockName]; + if (block == NULL) { + return NO; + } + NSString *queryString = [MHGJavascripBridgeUtility stringByURLDecoding:url.query]; + queryString = [queryString substringFromIndex:7]; + + if (queryString) { + NSArray *nativeParams = [NSJSONSerialization JSONObjectWithData:[queryString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; + if (nativeParams == nil) { + return NO; + } + block(nativeParams); + }else{ + block(nil); + } + + return YES; +} + +- (NSString *)callJavascriptFunction:(NSString *)functionName withParams:(NSArray *)params +{ + NSMutableString *jsParamString = [[NSMutableString alloc]init]; + + __block BOOL shouldContinue = YES; + [params enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + NSData *JSONData = [NSJSONSerialization dataWithJSONObject:obj options:0 error:nil]; + NSString *JSONString = [[NSString alloc]initWithData:JSONData encoding:NSUTF8StringEncoding]; + if (JSONString == nil) { + *stop = YES; + shouldContinue = NO; + } + [jsParamString appendString:JSONString]; + if (idx != params.count-1) { + [jsParamString appendString:@","]; + } + }]; + if (!shouldContinue) { + return nil; + } + NSString *call = [NSString stringWithFormat:@"%@(%@)",functionName,jsParamString]; + return [self.webView stringByEvaluatingJavaScriptFromString:call]; +} + +@end diff --git a/MHGJavascriptCore/MHGJavascriptCore-Info.plist b/MHGJavascriptCore/MHGJavascriptCore-Info.plist new file mode 100644 index 0000000..2f76087 --- /dev/null +++ b/MHGJavascriptCore/MHGJavascriptCore-Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + info.herkuang.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/MHGJavascriptCore/MHGJavascriptCore-Prefix.pch b/MHGJavascriptCore/MHGJavascriptCore-Prefix.pch new file mode 100644 index 0000000..743435c --- /dev/null +++ b/MHGJavascriptCore/MHGJavascriptCore-Prefix.pch @@ -0,0 +1,16 @@ +// +// Prefix header +// +// The contents of this file are implicitly included at the beginning of every source file. +// + +#import + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/MHGJavascriptCore/en.lproj/InfoPlist.strings b/MHGJavascriptCore/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/MHGJavascriptCore/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/MHGJavascriptCore/main.m b/MHGJavascriptCore/main.m new file mode 100644 index 0000000..40fa9ff --- /dev/null +++ b/MHGJavascriptCore/main.m @@ -0,0 +1,18 @@ +// +// main.m +// MHGJavascriptCore +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import + +#import "MHGAppDelegate.h" + +int main(int argc, char * argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([MHGAppDelegate class])); + } +} diff --git a/MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist b/MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist new file mode 100644 index 0000000..1488172 --- /dev/null +++ b/MHGJavascriptCoreTests/MHGJavascriptCoreTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + info.herkuang.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/MHGJavascriptCoreTests/MHGJavascriptCoreTests.m b/MHGJavascriptCoreTests/MHGJavascriptCoreTests.m new file mode 100644 index 0000000..6a3c838 --- /dev/null +++ b/MHGJavascriptCoreTests/MHGJavascriptCoreTests.m @@ -0,0 +1,34 @@ +// +// MHGJavascriptCoreTests.m +// MHGJavascriptCoreTests +// +// Created by 缪和光 on 9/04/2014. +// Copyright (c) 2014 Hokuang. All rights reserved. +// + +#import + +@interface MHGJavascriptCoreTests : XCTestCase + +@end + +@implementation MHGJavascriptCoreTests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample +{ + XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); +} + +@end diff --git a/MHGJavascriptCoreTests/en.lproj/InfoPlist.strings b/MHGJavascriptCoreTests/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/MHGJavascriptCoreTests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ +