You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/06/02 01:53:39 UTC

ios commit: Fixes CB-851 - guide for using url schemes in ios

Updated Branches:
  refs/heads/master 982d0bb3f -> 4d71555c4


Fixes CB-851 - guide for using url schemes in ios


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/4d71555c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/4d71555c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/4d71555c

Branch: refs/heads/master
Commit: 4d71555c4474ce068267d8a63b0cdd797417a9fe
Parents: 982d0bb
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri Jun 1 16:53:28 2012 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Jun 1 16:53:28 2012 -0700

----------------------------------------------------------------------
 Makefile                                     |    5 ++
 guides/Cordova Custom URL Scheme Handling.md |   44 +++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4d71555c/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 214f430..a60c781 100644
--- a/Makefile
+++ b/Makefile
@@ -212,6 +212,7 @@ installer: check-utils clean check-wkhtmltopdf md-to-html cordova-lib xcode3-tem
 	@$(WKHTMLTOPDF) --footer-center "Cordova ${CDV_VER} Plugin Upgrade Guide" CordovaInstaller/docs/plugin_upgrade.html 'dist/files/Guides/Cordova Plugin Upgrade Guide.pdf' > /dev/null 2>> $(PKG_ERROR_LOG)
 	@$(WKHTMLTOPDF) --footer-center "Cordova ${CDV_VER} Settings File" CordovaInstaller/docs/settings_file.html 'dist/files/Guides/Cordova Settings File.pdf' > /dev/null 2>> $(PKG_ERROR_LOG)
 	@$(WKHTMLTOPDF) --footer-center "Cordova ${CDV_VER} JavaScript Exception Logging" CordovaInstaller/docs/exception_logging.html 'dist/files/Guides/Cordova JavaScript Exception Logging.pdf' > /dev/null 2>> $(PKG_ERROR_LOG)
+	@$(WKHTMLTOPDF) --footer-center "Cordova ${CDV_VER} Custom URL Scheme Handling" CordovaInstaller/docs/custom_url_scheme.html 'dist/files/Guides/Cordova Custom URL Scheme Handling.pdf' > /dev/null 2>> $(PKG_ERROR_LOG)
 	@textutil -convert html -font 'Courier New' LICENSE -output CordovaInstaller/docs/LICENSE.html > /dev/null 2>> $(PKG_ERROR_LOG)
 	@textutil -cat html CordovaInstaller/docs/finishup.html CordovaInstaller/docs/readme.html CordovaInstaller/docs/LICENSE.html -output dist/files/Readme.html > /dev/null 2>> $(PKG_ERROR_LOG)
 	@$(WKHTMLTOPDF) --footer-center "Cordova ${CDV_VER} Readme" dist/files/Readme.html dist/files/Readme.pdf > /dev/null 2>> $(PKG_ERROR_LOG)
@@ -313,3 +314,7 @@ md-to-html: check-markdown
 	@echo '<html><body style="font-family: Helvetica Neue;font-size:10pt;">' >	 CordovaInstaller/docs/exception_logging.html
 	@$(MARKDOWN) 'guides/Cordova JavaScript Exception Logging.md' >> CordovaInstaller/docs/exception_logging.html
 	@echo '</body></html>'  >> CordovaInstaller/docs/exception_logging.html
+	@# generate 'Cordova Custom URL Scheme Handling' html from markdown
+	@echo '<html><body style="font-family: Helvetica Neue;font-size:10pt;">' >	 CordovaInstaller/docs/custom_url_scheme.html
+	@$(MARKDOWN) 'guides/Cordova Custom URL Scheme Handling.md' >> CordovaInstaller/docs/custom_url_scheme.html
+	@echo '</body></html>'  >> CordovaInstaller/docs/custom_url_scheme.html

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4d71555c/guides/Cordova Custom URL Scheme Handling.md
----------------------------------------------------------------------
diff --git a/guides/Cordova Custom URL Scheme Handling.md b/guides/Cordova Custom URL Scheme Handling.md
new file mode 100644
index 0000000..e7c9c99
--- /dev/null
+++ b/guides/Cordova Custom URL Scheme Handling.md	
@@ -0,0 +1,44 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+-->
+# Cordova Custom URL Scheme Handling #
+
+For an iOS app, you can add a URL Scheme handler in your app's Info.plist so that your app launches when another iOS app (like Mobile Safari) launches a URL with your custom scheme.
+
+1. Register your custom scheme in your app's Info.plist: the instructions are [here](http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW21)
+2. In your JavaScript, add a global function **handleOpenURL** which just takes one parameter, which will be a string containing the URL that was launched. Add your code to parse and handle the URL in that global function. This function will be called always if your app was launched from the custom scheme.
+
+        function handleOpenURL(url) {
+            // TODO: parse the url, and do something 
+        }
+
+3. In your JavaScript, the global variable **invokeString** will be set with the URL that your app was launched with **if it was first launched with a URL (from a terminated state)**, not from resuming from the background (multi-tasking).
+
+        
+**IMPORTANT NOTE:** 
+        
+You **cannot** launch any interactive features like alerts in the **handleOpenURL** code, if you do, your app will hang. Similarly, you should not call any Cordova APIs in there, unless you wrap it first in a setTimeout call, with a timeout value of zero:
+
+        function handleOpenUrl(url) {
+             // TODO: parse the url, and do something 
+             setTimeout(function() {
+                 // TODO: call some Cordova API here
+             }, 0);
+        }
\ No newline at end of file