Skip to content

Commit 512a616

Browse files
author
Alexandre Vallières-Lagacé
committed
Added Xcode demo for iOS platform
1 parent 43c1235 commit 512a616

138 files changed

Lines changed: 15219 additions & 0 deletions

File tree

Some content is hidden

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

demo-cordova/config.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<widget id="com.vallieres.plugin.getrouteripaddress.demo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3+
<name>GetRouterIPAddressDemo</name>
4+
<description>
5+
A sample Apache Cordova application that responds to the deviceready event.
6+
</description>
7+
<author email="dev@cordova.apache.org" href="http://cordova.io">
8+
Apache Cordova Team
9+
</author>
10+
<content src="index.html" />
11+
<access origin="*" />
12+
</widget>

demo-cordova/hooks/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
-->
21+
# Cordova Hooks
22+
23+
Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
24+
* Application hooks from `/hooks`;
25+
* Application hooks from `config.xml`;
26+
* Plugin hooks from `plugins/.../plugin.xml`.
27+
28+
__Remember__: Make your scripts executable.
29+
30+
__Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.
31+
32+
## Supported hook types
33+
The following hook types are supported:
34+
35+
after_build/
36+
after_compile/
37+
after_docs/
38+
after_emulate/
39+
after_platform_add/
40+
after_platform_rm/
41+
after_platform_ls/
42+
after_plugin_add/
43+
after_plugin_ls/
44+
after_plugin_rm/
45+
after_plugin_search/
46+
after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
47+
after_prepare/
48+
after_run/
49+
after_serve/
50+
before_build/
51+
before_compile/
52+
before_docs/
53+
before_emulate/
54+
before_platform_add/
55+
before_platform_rm/
56+
before_platform_ls/
57+
before_plugin_add/
58+
before_plugin_ls/
59+
before_plugin_rm/
60+
before_plugin_search/
61+
before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
62+
before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
63+
before_prepare/
64+
before_run/
65+
before_serve/
66+
pre_package/ <-- Windows 8 and Windows Phone only.
67+
68+
## Ways to define hooks
69+
### Via '/hooks' directory
70+
To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:
71+
72+
# script file will be automatically executed after each build
73+
hooks/after_build/after_build_custom_action.js
74+
75+
76+
### Config.xml
77+
78+
Hooks can be defined in project's `config.xml` using `<hook>` elements, for example:
79+
80+
<hook type="before_build" src="scripts/appBeforeBuild.bat" />
81+
<hook type="before_build" src="scripts/appBeforeBuild.js" />
82+
<hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
83+
84+
<platform name="wp8">
85+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.bat" />
86+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.js" />
87+
<hook type="before_plugin_install" src="scripts/wp8/appWP8BeforePluginInstall.js" />
88+
...
89+
</platform>
90+
91+
<platform name="windows8">
92+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.bat" />
93+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.js" />
94+
<hook type="before_plugin_install" src="scripts/windows8/appWin8BeforePluginInstall.js" />
95+
...
96+
</platform>
97+
98+
### Plugin hooks (plugin.xml)
99+
100+
As a plugin developer you can define hook scripts using `<hook>` elements in a `plugin.xml` like that:
101+
102+
<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
103+
<hook type="after_build" src="scripts/afterBuild.js" />
104+
105+
<platform name="wp8">
106+
<hook type="before_plugin_install" src="scripts/wp8BeforeInstall.js" />
107+
<hook type="before_build" src="scripts/wp8BeforeBuild.js" />
108+
...
109+
</platform>
110+
111+
`before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
112+
113+
## Script Interface
114+
115+
### Javascript
116+
117+
If you are writing hooks in Javascript you should use the following module definition:
118+
```javascript
119+
module.exports = function(context) {
120+
...
121+
}
122+
```
123+
124+
You can make your scipts async using Q:
125+
```javascript
126+
module.exports = function(context) {
127+
var Q = context.requireCordovaModule('q');
128+
var deferral = new Q.defer();
129+
130+
setTimeout(function(){
131+
console.log('hook.js>> end');
132+
deferral.resolve();
133+
}, 1000);
134+
135+
return deferral.promise;
136+
}
137+
```
138+
139+
`context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
140+
```json
141+
{
142+
"hook": "before_plugin_install",
143+
"scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
144+
"cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
145+
"opts": {
146+
"projectRoot":"C:\\path\\to\\the\\project",
147+
"cordova": {
148+
"platforms": ["wp8"],
149+
"plugins": ["com.plugin.withhooks"],
150+
"version": "0.21.7-dev"
151+
},
152+
"plugin": {
153+
"id": "com.plugin.withhooks",
154+
"pluginInfo": {
155+
...
156+
},
157+
"platform": "wp8",
158+
"dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
159+
}
160+
},
161+
"cordova": {...}
162+
}
163+
164+
```
165+
`context.opts.plugin` object will only be passed to plugin hooks scripts.
166+
167+
You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
168+
```javascript
169+
var Q = context.requireCordovaModule('q');
170+
```
171+
172+
__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
173+
For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.
174+
175+
### Non-javascript
176+
177+
Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
178+
179+
* CORDOVA_VERSION - The version of the Cordova-CLI.
180+
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
181+
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
182+
* CORDOVA_HOOK - Path to the hook that is being executed.
183+
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
184+
185+
If a script returns a non-zero exit code, then the parent cordova command will be aborted.
186+
187+
## Writing hooks
188+
189+
We highly recommend writting your hooks using Node.js so that they are
190+
cross-platform. Some good examples are shown here:
191+
192+
[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
193+
194+
Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:
195+
196+
#!/usr/bin/env [name_of_interpreter_executable]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.mode1v3
2+
*.perspectivev3
3+
*.pbxuser
4+
.DS_Store
5+
build/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVAvailability.h"
21+
22+
#import "CDVPlugin.h"
23+
#import "CDVViewController.h"
24+
#import "CDVCommandDelegate.h"
25+
#import "CDVURLProtocol.h"
26+
#import "CDVInvokedUrlCommand.h"
27+
28+
#import "CDVDebug.h"
29+
#import "CDVPluginResult.h"
30+
#import "CDVWhitelist.h"
31+
#import "CDVLocalStorage.h"
32+
#import "CDVScreenOrientationDelegate.h"
33+
#import "CDVTimer.h"
34+
35+
#import "NSArray+Comparisons.h"
36+
#import "NSData+Base64.h"
37+
#import "NSDictionary+Extensions.h"
38+
#import "NSMutableArray+QueueAdditions.h"
39+
#import "UIDevice+Extensions.h"
40+
41+
#import "CDVJSON.h"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVAvailabilityDeprecated.h"
21+
22+
#define __CORDOVA_IOS__
23+
24+
#define __CORDOVA_0_9_6 906
25+
#define __CORDOVA_1_0_0 10000
26+
#define __CORDOVA_1_1_0 10100
27+
#define __CORDOVA_1_2_0 10200
28+
#define __CORDOVA_1_3_0 10300
29+
#define __CORDOVA_1_4_0 10400
30+
#define __CORDOVA_1_4_1 10401
31+
#define __CORDOVA_1_5_0 10500
32+
#define __CORDOVA_1_6_0 10600
33+
#define __CORDOVA_1_6_1 10601
34+
#define __CORDOVA_1_7_0 10700
35+
#define __CORDOVA_1_8_0 10800
36+
#define __CORDOVA_1_8_1 10801
37+
#define __CORDOVA_1_9_0 10900
38+
#define __CORDOVA_2_0_0 20000
39+
#define __CORDOVA_2_1_0 20100
40+
#define __CORDOVA_2_2_0 20200
41+
#define __CORDOVA_2_3_0 20300
42+
#define __CORDOVA_2_4_0 20400
43+
#define __CORDOVA_2_5_0 20500
44+
#define __CORDOVA_2_6_0 20600
45+
#define __CORDOVA_2_7_0 20700
46+
#define __CORDOVA_2_8_0 20800
47+
#define __CORDOVA_2_9_0 20900
48+
#define __CORDOVA_3_0_0 30000
49+
#define __CORDOVA_3_1_0 30100
50+
#define __CORDOVA_3_2_0 30200
51+
#define __CORDOVA_3_3_0 30300
52+
#define __CORDOVA_3_4_0 30400
53+
#define __CORDOVA_3_4_1 30401
54+
#define __CORDOVA_3_5_0 30500
55+
#define __CORDOVA_3_6_0 30600
56+
#define __CORDOVA_3_7_0 30700
57+
#define __CORDOVA_NA 99999 /* not available */
58+
59+
/*
60+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_1_7_0
61+
// do something when its at least 1.7.0
62+
#else
63+
// do something else (non 1.7.0)
64+
#endif
65+
*/
66+
#ifndef CORDOVA_VERSION_MIN_REQUIRED
67+
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_3_7_0
68+
#endif
69+
70+
/*
71+
Returns YES if it is at least version specified as NSString(X)
72+
Usage:
73+
if (IsAtLeastiOSVersion(@"5.1")) {
74+
// do something for iOS 5.1 or greater
75+
}
76+
*/
77+
#define IsAtLeastiOSVersion(X) ([[[UIDevice currentDevice] systemVersion] compare:X options:NSNumericSearch] != NSOrderedAscending)
78+
79+
/* Return the string version of the decimal version */
80+
#define CDV_VERSION [NSString stringWithFormat:@"%d.%d.%d", \
81+
(CORDOVA_VERSION_MIN_REQUIRED / 10000), \
82+
(CORDOVA_VERSION_MIN_REQUIRED % 10000) / 100, \
83+
(CORDOVA_VERSION_MIN_REQUIRED % 10000) % 100]
84+
85+
// Enable this to log all exec() calls.
86+
#define CDV_ENABLE_EXEC_LOGGING 0
87+
#if CDV_ENABLE_EXEC_LOGGING
88+
#define CDV_EXEC_LOG NSLog
89+
#else
90+
#define CDV_EXEC_LOG(...) do {} while (NO)
91+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
21+
#import <UIKit/UIKit.h>
22+
23+
#ifdef __clang__
24+
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg)))
25+
#else
26+
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated()))
27+
#endif
28+
29+
static inline BOOL CDV_IsIPad(void) CDV_DEPRECATED(3.7.0, "This will be removed in 4.0.0");
30+
static inline BOOL CDV_IsIPhone5(void) CDV_DEPRECATED(3.7.0, "This will be removed in 4.0.0");
31+
32+
static inline BOOL CDV_IsIPad(void) {
33+
return [[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
34+
}
35+
36+
static inline BOOL CDV_IsIPhone5(void) {
37+
return ([[UIScreen mainScreen] bounds].size.width == 568 && [[UIScreen mainScreen] bounds].size.height == 320) || ([[UIScreen mainScreen] bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320);
38+
}

0 commit comments

Comments
 (0)