X Tutup
Skip to content

Commit 0a0fedf

Browse files
author
Anselz
committed
Create
Create this Program
1 parent 3fd792d commit 0a0fedf

File tree

11 files changed

+4876
-2
lines changed

11 files changed

+4876
-2
lines changed

JavaScript.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
5B314E481664ECD100DDD89C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B314E291664ECD100DDD89C /* Foundation.framework */; };
2222
5B314E501664ECD100DDD89C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B314E4E1664ECD100DDD89C /* InfoPlist.strings */; };
2323
5B314E531664ECD100DDD89C /* JavaScriptTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B314E521664ECD100DDD89C /* JavaScriptTests.m */; };
24+
5B314E5F1664ED0300DDD89C /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B314E5D1664ED0300DDD89C /* MainViewController.m */; };
25+
5B314E601664ED0300DDD89C /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B314E5E1664ED0300DDD89C /* MainViewController.xib */; };
2426
/* End PBXBuildFile section */
2527

2628
/* Begin PBXContainerItemProxy section */
@@ -53,6 +55,9 @@
5355
5B314E4F1664ECD100DDD89C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5456
5B314E511664ECD100DDD89C /* JavaScriptTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JavaScriptTests.h; sourceTree = "<group>"; };
5557
5B314E521664ECD100DDD89C /* JavaScriptTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JavaScriptTests.m; sourceTree = "<group>"; };
58+
5B314E5C1664ED0300DDD89C /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = "<group>"; };
59+
5B314E5D1664ED0300DDD89C /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = "<group>"; };
60+
5B314E5E1664ED0300DDD89C /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = "<group>"; };
5661
/* End PBXFileReference section */
5762

5863
/* Begin PBXFrameworksBuildPhase section */
@@ -115,6 +120,9 @@
115120
5B314E361664ECD100DDD89C /* AppDelegate.h */,
116121
5B314E371664ECD100DDD89C /* AppDelegate.m */,
117122
5B314E2E1664ECD100DDD89C /* Supporting Files */,
123+
5B314E5C1664ED0300DDD89C /* MainViewController.h */,
124+
5B314E5D1664ED0300DDD89C /* MainViewController.m */,
125+
5B314E5E1664ED0300DDD89C /* MainViewController.xib */,
118126
);
119127
path = JavaScript;
120128
sourceTree = "<group>";
@@ -227,6 +235,7 @@
227235
5B314E3A1664ECD100DDD89C /* Default.png in Resources */,
228236
5B314E3C1664ECD100DDD89C /* Default@2x.png in Resources */,
229237
5B314E3E1664ECD100DDD89C /* Default-568h@2x.png in Resources */,
238+
5B314E601664ED0300DDD89C /* MainViewController.xib in Resources */,
230239
);
231240
runOnlyForDeploymentPostprocessing = 0;
232241
};
@@ -263,6 +272,7 @@
263272
files = (
264273
5B314E341664ECD100DDD89C /* main.m in Sources */,
265274
5B314E381664ECD100DDD89C /* AppDelegate.m in Sources */,
275+
5B314E5F1664ED0300DDD89C /* MainViewController.m in Sources */,
266276
);
267277
runOnlyForDeploymentPostprocessing = 0;
268278
};
@@ -357,6 +367,7 @@
357367
5B314E571664ECD100DDD89C /* Debug */ = {
358368
isa = XCBuildConfiguration;
359369
buildSettings = {
370+
CLANG_ENABLE_OBJC_ARC = NO;
360371
GCC_PRECOMPILE_PREFIX_HEADER = YES;
361372
GCC_PREFIX_HEADER = "JavaScript/JavaScript-Prefix.pch";
362373
INFOPLIST_FILE = "JavaScript/JavaScript-Info.plist";
@@ -368,6 +379,7 @@
368379
5B314E581664ECD100DDD89C /* Release */ = {
369380
isa = XCBuildConfiguration;
370381
buildSettings = {
382+
CLANG_ENABLE_OBJC_ARC = NO;
371383
GCC_PRECOMPILE_PREFIX_HEADER = YES;
372384
GCC_PREFIX_HEADER = "JavaScript/JavaScript-Prefix.pch";
373385
INFOPLIST_FILE = "JavaScript/JavaScript-Info.plist";
@@ -429,6 +441,7 @@
429441
5B314E581664ECD100DDD89C /* Release */,
430442
);
431443
defaultConfigurationIsVisible = 0;
444+
defaultConfigurationName = Release;
432445
};
433446
5B314E591664ECD100DDD89C /* Build configuration list for PBXNativeTarget "JavaScriptTests" */ = {
434447
isa = XCConfigurationList;
@@ -437,6 +450,7 @@
437450
5B314E5B1664ECD100DDD89C /* Release */,
438451
);
439452
defaultConfigurationIsVisible = 0;
453+
defaultConfigurationName = Release;
440454
};
441455
/* End XCConfigurationList section */
442456
};

