Download - Mobile Devices
![Page 1: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/1.jpg)
Running On MobileHow mobile device is different from desktop, and what you can do about it
![Page 2: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/2.jpg)
Mobile Device Characteristics
• Always around
• Always connected
• Used for both urgent tasks and fun
![Page 3: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/3.jpg)
Users’ Expectations
• Battery lasts forever
• Apps work smoothly
• Seamless app switching
![Page 4: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/4.jpg)
Developer’s Perspective
• Interruptions will happen all the time
• Consider battery in everything you do
![Page 5: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/5.jpg)
Some stats
Android apps ad-serving responsible for
75% of app related battery drain
![Page 6: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/6.jpg)
Mobile Architecture• Application Sandbox
• Getting out:
• Using OS services
• Talking to other apps
• Background Execution
![Page 7: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/9.jpg)
Mobile Is Different
• Basic entity is the App
WhatsApp Mail Facebook
Mobile OS
![Page 10: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/10.jpg)
Mobile Apps Storage: iOS
![Page 11: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/11.jpg)
An app storage options
• Saving files on the file system
• Saving data in preferences (registry)
• Hybrid: Leverage browser storage
![Page 12: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/12.jpg)
HTML5 Storage
Online/Offline functionality Persistant storage
![Page 13: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/13.jpg)
Local Data Storage
• How do you store data on a client’s machine ?
![Page 14: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/14.jpg)
Cookies
![Page 15: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/17.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/18.jpg)
Q & A
![Page 19: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/19.jpg)
Offline Application
CacheDealing with low connectivity
(without stealing)
![Page 20: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/21.jpg)
Offline Web App
GET MANIFEST
CACHE MANIFEST index.html
style/main.css script/main.js
![Page 22: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/22.jpg)
Cache Manifest File
• Lists all the files that should be stored for offline access
• Enable with:<html manifest="example.appcache">
![Page 23: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/23.jpg)
Demo
• Application with a cache manifest
• Modifying manifest and updating
![Page 24: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/24.jpg)
Manifest - The Good
• Can store any file locally
• Provides offline/online app functionality
• Transparent to the user
![Page 25: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/25.jpg)
Manifest - The Bad
• Not suitable for data storage
• Complex update logic
![Page 26: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/26.jpg)
Sensitive Data Storage
• Both iOS and Android support a keychain
• Safe storage for sensitive data managed by the OS
![Page 27: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/27.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/28.jpg)
Pop Quiz
• Planning a twitter clone, what data would you store and how?
![Page 29: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/29.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/30.jpg)
Q & A
![Page 31: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/31.jpg)
Talking to Other Apps
![Page 32: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/32.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/33.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/34.jpg)
Solution: URL Schemes
Instagram iOSregister scheme
instag://
![Page 35: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/35.jpg)
Solution: URL Schemes
CoolCam open link
instag://photo/uploadiOS
iOS Instagraminstag://photo/upload
other request data
![Page 36: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/36.jpg)
Demo: CoolNotes
• Register a scheme handler for : cnotes://!
• Add notes to app from another app or web
![Page 37: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/37.jpg)
What Next
• Both Android and iOS support attaching files to other applications
• That requires launching from a native app
![Page 38: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/38.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/39.jpg)
Q & A
![Page 40: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/40.jpg)
Background execution
Abusing a user’s phone when you’re not running
![Page 41: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/41.jpg)
iOS vs. Android
• iOS is more limited in background execution
• Both allow apps to run when not in background
![Page 42: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/42.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/43.jpg)
iOS Application States
• iOS4 Added support for background execution
![Page 44: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/44.jpg)
iOS Moving To Background
• By default all apps continue some sort of background activity
• Acting friendly is your responsibility
![Page 45: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/45.jpg)
Background Activity
• By default main thread of the application is suspended
• Other threads (network) keep working
• Demo
![Page 46: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/46.jpg)
Background Activity
• It’s possible to request main thread to stay active ~10 minutes after suspension
• Demo
![Page 47: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/47.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/48.jpg)
Discussion
• What are user’s expectations from apps running in the background ?
![Page 49: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/49.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/50.jpg)
Q & A
![Page 51: Mobile Devices](https://reader033.vdocuments.us/reader033/viewer/2022051514/548e3032b4795949688b45bc/html5/thumbnails/51.jpg)
Thanks For Listening
• Ynon Perek
• http://ynonperek.com