ios App Development Using Cordova

Similar documents
BUILDING MOBILE WEB APPS WITH PHONEGAP. Matt Zukowski

Adobe Summit 2015 Lab 712: Building Mobile Apps: A PhoneGap Enterprise Introduction for Developers

Generate Android App

Introduction: The Xcode templates are not available in Cordova or above, so we'll use the previous version, for this recipe.

Website Login Integration

PhoneGap Build Starter

place/business fetch details, removefromfavorite () function, 189 search button handler bind, B BlackBerry build environment

unisys ClearPath eportal Developer 6.1 Unisys Multi-Device App Developer s Guide March

Mobile Application Development

Fortis Theme Update Guide

Dashboard Skin Tutorial. For ETS2 HTML5 Mobile Dashboard v3.0.2

Links Getting Started with Widgets, Gadgets and Mobile Apps

Responsive Design Best Practices

How To Use Titanium Studio

Develop a Native App (ios and Android) for a Drupal Website without Learning Objective-C or Java. Drupaldelphia 2014 By Joe Roberts

Working with the new enudge responsive styles

CST 150 Web Design I CSS Review - In-Class Lab

DreamFactory & Modus Create Case Study

Sizmek Formats. IAB Mobile Pull. Build Guide

Chapter 1 Introduction to web development and PHP

Responsive Web Design for Teachers. Exercise: Building a Responsive Page with the Fluid Grid Layout Feature

JJY s Joomla 1.5 Template Design Tutorial:

jquery Sliding Image Gallery

Contents. Downloading the Data Files Centering Page Elements... 6

Apple Newsstand. v 1.2 1/22

CSS for Page Layout. Key Concepts

Mobile Web Site Style Guide

How To Customize A Forum On Vanilla Forum On A Pcode (Forum) On A Windows (For Forum) On An Html5 (Forums) On Pcode Or Windows 7 (Forforums) On Your Pc

Quick Start Guide Mobile Entrée 4

Style & Layout in the web: CSS and Bootstrap

CREATING HORIZONTAL NAVIGATION BAR USING ADOBE DREAMWEAVER CS5

Beginning Web Development with Node.js

Development Perspective: DIV and CSS HTML layout. Web Design. Lesson 2. Development Perspective: DIV/CSS

Title: Appium Automation for Mac OS X. Created By: Prithivirajan M. Abstract. Introduction

FREE VERSION. Created by: Jason Nesbitt Mobile App Development Guide

Chapter 1. Introduction to web development

ios App for Mobile Website! Documentation!

Web layout guidelines for daughter sites of Scotland s Environment

Icons: 1024x1024, 512x512, 180x180, 120x120, 114x114, 80x80, 60x60, 58x58, 57x57, 40x40, 29x29

White Paper Using PHP Site Assistant to create sites for mobile devices

WP Popup Magic User Guide

Extended Reference for Freeway 7

JTouch Mobile Extension for Joomla! User Guide

Building Mobile Applications Creating ios applications with jquery Mobile, PhoneGap, and Drupal 7

Web Designer s Guide to. panpage. v4.0. Website Content Management System

CREATING A NEWSLETTER IN ADOBE DREAMWEAVER CS5 (step-by-step directions)

Access the TCNJ Palo Alto Networks VPN using the GlobalProtect VPN client

ultimo theme Update Guide Copyright Infortis All rights reserved

Differences between HTML and HTML 5

OS X LION SET UP THE SYSTEM

Chapter 7 Page Layout Basics Key Concepts. Copyright 2013 Terry Ann Morris, Ed.D

TakeMySelfie ios App Documentation

How to program a Zumo Robot with Simulink

A set-up guide and general information to help you get the most out of your new theme.

Introduction to web development and JavaScript

THE SAS OUTPUT DELIVERY SYSTEM: BOLDLY TAKE YOUR WEB PAGES WHERE THEY HAVE NEVER GONE BEFORE! CHEVELL PARKER, SAS INSTITUTE INC.

Spike Tech Tip: How to use your online, cloud-based tools for Spike