JavaScript.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "1.0">
5+
</Bucket>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0450"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "5B314E221664ECD100DDD89C"
18+
BuildableName = "JavaScript.app"
19+
BlueprintName = "JavaScript"
20+
ReferencedContainer = "container:JavaScript.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "5B314E431664ECD100DDD89C"
36+
BuildableName = "JavaScriptTests.octest"
37+
BlueprintName = "JavaScriptTests"
38+
ReferencedContainer = "container:JavaScript.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "5B314E221664ECD100DDD89C"
46+
BuildableName = "JavaScript.app"
47+
BlueprintName = "JavaScript"
48+
ReferencedContainer = "container:JavaScript.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
</TestAction>
52+
<LaunchAction
53+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
54+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
55+
launchStyle = "0"
56+
useCustomWorkingDirectory = "NO"
57+
buildConfiguration = "Debug"
58+
ignoresPersistentStateOnLaunch = "NO"
59+
debugDocumentVersioning = "YES"
60+
allowLocationSimulation = "YES">
61+
<BuildableProductRunnable>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "5B314E221664ECD100DDD89C"
65+
BuildableName = "JavaScript.app"
66+
BlueprintName = "JavaScript"
67+
ReferencedContainer = "container:JavaScript.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
<AdditionalOptions>
71+
</AdditionalOptions>
72+
</LaunchAction>
73+
<ProfileAction
74+
shouldUseLaunchSchemeArgsEnv = "YES"
75+
savedToolIdentifier = ""
76+
useCustomWorkingDirectory = "NO"
77+
buildConfiguration = "Release"
78+
debugDocumentVersioning = "YES">
79+
<BuildableProductRunnable>
80+
<BuildableReference
81+
BuildableIdentifier = "primary"
82+
BlueprintIdentifier = "5B314E221664ECD100DDD89C"
83+
BuildableName = "JavaScript.app"
84+
BlueprintName = "JavaScript"
85+
ReferencedContainer = "container:JavaScript.xcodeproj">
86+
</BuildableReference>
87+
</BuildableProductRunnable>
88+
</ProfileAction>
89+
<AnalyzeAction
90+
buildConfiguration = "Debug">
91+
</AnalyzeAction>
92+
<ArchiveAction
93+
buildConfiguration = "Release"
94+
revealArchiveInOrganizer = "YES">
95+
</ArchiveAction>
96+
</Scheme>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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>SchemeUserState</key>
6+
<dict>
7+
<key>JavaScript.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>5B314E221664ECD100DDD89C</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>5B314E431664ECD100DDD89C</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
</dict>
26+
</dict>
27+
</plist>

JavaScript/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
10+
#import "MainViewController.h"
1111
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1212

1313
@property (strong, nonatomic) UIWindow *window;

JavaScript/AppDelegate.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ @implementation AppDelegate
1212

1313
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1414
{
15-
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
15+
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
1616
// Override point for customization after application launch.
1717
self.window.backgroundColor = [UIColor whiteColor];
18+
MainViewController *rootViewController = [[[MainViewController alloc]init]autorelease];
19+
[rootViewController setTest:@"hello"];
20+
self.window.rootViewController = rootViewController;
1821
[self.window makeKeyAndVisible];
1922
return YES;
2023
}

JavaScript/MainViewController.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MainViewController.h
3+
// JavaScript
4+
//
5+
// Created by Ansel on 12-11-27.
6+
// Copyright (c) 2012年 Ansel. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface MainViewController : UIViewController<UIWebViewDelegate>
12+
{
13+
NSString *test;
14+
}
15+
-(void)setTest:(NSString *) newtest;
16+
@property (retain, nonatomic) IBOutlet UIWebView *JSwebView;
17+
@end

