mobile devices

51
Running On Mobile How mobile device is different from desktop, and what you can do about it

Upload: ynon-perek

Post on 15-Dec-2014

223 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Mobile Devices

Running On MobileHow mobile device is different from desktop, and what you can do about it

Page 2: Mobile Devices

Mobile Device Characteristics

• Always around

• Always connected

• Used for both urgent tasks and fun

Page 3: Mobile Devices

Users’ Expectations

• Battery lasts forever

• Apps work smoothly

• Seamless app switching

Page 4: Mobile Devices

Developer’s Perspective

• Interruptions will happen all the time

• Consider battery in everything you do

Page 5: Mobile Devices

Some stats

Android apps ad-serving responsible for

75% of app related battery drain

Page 6: Mobile Devices

Mobile Architecture• Application Sandbox

• Getting out:

• Using OS services

• Talking to other apps

• Background Execution

Page 7: Mobile Devices

Let’s start with a desktop

• On a desktop:

• File separation is user based

• A user can access all her files, everywhere

Page 8: Mobile Devices

Let’s start with a desktop

1 file = File.open(“/Users/ynonperek/tmp/test.sh") 2 file.each do |line| 3 print line 4 end

Page 9: Mobile Devices

Mobile Is Different

• Basic entity is the App

WhatsApp Mail Facebook

Mobile OS

Page 10: Mobile Devices

Mobile Apps Storage: iOS

Page 11: Mobile Devices

An app storage options

• Saving files on the file system

• Saving data in preferences (registry)

• Hybrid: Leverage browser storage

Page 12: Mobile Devices

HTML5 Storage

Online/Offline functionality Persistant storage

Page 13: Mobile Devices

Local Data Storage

• How do you store data on a client’s machine ?

Page 14: Mobile Devices

Cookies

Page 15: Mobile Devices

What’s wrong with cookies?• Before HTML5: cookies were used to store data on the

client side

• Cookies Disadvantages:

• Limited size (4k)

• Sent with every request

• Complex to use

Page 16: Mobile Devices

Local Storage• A JavaScript API for storing

client side data

• Can store up to 5MB (per site)

• Simple API

• Never run out of space

Page 17: Mobile Devices

Local Storage API

• Store data:

• Read data:

• Remove data:

localStorage.setItem('username', 'bob');

var stored_username = localStorage.getItem('username'); username = stored_username || 'Anonymous';

localStorage.removeItem('username');

Page 18: Mobile Devices

Q & A

Page 19: Mobile Devices

Offline Application

CacheDealing with low connectivity

(without stealing)

Page 20: Mobile Devices

Offline Web App

• Online-Offline Apps

• Sync with the Cloud, but can suffer a downtime (Think Google Gears)

• Can run completely offline app as a standalone

• Mobile - Save bandwidth

Page 21: Mobile Devices

Offline Web App

GET MANIFEST

CACHE MANIFEST index.html

style/main.css script/main.js

Page 22: Mobile Devices

Cache Manifest File

• Lists all the files that should be stored for offline access

• Enable with:<html manifest="example.appcache">

Page 23: Mobile Devices

Demo

• Application with a cache manifest

• Modifying manifest and updating

Page 24: Mobile Devices

Manifest - The Good

• Can store any file locally

• Provides offline/online app functionality

• Transparent to the user

Page 25: Mobile Devices

Manifest - The Bad

• Not suitable for data storage

• Complex update logic

Page 26: Mobile Devices

Sensitive Data Storage

• Both iOS and Android support a keychain

• Safe storage for sensitive data managed by the OS

Page 27: Mobile Devices

iOS Keychain Demo

KeychainItemWrapper *keychainItem = ! [[KeychainItemWrapper alloc] ! initWithIdentifier:@"YourAppLogin" ! accessGroup:nil];!

[keychainItem setObject:@"password you are saving" forKey:kSecValueData];![keychainItem setObject:@"username you are saving" forKey:kSecAttrAccount];

Init

Save username/password

NSString *password = [keychainItem objectForKey:kSecValueData];!NSString *username = [keychainItem objectForKey:kSecAttrAccount];

Retrieve username/password

Page 28: Mobile Devices

Pop Quiz

• Planning a twitter clone, what data would you store and how?

Page 29: Mobile Devices

Storage: Keep In Mind

• Storage helps you be prepared for interruptions

• Store application state whenever it matters

• Don’t let a user type twice

Page 30: Mobile Devices

Q & A

Page 31: Mobile Devices

Talking to Other Apps

Page 32: Mobile Devices

The problem…

• In a sandbox, we can’t access another app’s data

• Desktop “start external process” is also not an option

Page 33: Mobile Devices

Solution: URL Schemes

• Each app can register itself as a valid handler for some link type

• Each app can open an external link

• OS connects handler with action

Page 34: Mobile Devices

Solution: URL Schemes

Instagram iOSregister scheme

instag://

Page 35: Mobile Devices

Solution: URL Schemes

CoolCam open link

instag://photo/uploadiOS

iOS Instagraminstag://photo/upload

other request data

Page 36: Mobile Devices

Demo: CoolNotes

• Register a scheme handler for : cnotes://!

• Add notes to app from another app or web

Page 37: Mobile Devices

What Next

• Both Android and iOS support attaching files to other applications

• That requires launching from a native app

Page 38: Mobile Devices

Online Resources

• Registering custom URL scheme on iOS: https://github.com/phonegap/phonegap/blob/master/lib/ios/guides/Cordova%20Custom%20URL%20Scheme%20Handling.md

• Registering custom URL scheme on Android:http://blog.cttapp.com/p/phonegap-handleopenurl-for-android/

Page 39: Mobile Devices

Q & A

Page 40: Mobile Devices

Background execution

Abusing a user’s phone when you’re not running

Page 41: Mobile Devices

iOS vs. Android

• iOS is more limited in background execution

• Both allow apps to run when not in background

Page 42: Mobile Devices

Android Services

• Non-GUI part of a program

• Can run while app is not active

• Can be used from other apps

Page 43: Mobile Devices

iOS Application States

• iOS4 Added support for background execution

Page 44: Mobile Devices

iOS Moving To Background

• By default all apps continue some sort of background activity

• Acting friendly is your responsibility

Page 45: Mobile Devices

Background Activity

• By default main thread of the application is suspended

• Other threads (network) keep working

• Demo

Page 46: Mobile Devices

Background Activity

• It’s possible to request main thread to stay active ~10 minutes after suspension

• Demo

Page 47: Mobile Devices

Background Activity

• Apps that integrate with OS services can request to handle events

• Services include: audio, location, voip, external-accessory, bluetooth, network fetch, remote notifications

Page 48: Mobile Devices

Discussion

• What are user’s expectations from apps running in the background ?

Page 49: Mobile Devices

Abusing Mobile Devices

• Keep GPS on while app not running

• Send small analytics network packets to your servers

• Perform CPU intensive tasks while app not running

Page 50: Mobile Devices

Q & A

Page 51: Mobile Devices

Thanks For Listening

• Ynon Perek

• http://ynonperek.com

[email protected]