Developing multidevice-apps using Apache Cordova and HTML5. Guadalajara Java User Group Guillermo Muñoz Java Developer

How to Deploy Custom Visualizations Using D3 on MSTR 10. Version 1.0. Presented by: Felipe Vilela

How to install and use the File Sharing Outlook Plugin

Microsoft Expression Web Quickstart Guide

Export / Import using itunes File Sharing

Developing Native JavaScript Mobile Apps Using Apache Cordova. Hazem Saleh

Responsive Web Design Creative License

Pulse Secure Client. Customization Developer Guide. Product Release 5.1. Document Revision 1.0. Published:

MiraCosta College now offers two ways to access your student virtual desktop.

the intro for RPG programmers Making mobile app development easier... of KrengelTech by Aaron Bartell

Web Developer Jr - Newbie Course

How to File the FBAR Electronically. The following steps describe the process of filing an FBAR electronically with our system.

Adobe Dreamweaver CC 14 Tutorial

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

How to Add a Transparent Flash FLV movie to your Web Page Tutorial by R. Berdan Oct

User Guide for Smart Former Gold (v. 1.0) by IToris Inc. team

How To Customize An Orgsync App On Anorus Mobile Security Suite On A Microsoft Ipad Oracle 2.5 (Ios) On A Pc Orca 2.2 (Iphone) On An Android Orca2 (Ip

Digital Signage with Apps

Blueball Design Dynamic Content 2 Stack Readme Manual v1.0

1. Application Overview System Requirements Installation Splash Screen Registration Screen...

Monitor Your Home With the Raspberry Pi B+

ITP 101 Project 3 - Dreamweaver

Sizmek Formats. HTML5 Page Skin. Build Guide

Getting Started using the SQuirreL SQL Client

You can use percentages for both page elements and text. Ems are used for text,

We automatically generate the HTML for this as seen below. Provide the above components for the teaser.txt file.

Wakanda Studio Features

WHITEPAPER. Skinning Guide. Let s chat Velaro info@velaro.com by Velaro

Certificates and Application Resigning

Polycom Video Media Center (VMC) 1000 Branding Guide

<link rel="stylesheet" type="text/css" media="all" href="css/iphone.css" /> <!-- User defined styles -->

Transcription:

ios App Development Using Cordova Created by Todd Treece Last updated on 2015-06-29 08:20:06 AM EDT

Guide Contents Guide Contents Overview Installing Dependencies Creating a New App index.html index.css index.js Testing the App ios Simulator ios Device Customizing the App Modifying the config.xml 2 3 4 6 7 8 9 11 11 11 13 14 Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 2 of 17

Overview This tutorial will take you through the steps necessary to get started with using Apache Cordova (http://adafru.it/fu1) to write ios applications. The benefit of using Cordova is that you do not have to learn Objective-C or Swift to write an app. If you can write HTML and Javascript, you can build a native ios app with Cordova! We are going to make a very simple weather application for our first project. It will use data from openweathermap.org (http://adafru.it/fu2)and display it on the screen with an icon. Let's get started. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 3 of 17

Installing Dependencies You will need a Mac running OS X 10.10 to run the latest version of XCode, which is required for uploading to ios devices. Thanks to changes in XCode 7, you no longer need an Apple Developer account to test applications on ios devices. You can also use XCode 6 for this tutorial, but you will need an Apple Developer account to upload to your ios device. XCode 7 is still in beta and not available in the App Store yet, so you will need to download it from Apple's Developer site and install. XCode 7 Download http://adafru.it/fu3 You will also need the latest version of node.js (http://adafru.it/fu4) installed on your computer. Download and install the latest version using the link below. Node.js Download http://adafru.it/fu4 Next, you will need to install Cordova using npm from the terminal. npm install -g cordova ios-sim Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 4 of 17

Now we are ready to look at creating a basic application. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 5 of 17

Creating a New App First, we will need to create the project from the terminal using the following command. cordova create weather com.example.weather Weather The cordova create command bootstraps a basic app using the supplied folder, app ID, and name. The new app has the following directory structure. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 6 of 17

config.xml hooks README.md platforms plugins www css index.css img logo.png index.html js index.js 7 directories, 6 files Most of our work will be focused on the files in the www folder. Since a Cordova application is a web app, most of the development can be done in a browser before testing on a phone. Let's get started with writing our basic weather app. index.html First, open up www/index.html in your favorite text editor, and replace the default HTML with the following: <!DOCTYPE html> <html> <head> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device- <link rel="stylesheet" type="text/css" href="css/index.css"> <title>weather</title> </head> <body> <div class="app"> <img src="" id="icon"> <div id="info">loading...</div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/index.js"></script> </body> </html> Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 7 of 17

The HTML above sets the title of the page to 'Weather', adds a couple div elements to hold our weather info, and adds the latest version of jquery to the page. index.css Next, open up www/css/index.css in your text editor, and replace the existing CSS with the following: * { -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ body { -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ background-color:#000; font-family:'helveticaneue-light', 'HelveticaNeue', Helvetica, Arial, sans-serif; font-size:12px; height:100%; margin:0px; padding:0px; text-transform:uppercase; width:100%; color:#fff; /* Portrait layout (default) */.app { position:absolute; /* position in the center of the screen */ left:50%; top:16%; height:50px; /* text area height */ width:225px; /* text area width */ text-align:center; padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */ margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */ /* offset horizontal: half of text area width */ /* Landscape layout (with min-width) */ @media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {.app { padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */ margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 8 of 17

margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ /* offset horizontal: half of image width and text area width */ #icon, #info { text-align: center; #icon { width: 50% h1 { padding: 0; margin: 0; index.js The final modification in the www folder we will need to make is to the www/js/index.js file. var app = { zip: 10013, // nyc. feel free to change initialize: function() {, this.bindevents(); bindevents: function() {, document.addeventlistener('deviceready', this.ondeviceready, false); ondeviceready: function() { // grap weather info $.getjson('http://api.openweathermap.org/data/2.5/find?q=' + app.zip + ',us&units=imperial', function(data) var info = $('#info'), icon = $('#icon'), result; // no results. bail if(data.count < 1) { Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 9 of 17

if(data.count < 1) { info.html('could not load weather'); return; // set result var to first result result = data.list[0]; // show icon if we have a result if(result.weather.length > 0) { icon.attr('src', 'http://openweathermap.org/img/w/' + result.weather[0].icon + '.png'); icon.show(); // add info to page info.html('<h1>' + result.name + '</h1><br>'); info.append(result.main.temp + ' F<br>'); info.append(result.main.humidity + '% Humidity<br>'); info.append(result.wind.speed + ' MPH'); ); ; app.initialize(); Now that we have added all of our code to the project, we can test our app. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 10 of 17

Testing the App Before testing our app, we will need to add the Cordova whitelist plugin to our app, and to add the ios platform. First add the plugin using the following command. This will only need to be done once for any plugin you use. cordova plugin add cordova-plugin-whitelist@1.0.0 Next, add the ios platform to the project. This will only need to be done once. cordova platform add ios ios Simulator Now we are ready to run the app in the ios simulator. Run the following command to build the app and launch the simulator. cordova emulate ios Device Now we are ready to test the app on an actual ios device. Plug your device in using a USB cable, Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 11 of 17

and open XCode 7. Once XCode has finished opening, we will open the project using the File- >Open menu. Navigate to the weather/platforms/ios folder and open Weather.xcodeproj. Once the project has opened, click the play button at the top of the window to build and install the app on your device. Make sure the device is unlocked before clicking the play button. The app should now launch on your device and display the weather! If you modify any of the files in the project, you will need to run the following command before uploading to your device. cordova build Next, we will look at how to customize the app with a new icon and splash screen. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 12 of 17

Customizing the App Now that you know the basics of building and uploading an app, let's customize it a bit by adding a splash screen. We will be using TiCon (http://adafru.it/fu5) to make new splash and icon images. Upload your images with the suggested sizes to the site and generate new images for your app. Download the images and add them to your project under a new res/ios folder. The folder structure of your app should now look like the structure below. config.xml hooks README.md platforms platforms.json Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 13 of 17

plugins res ios Default-568h@2x.png Default-667h@2x.png Default-Landscape-736h@3x.png Default-Landscape.png Default-Landscape@2x.png Default-Portrait-736h@3x.png Default-Portrait.png Default-Portrait@2x.png Default.png Default@2x.png appicon-60.png appicon-60@2x.png appicon-60@3x.png appicon-72.png appicon-72@2x.png appicon-76.png appicon-76@2x.png appicon-small-40.png appicon-small-40@2x.png appicon-small-50.png appicon-small-50@2x.png appicon-small.png appicon-small@2x.png appicon-small@3x.png appicon.png appicon@2x.png itunesartwork itunesartwork@2x www css index.css img logo.png index.html js index.js 9 directories, 35 files Modifying the config.xml Next, you will need to add the locations of your images to the config.xml found in your app. The Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 14 of 17

file should look like this after you have finished. <?xml version='1.0' encoding='utf-8'?> <widget id="com.example.weather" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apach <name>weather</name> <description> A simple weather app. </description> <author email="dev@cordova.apache.org" href="http://cordova.io"> Todd Treece </author> <content src="index.html" /> <plugin name="cordova-plugin-whitelist" version="1.0.0" /> <access origin="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> <allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" /> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> <icon src="res/ios/appicon-60@3x.png" width="180" height="180" /> <icon src="res/ios/appicon-60.png" width="60" height="60" /> <icon src="res/ios/appicon-60@2x.png" width="120" height="120" /> <icon src="res/ios/appicon-76.png" width="76" height="76" /> <icon src="res/ios/appicon-76@2x.png" width="152" height="152" /> <icon src="res/ios/appicon-small-40.png" width="40" height="40" /> <icon src="res/ios/appicon-small-40@2x.png" width="80" height="80" /> <icon src="res/ios/appicon-small-40@3x.png" width="120" height="120" /> <icon src="res/ios/appicon.png" width="57" height="57" /> <icon src="res/ios/appicon@2x.png" width="114" height="114" /> <icon src="res/ios/appicon-72.png" width="72" height="72" /> <icon src="res/ios/appicon-72@2x.png" width="144" height="144" /> <icon src="res/ios/appicon-small.png" width="29" height="29" /> <icon src="res/ios/appicon-small@2x.png" width="58" height="58" /> <icon src="res/ios/appicon-small@3x.png" wdth="87" height="87" /> <icon src="res/ios/appicon-small-50.png" width="50" height="50" /> <icon src="res/ios/appicon-small-50@2x.png" width="100" height="100" /> <splash src="res/ios/default.png" width="320" height="480"/> <splash src="res/ios/default@2x.png" width="640" height="960"/> <splash src="res/ios/default-portrait.png" width="768" height="1024"/> <splash src="res/ios/default-portrait@2x.png" width="1536" height="2048"/> <splash src="res/ios/default-landscape.png" width="1024" height="768"/> <splash src="res/ios/default-landscape@2x.png" width="2048" height="1334"/> Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 15 of 17

<splash src="res/ios/default-landscape@2x.png" width="2048" height="1334"/> <splash src="res/ios/default-568h@2x.png" width="640" height="1136"/> <splash src="res/ios/default-667h@2x.png" width="640" height="1136"/> <splash src="res/ios/default-landscape-736h@3x.png" width="750" height="1242"/> <splash src="res/ios/default-portrait-736h@3x.png" width="1242" height="2208"/> <splash src="res/ios/640x1136.png" width="640" height="1136"/> </platform> </widget> After modifying the config, you will need to rebuild the app by running the following command. cordova build Now if you upload the app to a device or test it in the simulator, you will see the new icon and splash image. Adafruit Industries https://learn.adafruit.com/ios-app-development-using-cordova Page 16 of 17

That's it! We will be exploring interating with hardware from ios in future tutorials, so stay tuned! Adafruit Industries Last Updated: 2015-06-29 08:20:07 AM EDT Page 17 of 17