Skip to content

Commit 0669401

Browse files
author
Jakey
committed
增加定位 与 文件浏览
1 parent ebc3c92 commit 0669401

File tree

8 files changed

+278
-11
lines changed

8 files changed

+278
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WebViewJS.xcodeproj/xcuserdata/Jakey.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

WebViewJS.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
A29B2822198F0F4400F184DE /* location.html in Resources */ = {isa = PBXBuildFile; fileRef = A29B2821198F0F4400F184DE /* location.html */; };
11+
A29B2824198F121A00F184DE /* file.html in Resources */ = {isa = PBXBuildFile; fileRef = A29B2823198F121A00F184DE /* file.html */; };
12+
A29B2826198F150E00F184DE /* phone.php in Resources */ = {isa = PBXBuildFile; fileRef = A29B2825198F150E00F184DE /* phone.php */; };
1013
A2E71E0B197F911B0055B687 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A2E71E0A197F911B0055B687 /* Foundation.framework */; };
1114
A2E71E0D197F911B0055B687 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A2E71E0C197F911B0055B687 /* CoreGraphics.framework */; };
1215
A2E71E0F197F911B0055B687 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A2E71E0E197F911B0055B687 /* UIKit.framework */; };
@@ -40,6 +43,9 @@
4043
/* End PBXContainerItemProxy section */
4144

4245
/* Begin PBXFileReference section */
46+
A29B2821198F0F4400F184DE /* location.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = location.html; sourceTree = "<group>"; };
47+
A29B2823198F121A00F184DE /* file.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = file.html; sourceTree = "<group>"; };
48+
A29B2825198F150E00F184DE /* phone.php */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.php; path = phone.php; sourceTree = "<group>"; };
4349
A2E71E07197F911B0055B687 /* WebViewJS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WebViewJS.app; sourceTree = BUILT_PRODUCTS_DIR; };
4450
A2E71E0A197F911B0055B687 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
4551
A2E71E0C197F911B0055B687 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
@@ -136,6 +142,9 @@
136142
A2E71E43197F913D0055B687 /* light_advice.png */,
137143
A2E71E44197F913D0055B687 /* light_illstration.png */,
138144
A2E71E4C197F92260055B687 /* 1.html */,
145+
A29B2821198F0F4400F184DE /* location.html */,
146+
A29B2823198F121A00F184DE /* file.html */,
147+
A29B2825198F150E00F184DE /* phone.php */,
139148
A2E71E1C197F911B0055B687 /* Images.xcassets */,
140149
A2E71E11197F911B0055B687 /* Supporting Files */,
141150
);
@@ -263,6 +272,9 @@
263272
A2E71E46197F913D0055B687 /* light_illstration.png in Resources */,
264273
A2E71E15197F911B0055B687 /* InfoPlist.strings in Resources */,
265274
A2E71E1D197F911B0055B687 /* Images.xcassets in Resources */,
275+
A29B2824198F121A00F184DE /* file.html in Resources */,
276+
A29B2826198F150E00F184DE /* phone.php in Resources */,
277+
A29B2822198F0F4400F184DE /* location.html in Resources */,
266278
A2E71E4D197F92260055B687 /* 1.html in Resources */,
267279
A2E71E45197F913D0055B687 /* light_advice.png in Resources */,
268280
);
@@ -489,6 +501,7 @@
489501
A2E71E35197F911B0055B687 /* Release */,
490502
);
491503
defaultConfigurationIsVisible = 0;
504+
defaultConfigurationName = Release;
492505
};
493506
A2E71E36197F911B0055B687 /* Build configuration list for PBXNativeTarget "WebViewJSTests" */ = {
494507
isa = XCConfigurationList;
@@ -497,6 +510,7 @@
497510
A2E71E38197F911B0055B687 /* Release */,
498511
);
499512
defaultConfigurationIsVisible = 0;
513+
defaultConfigurationName = Release;
500514
};
501515
/* End XCConfigurationList section */
502516
};

WebViewJS/ViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
- (IBAction)submitTouched:(id)sender;
2323
- (IBAction)replaceImgSrc:(id)sender;
2424
- (IBAction)fontTouched:(id)sender;
25+
- (IBAction)locationTouched:(id)sender;
26+
- (IBAction)uploadTouched:(id)sender;
27+
- (IBAction)phoneTouched:(id)sender;
2528
@end

WebViewJS/ViewController.m

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ - (void)didReceiveMemoryWarning
3030
}
3131

