Skip to content

Commit e718855

Browse files
committed
初始化项目
1 parent 262a7a9 commit e718855

File tree

63 files changed

+5005
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5005
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ fastlane/test_output
6161
# https://github.com/johnno1962/injectionforxcode
6262

6363
iOSInjectionProject/
64+
65+
/.idea

JsBridge-WebViewJavascriptBridge-Sample.xcodeproj/project.pbxproj

+702
Large diffs are not rendered by default.

JsBridge-WebViewJavascriptBridge-Sample.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AppDelegate.h
3+
// JsBridge-WebViewJavascriptBridge-Sample
4+
//
5+
// Created by pengwei on 2017/10/9.
6+
// Copyright © 2017 apkfuns. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
12+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
13+
14+
@property (strong, nonatomic) UIWindow *window;
15+
16+
17+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// AppDelegate.m
3+
// JsBridge-WebViewJavascriptBridge-Sample
4+
//
5+
// Created by pengwei on 2017/10/9.
6+
// Copyright © 2017 apkfuns. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
11+
12+
@interface AppDelegate ()
13+
14+
@end
15+
16+
@implementation AppDelegate
17+
18+
19+
20+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
21+
// Override point for customization after application launch.
22+
return YES;
23+
}
24+
25+
26+
- (void)applicationWillResignActive:(UIApplication *)application {
27+
// 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.
28+
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
29+
30+
}
31+
32+
33+
- (void)applicationDidEnterBackground:(UIApplication *)application {
34+
// 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.
35+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
36+
37+
}
38+
39+
40+
- (void)applicationWillEnterForeground:(UIApplication *)application {
41+
// 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.
42+
}
43+
44+
45+
- (void)applicationDidBecomeActive:(UIApplication *)application {
46+
// 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.
47+
}
48+
49+
50+
- (void)applicationWillTerminate:(UIApplication *)application {
51+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
52+
}
53+
54+
55+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="EHf-IW-A2E">
10+
<objects>
11+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
14+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="tne-QT-ifu">
10+
<objects>
11+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14+
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23+
</objects>
24+
</scene>
25+
</scenes>
26+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSAppTransportSecurity</key>
6+
<dict>
7+
<key>NSAllowsArbitraryLoads</key>
8+
<true/>
9+
</dict>
10+
<key>CFBundleDevelopmentRegion</key>
11+
<string>en</string>
12+
<key>CFBundleExecutable</key>
13+
<string>$(EXECUTABLE_NAME)</string>
14+
<key>CFBundleIdentifier</key>
15+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
16+
<key>CFBundleInfoDictionaryVersion</key>
17+
<string>6.0</string>
18+
<key>CFBundleName</key>
19+
<string>$(PRODUCT_NAME)</string>
20+
<key>CFBundlePackageType</key>
21+
<string>APPL</string>
22+
<key>CFBundleShortVersionString</key>
23+
<string>1.0</string>
24+
<key>CFBundleVersion</key>
25+
<string>1</string>
26+
<key>LSRequiresIPhoneOS</key>
27+
<true/>
28+
<key>UILaunchStoryboardName</key>
29+
<string>LaunchScreen</string>
30+
<key>UIMainStoryboardFile</key>
31+
<string>Main</string>
32+
<key>UIRequiredDeviceCapabilities</key>
33+
<array>
34+
<string>armv7</string>
35+
</array>
36+
<key>UISupportedInterfaceOrientations</key>
37+
<array>
38+
<string>UIInterfaceOrientationPortrait</string>
39+
<string>UIInterfaceOrientationLandscapeLeft</string>
40+
<string>UIInterfaceOrientationLandscapeRight</string>
41+
</array>
42+
</dict>
43+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) {
2+
var bridge = event.bridge;
3+
window.MyBridge = {
4+
sdk: {
5+
version: function(){
6+
return 1;
7+
}
8+
},
9+
title: {
10+
setTitle: function(options) {
11+
if (options) {
12+
bridge.callHandler('JsBridge.title.setTitle', options.data, function(responseObject) {
13+
if (responseObject) {
14+
options.onSuccess()
15+
} else {
16+
options.onFailure()
17+
}
18+
})
19+
}
20+
},
21+
setNavMenu: function(options) {
22+
if (options) {
23+
bridge.callHandler('JsBridge.title.setNavMenu', options.data, function(responseObject) {
24+
if (responseObject) {
25+
options.onSuccess();
26+
options.onListener(responseObject)
27+
} else {
28+
options.onFailure();
29+
}
30+
})
31+
}
32+
}
33+
}
34+
};
35+
if (onMyBridgeReady) {
36+
onMyBridgeReady();
37+
}
38+
});
39+
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// ViewController.h
3+
// JsBridge-WebViewJavascriptBridge-Sample
4+
//
5+
// Created by pengwei on 2017/10/9.
6+
// Copyright © 2017 apkfuns. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
12+
@interface ViewController : UIViewController<UIWebViewDelegate>
13+
14+
15+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// ViewController.m
3+
// JsBridge-WebViewJavascriptBridge-Sample
4+
//
5+
// Created by pengwei on 2017/10/9.
6+
// Copyright © 2017 apkfuns. All rights reserved.
7+
//
8+
9+
#import "ViewController.h"
10+
11+
12+
@interface ViewController ()
13+
14+
@end
15+
16+
@implementation ViewController {
17+
UIWebView *webView;
18+
NSString *bridgeCore;
19+
}
20+
21+
- (void)viewDidLoad {
22+
[super viewDidLoad];
23+
CGRect bounds = self.view.bounds;
24+
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width,
25+
bounds.size.height)];
26+
webView.delegate = self;
27+
[self.view addSubview:webView];
28+
NSString *url = @"http://www.baidu.com";
29+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
30+
[webView loadRequest:request];
31+
}
32+
33+
34+
- (void)didReceiveMemoryWarning {
35+
[super didReceiveMemoryWarning];
36+
}
37+
38+
- (BOOL)webView:(UIWebView *)webView1 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
39+
return YES;
40+
}
41+
42+
- (void)webViewDidFinishLoad:(UIWebView *)webView1 {
43+
// inject JS
44+
if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof MyBridge == 'object'"] isEqualToString:@"true"]) {
45+
if (!bridgeCore) {
46+
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"JsBridgeCore" ofType:@"js"];
47+
bridgeCore = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
48+
}
49+
if (bridgeCore.length > 0) {
50+
[webView stringByEvaluatingJavaScriptFromString:bridgeCore];
51+
NSLog(@"inject js bridge from file.");
52+
}
53+
}
54+
}
55+
56+
57+
@end

0 commit comments

Comments
 (0)