JavaScript/MainViewController.m

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//
2+
// MainViewController.m
3+
// JavaScript
4+
//
5+
// Created by Ansel on 12-11-27.
6+
// Copyright (c) 2012年 Ansel. All rights reserved.
7+
//
8+
9+
#import "MainViewController.h"
10+
#include <sys/sysctl.h>
11+
12+
#include <mach/mach.h>
13+
@interface MainViewController ()
14+
15+
@end
16+
17+
@implementation MainViewController
18+
@synthesize JSwebView;
19+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
20+
{
21+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
22+
if (self) {
23+
// Custom initialization
24+
}
25+
return self;
26+
}
27+
28+
- (void)viewDidLoad
29+
{
30+
[super viewDidLoad];
31+
NSLog(@"test String :%@",test);
32+
JSwebView.backgroundColor = [UIColor clearColor];
33+
JSwebView.scalesPageToFit = YES;
34+
JSwebView. delegate = self;
35+
NSURL * url = [[NSURL alloc] initWithString: @"http://www.google.com.hk/m?gl=CN&hl=zh_CN&source=ihp" ];
36+
NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
37+
[JSwebView loadRequest:request];
38+
[url release];
39+
[request release];
40+
41+
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3
42+
target:self
43+
selector:@selector(onTimer:)
44+
userInfo:nil
45+
repeats:YES];
46+
// Do any additional setup after loading the view from its nib.
47+
}
48+
#pragma mark - ----------UIWebView代理方法------------
49+
- ( void )webViewDidFinishLoad:(UIWebView * )webView {
50+
51+
NSString * currentURL = [webView stringByEvaluatingJavaScriptFromString: @"document.location.href" ];
52+
NSString * title = [webView stringByEvaluatingJavaScriptFromString: @"document.title" ];
53+
NSLog(@"\ncurrentURL is:%@,\nTitle is:%@",currentURL,title);
54+
NSString * js_result = [webView stringByEvaluatingJavaScriptFromString: @"document.getElementsByName('q')[0].value='赵发凯'; " ];
55+
NSLog(@"js_result is:%@",js_result);
56+
57+
// NSString * js_result2 = [webView stringByEvaluatingJavaScriptFromString: @" document.forms[0].submit(); "];
58+
// NSLog(@"js_result2 is:%@",js_result2);
59+
// [webView stringByEvaluatingJavaScriptFromString: @" var script = document.createElement('script'); "
60+
// " script.type = 'text/javascript'; "
61+
// " script.text = \"function myFunction() { "
62+
// " var field = document.getElementsByName('q')[0]; "
63+
// " field.value='赵发凯'; "
64+
// " document.forms[0].submit(); "
65+
// " }\"; "
66+
// " document.getElementsByTagName('head')[0].appendChild(script); " ];
67+
//
68+
// [webView stringByEvaluatingJavaScriptFromString: @" myFunction(); " ];
69+
}
70+
- (void)didReceiveMemoryWarning
71+
{
72+
[super didReceiveMemoryWarning];
73+
// Dispose of any resources that can be recreated.
74+
}
75+
//MARK: 可用内存
76+
- (double)availableMemory
77+
{
78+
vm_statistics_data_t vmStats;
79+
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
80+
kern_return_t kernReturn = host_statistics(mach_host_self(),HOST_VM_INFO,(host_info_t)&vmStats,&infoCount);
81+
if(kernReturn != KERN_SUCCESS)
82+
{
83+
return NSNotFound;
84+
}
85+
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
86+
}
87+
88+
89+
//MARK: 已使用内存
90+
- (double)usedMemory
91+
{
92+
task_basic_info_data_t taskInfo;
93+
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
94+
kern_return_t kernReturn = task_info(mach_task_self(),
95+
TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
96+
if(kernReturn != KERN_SUCCESS) {
97+
return NSNotFound;
98+
}
99+
return taskInfo.resident_size / 1024.0 / 1024.0;
100+
}
101+
102+
//MARK: 总的内存为
103+
-(double)totalMemory{
104+
task_basic_info_data_t taskInfo;
105+
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
106+
kern_return_t kernReturn = task_info(mach_task_self(),
107+
TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
108+
if(kernReturn != KERN_SUCCESS) {
109+
return NSNotFound;
110+
}
111+
return taskInfo.resident_size / 1024.0 / 1024.0;
112+
}
113+
114+
- (void)onTimer:(id)sender
115+
{
116+
NSLog(@" 使用内存 %f 剩余内存 %f",[self usedMemory],[self availableMemory]);
117+
}
118+
-(void)setTest:(NSString *) newtest{
119+
if(test == newtest){
120+
[test release];
121+
}
122+
test = [newtest retain];
123+
}
124+
@end

0 commit comments

Comments
 (0)
X Tutup