3232
- (IBAction)loadTouched:(id)sender {
33-
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];
34-
35-
NSURL *url = [NSURL fileURLWithPath:filePath];
36-
37-
NSURLRequest *request = [NSURLRequest requestWithURL:url];
38-
39-
[self.myWeb loadRequest:request];
33+
[self laodHtml:@"1"];
4034
}
4135

4236

@@ -105,4 +99,25 @@ - (IBAction)fontTouched:(id)sender {
10599
[self.myWeb stringByEvaluatingJavaScriptFromString:tempString2];
106100

107101
}
102+
//定位
103+
- (IBAction)locationTouched:(id)sender {
104+
[self laodHtml:@"location"];
105+
}
106+
//浏览文件
107+
- (IBAction)uploadTouched:(id)sender {
108+
[self laodHtml:@"file"];
109+
}
110+
- (IBAction)phoneTouched:(id)sender {
111+
112+
}
113+
-(void)laodHtml:(NSString*)name{
114+
NSString *filePath = [[NSBundle mainBundle]pathForResource:name ofType:@"html"];
115+
116+
NSURL *url = [NSURL fileURLWithPath:filePath];
117+
118+
NSURLRequest *request = [NSURLRequest requestWithURL:url];
119+
120+
[self.myWeb loadRequest:request];
121+
}
122+
108123
@end

WebViewJS/ViewController.xib

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
</placeholder>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1414
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="6">
15-
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
15+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
1616
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1717
<subviews>
1818
<webView contentMode="scaleToFill" id="8">
19-
<rect key="frame" x="0.0" y="0.0" width="320" height="294"/>
19+
<rect key="frame" x="0.0" y="0.0" width="320" height="285"/>
2020
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2121
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
2222
<connections>
@@ -113,10 +113,40 @@
113113
<action selector="fontTouched:" destination="-1" eventType="touchUpInside" id="MWv-cC-fgb"/>
114114
</connections>
115115
</button>
116+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Rmh-hg-3of">
117+
<rect key="frame" x="162" y="440" width="30" height="30"/>
118+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
119+
<state key="normal" title="定位">
120+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
121+
</state>
122+
<connections>
123+
<action selector="locationTouched:" destination="-1" eventType="touchUpInside" id="LAF-my-vLe"/>
124+
</connections>
125+
</button>
126+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Xgc-Wh-VQR">
127+
<rect key="frame" x="220" y="440" width="60" height="30"/>
128+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
129+
<state key="normal" title="上传图片">
130+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
131+
</state>
132+
<connections>
133+
<action selector="uploadTouched:" destination="-1" eventType="touchUpInside" id="Eb7-vW-nft"/>
134+
</connections>
135+
</button>
136+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="X3j-DJ-CMf">
137+
<rect key="frame" x="-2" y="473" width="75" height="30"/>
138+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
139+
<state key="normal" title="获取手机号">
140+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
141+
</state>
142+
<connections>
143+
<action selector="phoneTouched:" destination="-1" eventType="touchUpInside" id="3jb-li-5Fn"/>
144+
</connections>
145+
</button>
116146
</subviews>
117147
<color key="backgroundColor" white="0.75" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
118-
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
119-
<simulatedScreenMetrics key="simulatedDestinationMetrics"/>
148+
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="blackOpaque"/>
149+
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
120150
</view>
121151
</objects>
122152
</document>

WebViewJS/file.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4+
<body>
5+
<input type="file" accept="video/*;capture=camcorder">
6+
<input type="file" accept="audio/*;capture=microphone">
7+
<input type="file" accept="image/*;capture=camera">
8+
</body>
9+
</html>

WebViewJS/location.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4+
<body>
5+
<p id="demo">点击这个按钮,获得您的坐标:</p>
6+
<button onclick="getLocation()">试一下</button>
7+
<script>
8+
var x=document.getElementById("demo");
9+
function getLocation()
10+
{
11+
if (navigator.geolocation)
12+
{
13+
navigator.geolocation.getCurrentPosition(showPosition);
14+
}
15+
else{x.innerHTML="Geolocation is not supported by this browser.";}
16+
}
17+
function showPosition(position)
18+
{
19+
x.innerHTML="Latitude: " + position.coords.latitude +
20+
"<br />Longitude: " + position.coords.longitude;
21+
}
22+
</script>
23+
</body>
24+
</html>

