$30 off During Our Annual Pro Sale. View Details »

From iOS to Android(or reverse)

From iOS to Android(or reverse)

From iOS to Android(or reverse)

jmortegac

April 26, 2015
Tweet

More Decks by jmortegac

Other Decks in Programming

Transcript

  1. MADRID · NOV 21-22 · 2014
    From iOS To Android(or reverse)
    José Manuel Ortega Candel
    @jmortegac
    http://www.linkedin.com/jmortega1

    View Slide

  2. MADRID · NOV 21-22 · 2014
    https://speakerdeck.com/jmortega/

    View Slide

  3. MADRID · NOV 21-22 · 2014
    ARCHITECTURE / iOS / ANDROID
    TOOLS XCODE vs ANDROID STUDIO
    APPLICATIONS / PERMISSIONS / PRIVACY
    USER INTERFACE
    STATIC ANALYSIS CODE / TESTING
    CERTIFICATES AND SIGNING
    EMULATORS / MEMORY MANAGEMENT/ DATABASE
    APP PUBLISHING / DEVELOPER LIBRARIES

    View Slide

  4. MADRID · NOV 21-22 · 2014
    ARCHITECTURE

    View Slide

  5. MADRID · NOV 21-22 · 2014
    Android Architecture
    DALVIK ART
    Just-In-Time (JIT) Compilation Ahead-Of-Time (AOT)
    Compilation
    Cache builds up over time
    Boot times are faster
    Cache is built at first boot
    Rebooting device takes
    significantly longer
    Apps compiled when executed Stores Compiled Apps
    Consumes much more internal
    storage space

    View Slide

  6. MADRID · NOV 21-22 · 2014
    iOS Architecture

    View Slide

  7. MADRID · NOV 21-22 · 2014
    TOOLS

    View Slide

  8. MADRID · NOV 21-22 · 2014
    IDES
    Android iOS
    https://developer.android.com/sdk/
    installing/studio.html
    APPCode
    http://www.jetbrains.com/objc/

    View Slide

  9. MADRID · NOV 21-22 · 2014
    on Android Studio
     InteliJ IDE Based
     Maven based Build Dependency
     Combines Ant && Maven / Gradle Tasks

    View Slide

  10. MADRID · NOV 21-22 · 2014
    Android Studio
     Templates

    View Slide

  11. MADRID · NOV 21-22 · 2014
    Android Studio
     Project settings

    View Slide

  12. MADRID · NOV 21-22 · 2014
    XCode
     Provides multiple ios app templates

    View Slide

  13. MADRID · NOV 21-22 · 2014
    Xcode Project
     Testing on device
     Base SDK

    View Slide

  14. MADRID · NOV 21-22 · 2014
    Interface Builder

    View Slide

  15. MADRID · NOV 21-22 · 2014
    Instruments on iOS
     Debugging, performance analysis, and testing
     Real-time CPU, memory, disk, energy, and network
    usage
     Threads, network, and energy usage
     I/O system and thread activity
     Allows detecting memory leaks

    View Slide

  16. MADRID · NOV 21-22 · 2014
    APPLICATIONS

    View Slide

  17. MADRID · NOV 21-22 · 2014
    Android Applications

    View Slide

  18. MADRID · NOV 21-22 · 2014
    Android Layout Manager+ Device Preview

    View Slide

  19. MADRID · NOV 21-22 · 2014
    Android Applications
    import android.os.Bundle;
    import android.app.Activity;
    public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);}
    }
    public static void invokeWebBrowser(Activity activity){
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.google.com"));
    activity.startActivity(intent);
    }
     Activity
     Intents [Explicit,Implicits]
     Services
     Content Providers[Sharing data between apps]
     Fragments from 3.0

    View Slide

  20. MADRID · NOV 21-22 · 2014
    Android components

    View Slide

  21. MADRID · NOV 21-22 · 2014
    Android’s RecyclerView
     Adapter
     ViewHolder
     LayoutManager
     ItemDecoration
     ItemAnimator
    https://developer.android.com/training/material/lists-cards.html

    View Slide

  22. MADRID · NOV 21-22 · 2014
    Android Navigation Drawer

    View Slide

  23. MADRID · NOV 21-22 · 2014
    Layout Systems
    UINavigationBar
    UITableView
    TextView
    TextView
    LinearLayout
    TextView
    TextView

    View Slide

  24. MADRID · NOV 21-22 · 2014
    LifeCycle Applications

    View Slide

  25. MADRID · NOV 21-22 · 2014
    LifeCycle Applications
    - (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
    }

    View Slide

  26. MADRID · NOV 21-22 · 2014
    iOS Applications
     C
     Objective –C,[message passing]
     Swift
     PlayGround for leaning Swift
     Programming with Objetive-C in windows/
    linux
     http://www.gnustep.org/
    https://developer.apple.com/swift

    View Slide

  27. MADRID · NOV 21-22 · 2014
    Objective-C vs Swift
    NSString *string = @“hello”;
    let string = "hello" as NSString
    let s: NSString = "hello"
    var string: NSString = "hello"
    string= "Hello"
    NSLog(@“This is a string”); println("This is a string");
    NSArray *myArray = [NSArray
    arrayWithObjects:@“string1",
    @“string2", nil];
    var myArray = [“string1", "string2"]
    var myArray : [String] =
    [“string1", "string2"]

    View Slide

  28. MADRID · NOV 21-22 · 2014
    iOS Applications
     @synthesize will generate getter and setter
    methods for your @property
    @interface MyObject:NSObject {
    NSString *_name;
    }
    @property (nonatomic,assign) NSString* name;
    @end
    @implementation MyObject
    @synthesize name = _ name;
    @end

    View Slide

  29. MADRID · NOV 21-22 · 2014
    UIKit Framework
     UIButton
     UILabel
     UIImageView
     UITextField
     UIPickerView
     UIWindow
     UIView
     UIViewController
     NSObject,NSString,NSMutableString, NSDate,NSNumber
     Collections(NSArray, NSDictionary, NSSet,NSEnumerator)
    Foundation Framework

    View Slide

  30. MADRID · NOV 21-22 · 2014
    iOS Applications
     UIViewController is the parent for view Controllers

    View Slide

  31. MADRID · NOV 21-22 · 2014
    iOS Applications
     Organizer

    View Slide

  32. MADRID · NOV 21-22 · 2014
    iOS Applications
     Snippets in XCode

    View Slide

  33. MADRID · NOV 21-22 · 2014
    iOS Applications

    View Slide

  34. MADRID · NOV 21-22 · 2014
    iOS Applications
    #import
    @interface MyViewController : UIViewController UITableViewDelegate>{
    IBOutlet UITableView *table;
    NSMutableData *dataReceive;
    }
    @property(nonatomic,assign) NSMutableData *dataReceive;
    @end
     UIViewController interface MyViewController.h
     implementation MyViewController.m
    @implementation MyViewController
    @synthesize dataReceive,table;
    - (void)viewDidLoad{
    [super viewDidLoad];
    NSURL *url = [[NSURL alloc] initWithString:@“url"];
    self.dataReceive = [[NSMutableData data] retain];
    }

    View Slide

  35. MADRID · NOV 21-22 · 2014
    iOS Applications
     UINavigationController

    View Slide

  36. MADRID · NOV 21-22 · 2014
    iOS Applications
     UINavigationController
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
    *)launchOptions {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    //Recuperamos el ViewController
    UIViewController *rootViewController = [storyboard instantiateInitialViewController];
    // Creamos un UINavigationController, que se encargará de controlar y almacenar los distintos
    viewControllers de nuestra aplicación.
    UINavigationController *navigationController = [[UINavigationController
    alloc]initWithRootViewController:rootViewController];
    //Asignamos el navigationController como principal.
    self.window.rootViewController = navigationController; return YES;
    }
    -(IBAction)goToPantalla2:(id)sender {
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    //Obtenemos el controlador con Identifier "Pantalla2"
    Pantalla2ViewController *pantalla2Controller = [storyBoard
    instantiateViewControllerWithIdentifier:@"Pantalla2"];
    //Lanzamos el controlador en el navigation de forma animada:
    [self.navigationController pushViewController:pantalla2Controller animated:YES]; }

    View Slide

  37. MADRID · NOV 21-22 · 2014
    Design patterns on iOS Applications
     MVC
     Target-action
     Delegate and protocols
    A delegate is an object that control of the user interface for that event.

    View Slide

  38. MADRID · NOV 21-22 · 2014
    ViewPager / UIPageViewController
     Swipe gesture

    View Slide

  39. MADRID · NOV 21-22 · 2014
    Multilanguage
    NSString *localizedString =
    NSLocalizedString(@"Hello",@“DefaultString");

    View Slide

  40. MADRID · NOV 21-22 · 2014
    Certificates and Signing
    Android iOS
    Self-signed certificate
    Apps are signed by
    developers
    Apple certificate
    Apps are signed by Apple
    Java Keytool Generate a distribution
    provisioning profile
    Export + Sign APK iOS Provisioning Portal
    Debug and distribution
    certificate
    App ID (unique ID of your app)
    Set of device unique identifiers
    Developer certificate

    View Slide

  41. MADRID · NOV 21-22 · 2014
    Android Studio
     Export + Sign APK

    View Slide

  42. MADRID · NOV 21-22 · 2014
    PERMISSIONS

    View Slide

  43. MADRID · NOV 21-22 · 2014
    Permissions on Android
     AndroidManifest.xml
     Protection mechanism to interact with other
    applications

    android:name="android.permission.ACCESS_NETWORK_STATE"/>
    android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    android:name="android.permission.ACCESS_FINE_LOCATION"/>
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    View Slide

  44. MADRID · NOV 21-22 · 2014
    Permissions on iOS
    o Declare your application requirements in its manifest-like Info.plist.
    This is used only for ensuring device compatibility.
    o UIRequiredDeviceCapabilities allows you to list
    ’hardware-like’ capabilities that your app needs.
    o AppStore reads this information for filter installer
    devices.

    View Slide

  45. MADRID · NOV 21-22 · 2014
    Permissions on iOS
     Privacy Analysis Tools for iOs Applications
     patia.unileon.es

    View Slide

  46. MADRID · NOV 21-22 · 2014
    Privacy
    Permission Manager

    View Slide

  47. MADRID · NOV 21-22 · 2014
    USER
    INTERFACE

    View Slide

  48. MADRID · NOV 21-22 · 2014
    Evolution

    View Slide

  49. MADRID · NOV 21-22 · 2014
    Android Material design
     Minimalist and consistency
     Transitions, animiations
     Cards
    https://developer.android.com/training/material/get-started.html

    View Slide

  50. MADRID · NOV 21-22 · 2014
    Android Material design
     Ldrawer
     https://github.com/kanytu/android-material-drawer-template
    https://github.com/IkiMuhendis/LDrawer


    parent="android:Theme.Material.Light">

    @color/primary

    @color/primary_dark

    @color/accent

    @color/text_primary

    @color/text_secondary

    @color/primary_dark

    View Slide

  51. MADRID · NOV 21-22 · 2014
    Android Material design
     https://github.com/google/iosched

    View Slide

  52. MADRID · NOV 21-22 · 2014
    Android Fragments
     Fragment is a chunk of user interface with its own life cycle.
     Fragment must exist within an Activity
     Interaction with fragments is done through FragmentManager
     Fragment API was introduced in API 11
     http://developer.android.com/tools/support-library

    View Slide

  53. MADRID · NOV 21-22 · 2014
    Android Fragments

    View Slide

  54. MADRID · NOV 21-22 · 2014
    iOS
     Master-Detail template
     UISplitViewController

    View Slide

  55. MADRID · NOV 21-22 · 2014
    Notifications

    View Slide

  56. MADRID · NOV 21-22 · 2014
    STATIC
    ANALYSIS CODE

    View Slide

  57. MADRID · NOV 21-22 · 2014
    Static analysis code on Android Studio
     Inspect Profile
     Lint

    View Slide

  58. MADRID · NOV 21-22 · 2014
    Static analysis code on Java projects
     SonarQube
     Sonnar-runner

    View Slide

  59. MADRID · NOV 21-22 · 2014
    Static analysis code on XCode
     Static Analyzer
     Detect memory leaks

    View Slide

  60. MADRID · NOV 21-22 · 2014
    TESTING

    View Slide

  61. MADRID · NOV 21-22 · 2014
    Mobile Application Testing
    TYPES
    Unit Testing
    Functionality
    Testing
    Integration
    Testing
    Regression Load Testing
    Stress
    Testing
    Performance
    Usability
    Testing

    View Slide

  62. MADRID · NOV 21-22 · 2014
    Mobile Application Testing

    View Slide

  63. MADRID · NOV 21-22 · 2014
    CheckList
     Rotating the screen
     Behavior of when network is not
    available
     Navigation between screens
     Behavior of app if app is running for
    longer period of time and checking
    memory

    View Slide

  64. MADRID · NOV 21-22 · 2014
    Testing on Android
     Unit & Integration,TDD
     Junit
     RoboElectric
     Acceptance,BDD
     RobotiumTesting User Interface
     Calabash

    View Slide

  65. MADRID · NOV 21-22 · 2014
    Unit testing on iOS
     XCTest
    #import
    #import “TestObject.h"
    @interface TestOjectLogicTests : XCTestCase {
    @private
    TestObject *object;
    }
    @end

    View Slide

  66. MADRID · NOV 21-22 · 2014
    EMULATORS

    View Slide

  67. MADRID · NOV 21-22 · 2014
    Emulator vs Simulator
    Android iOS
    Emulator Simulator
    Very slow integrated with SDK Integrated with Xcode
    Emulates hardware and software Simulates only software
    Launched apps are equal
    binaries from the apps compiled
    for Device CPU
    Launched apps are different
    binaries from the apps compiled
    for Device CPU

    View Slide

  68. MADRID · NOV 21-22 · 2014
    Genymotion
     Integration with Eclipse and Android Studio
     MULTI OS Compatible with Linux,Windows and Mac
     Requires VirtualBox

    View Slide

  69. MADRID · NOV 21-22 · 2014
    Alternatives
     http://jimulabs.com/ for Android live preview
     https://appthwack.com/ for testing in the cloud with real
    devices

    View Slide

  70. MADRID · NOV 21-22 · 2014
    MEMORY
    MANAGEMENT

    View Slide

  71. MADRID · NOV 21-22 · 2014
     Android
    Handles memory management
    automatically
    Garbage Collector
     iOS
    release, retain, autorelease
    ARC(Automatic Reference Counting)
     Developer maintain the count number for each object
     Destroys object when reference counting become 0
     @autoreleasepool
     With ARC, compiler set this methods where its
    necessary

    View Slide

  72. MADRID · NOV 21-22 · 2014
    ARC
     Migrating to ARC
     Project Build Settings

    View Slide

  73. MADRID · NOV 21-22 · 2014
    DATA
    PERSISTENCE

    View Slide

  74. MADRID · NOV 21-22 · 2014
    Android iOS
    SQLite
    android.database.sqlite
     Tables and relations
    Core Data
     Objects
     DataModel
    Content Providers
    /data/data/
    /databases/
    Only acces with root
    DataModel editor in Xcode for
    register objects and their
    relationships

    View Slide

  75. MADRID · NOV 21-22 · 2014
    iOS Core Data

    View Slide

  76. MADRID · NOV 21-22 · 2014
    Alernatives
    http://realm.io/
    Android and iOS
    Object-oriented API
    C++ Core

    View Slide

  77. MADRID · NOV 21-22 · 2014
    SHARED
    ACTIONS

    View Slide

  78. MADRID · NOV 21-22 · 2014
    Android


    android:id="@+id/share"
    android:title="@string/share"
    android:showAsAction="ifRoom"
    android:actionProviderClass="android.widget.ShareActionProvider"/>

    private ShareActionProvider mShareActionProvider;
    mShareActionProvider.setShareIntent(getDefaultShareIntent());
    private Intent getDefaultShareIntent(){
    Intent intent = new Intent(Intent.ACTION_SEND); //IMPLICIT INTENT
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT,"Extra Text");
    return intent;}

    View Slide

  79. MADRID · NOV 21-22 · 2014
    iOS
    - (IBAction)shareButton:(UIBarButtonItem *)sender
    {
    NSString *textToShare = @“textToShare";
    UIImage *imageToShare = [UIImage imageNamed:@"yourImage.png"];
    NSURL *myWebsite = [NSURL
    URLWithString:@"http://www.example.com/"];
    NSArray *objectsToShare = @[textToShare, imageToShare ,myWebsite];
    UIActivityViewController *activityVC = [[UIActivityViewController
    alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
    NSArray *excludeActivities =
    @[UIActivityTypeAirDrop,UIActivityTypePrint];
    activityVC.excludedActivityTypes = excludeActivities;
    [self presentViewController:activityVC animated:YES completion:nil];
    }
     UIActivityViewController

    View Slide

  80. MADRID · NOV 21-22 · 2014
    CHECK
    CONNECTIVITY

    View Slide

  81. MADRID · NOV 21-22 · 2014
    Check connectivity on Android
     ConnectivityManager
    android:name="android.permission.ACCESS_NETWORK_STATE" />

    public static boolean checkConnectivity(Context context) {
    ConnectivityManager cm
    =(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    }

    View Slide

  82. MADRID · NOV 21-22 · 2014
    Check connectivity on iOS
     Reachability
    internetReach = [[Reachability reachabilityForInternetConnection]
    retain];
    [internetReach startNotifier];
    if([internetReach currentReachabilityStatus] == ReachableViaWWAN) {
    // Tenemos conexión a Internet
    }
    wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
    [wifiReach startNotifier];
    if([wifiReach currentReachabilityStatus] == ReachableViaWiFi) {
    // Estamos conectados mediante Wi-Fi
    }

    View Slide

  83. MADRID · NOV 21-22 · 2014
    APP
    PUBLISHING

    View Slide

  84. MADRID · NOV 21-22 · 2014
    Android iOS
    Google requires a one time fee of
    US$25
    iOS Developer Program
    $99 /year
    Greater capacity for monetization
    Google play + Publish in other
    stores like Amazon,Opera
    AppStore
    Alpha/beta testing before put in
    production
    Upload to store in 30 min
    Review process 5-7 days
    Android Developer
    Console
    Beta Testing
    http://ibetatest.com/
    http://testflightapp.com/

    View Slide

  85. MADRID · NOV 21-22 · 2014
     Distribution

    View Slide

  86. MADRID · NOV 21-22 · 2014
    Developers
    Library

    View Slide

  87. MADRID · NOV 21-22 · 2014
    Async connections
     iOS
     Thread managed by NSURLConnection
     Android
     Services, AsyncTask
     Libraries for Android
     Otto Event Bus,RoboSpice
     http://square.github.io/otto/

    View Slide

  88. MADRID · NOV 21-22 · 2014
    https://play.google.com/store/apps/details?id=com.desarrollodroide.repos
     Android libraries with demos in GP

    View Slide

  89. MADRID · NOV 21-22 · 2014
    https://developer.apple.com/library/ios/navigation/
     iOS Developer library

    View Slide

  90. MADRID · NOV 21-22 · 2014
     Classes comparative
    iOS Android
    Base UIApplication Application
    Controller UIViewController Activity/Fragment
    Event Emitter Target Action/Responder
    Chain
    Event Listener i.e. onClick()
    Data Saving NSUserDefaults / SQLite SharedPreferences / SQLite
    Multi Thread NSThread Thread/AsyncTask/Service
    Internationalization NSLocalizedString Resource files
    GPS CoreLocation LocationManager
    for MapView, use Google
    SDK
    Accelerometer UIAccelerometer SensorManager
    Local Notification UILocalNotification NotificationManager
    Remote Push
    Notification
    Apple Push Notifiation Service C2DM (external package)
    com.google.android.c2dm

    View Slide

  91. MADRID · NOV 21-22 · 2014
    BOOKS

    View Slide

  92. MADRID · NOV 21-22 · 2014

    View Slide

  93. MADRID · NOV 21-22 · 2014
    References
    o www.developer.android.com
    o http://www.google.com/design/spec/material-design/
    introduction.html
    o http://tools.android.com/
    o https://android-arsenal.com/
    o http://android-developers.blogspot.com.es/
    o www.developer.apple.com
    o https://developer.apple.com/videos/wwdc/
    o https://developer.apple.com/library/ios/referencelibrary/Getting
    Started/RoadMapiOS/

    View Slide

  94. MADRID · NOV 21-22 · 2014
    Thanks
    Questions?

    View Slide