WebViewJS/phone.php

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
3+
function getPhoneNumber()
4+
{
5+
if (isset($_SERVER['HTTP_X_NETWORK_INFO']))
6+
{
7+
$str1 = $_SERVER['HTTP_X_NETWORK_INFO'];
8+
$getstr1 = preg_replace('/(.*,)(11[d])(,.*)/i','',$str1);
9+
Return $getstr1;
10+
}
11+
elseif (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID']))
12+
{
13+
$getstr2 = $_SERVER['HTTP_X_UP_CALLING_LINE_ID'];
14+
Return $getstr2;
15+
}
16+
elseif (isset($_SERVER['HTTP_X_UP_SUBNO']))
17+
{
18+
$str3 = $_SERVER['HTTP_X_UP_SUBNO'];
19+
$getstr3 = preg_replace('/(.*)(11[d])(.*)/i','',$str3);
20+
Return $getstr3;
21+
}
22+
elseif (isset($_SERVER['DEVICEID']))
23+
{
24+
Return $_SERVER['DEVICEID'];
25+
}
26+
else
27+
{
28+
Return false;
29+
}
30+
}
31+
32+
/**
33+
* 函数名称: getHttpHeader
34+
* 函数功能: 取头信息
35+
* 输入参数: none
36+
* 函数返回值: 成功返回号码,失败返回false
37+
* 其它说明: 说明
38+
*/
39+
function getHttpHeader()
40+
{
41+
$str = '';
42+
foreach ($_SERVER as $key=>$val)
43+
{
44+
$gstr = str_replace("&","&",$val);
45+
$str.= "$key -> ".$gstr." ";
46+
}
47+
Return $str;
48+
}
49+
50+
/**
51+
* 函数名称: getUA
52+
* 函数功能: 取UA
53+
* 输入参数: none
54+
* 函数返回值: 成功返回号码,失败返回false
55+
* 其它说明: 说明
56+
*/
57+
function getUA()
58+
{
59+
if (isset($_SERVER['HTTP_USER_AGENT']))
60+
{
61+
Return $_SERVER['HTTP_USER_AGENT'];
62+
}
63+
else
64+
{
65+
Return false;
66+
}
67+
}
68+
69+
/**
70+
* 函数名称: getPhoneType
71+
* 函数功能: 取得手机类型
72+
* 输入参数: none
73+
* 函数返回值: 成功返回string,失败返回false
74+
* 其它说明: 说明
75+
*/
76+
function getPhoneType()
77+
{
78+
$ua = $this->getUA();
79+
if($ua!=false)
80+
{
81+
$str = explode(' ',$ua);
82+
Return $str[0];
83+
}
84+
else
85+
{
86+
Return false;
87+
}
88+
}
89+
90+
/**
91+
* 函数名称: isOpera
92+
* 函数功能: 判断是否是opera
93+
* 输入参数: none
94+
* 函数返回值: 成功返回string,失败返回false
95+
* 其它说明: 说明
96+
*/
97+
function isOpera()
98+
{
99+
$uainfo = $this->getUA();
100+
if (preg_match('/.*Opera.*/i',$uainfo))
101+
{
102+
Return true;
103+
}
104+
else
105+
{
106+
Return false;
107+
}
108+
}
109+
110+
/**
111+
* 函数名称: isM3gate
112+
* 函数功能: 判断是否是m3gate
113+
* 输入参数: none
114+
* 函数返回值: 成功返回string,失败返回false
115+
* 其它说明: 说明
116+
*/
117+
function isM3gate()
118+
{
119+
$uainfo = $this->getUA();
120+
if (preg_match('/M3Gate/i',$uainfo))
121+
{
122+
Return true;
123+
}
124+
else
125+
{
126+
Return false;
127+
}
128+
}
129+
130+
/**
131+
* 函数名称: getHttpAccept
132+
* 函数功能: 取得HA
133+
* 输入参数: none
134+
* 函数返回值: 成功返回string,失败返回false
135+
* 其它说明: 说明
136+
*/
137+
function getHttpAccept()
138+
{
139+
if (isset($_SERVER['HTTP_ACCEPT']))
140+
{
141+
Return $_SERVER['HTTP_ACCEPT'];
142+
}
143+
else
144+
{
145+
Return false;
146+
}
147+
}
148+
149+
/**
150+
* 函数名称: getIP
151+
* 函数功能: 取得手机IP
152+
* 输入参数: none
153+
* 函数返回值: 成功返回string
154+
* 其它说明: 说明
155+
*/
156+
function getIP()
157+
{
158+
$ip=getenv('REMOTE_ADDR');
159+
$ip_ = getenv('HTTP_X_FORWARDED_FOR');
160+
if (($ip_ != "") && ($ip_ != "unknown"))
161+
{
162+
$ip=$ip_;
163+
}
164+
return $ip;
165+
}
166+
function alertp(){
167+
168+
getPhoneNumber();
169+
}
170+
171+
?>

0 commit comments

Comments
 (0)