SlideShare uma empresa Scribd logo
1 de 60
Baixar para ler offline
Sviluppo di app mobile con
      MonoTouch e
    Mono for Android


• Stefano Ottaviani
  ‣ steott@gmail.com
  ‣ @ste8



                             1
Cos’è TechBar
                  Bar


“Se ascolto dimentico, se vedo
ricordo, se faccio capisco” – Confucio




                                         2
Conosciamoci un po’
• Chi ha utilizzato MonoTouch o Mono
  for Android? In produzione? Chi ha
  idea di cosa si tratta?

• Che ambiente avete dietro?

• Chi conosce già gli ambienti nativi
  iOS e Android?

• Chi conosce il .NET Framework?
    3




                                        3
Chi sono?
• Dev / SEng @ KILOG Srl
  ‣ Da Palm OS a iPad, passando per Windows CE / Mobile
      (C++, .NET CF)


• Communities
  ‣ DotNetMarche, XPUG Marche


• Contatti
  ‣        steott@gmail.com
  ‣        @ste8
       4
  ‣        blogs.ugidotnet.org/ste8



                                                          4
5
Cosa devo sviluppare?             (1/2)



• App LOB (Line of Business)
  ‣ Online e soprattutto OFFLINE
    ✴Non si vive di soli servizi!


• Device:iPhone e iPad come riferimenti
  ‣ ma ci sono anche Android, WP7, netbook


• UX usabile e attraente!
    6




                                             6
Cosa devo sviluppare?               (2/2)



• Performante
  ‣ L’exe non deve essere per forza piccolo

• Controllo sul deploy dell’app

• Ridurre potenziali problemi x sviluppo
  ‣ No puntatori & rilascio memoria

    7




                                              7
Considerazioni sullo
         sviluppo
     Cross Platform


8




                           8
La UI va rifatta...o no?             (1/5)



      Esempio MIX11 App
        http://tinyurl.com/442vt3t

                iPhone




 9




                                             9
La UI va rifatta...o no?             (2/5)



      Esempio MIX11 App
        http://tinyurl.com/442vt3t

                  WP7




 10




                                             10
La UI va rifatta...o no?             (3/5)



      Esempio MIX11 App
        http://tinyurl.com/442vt3t

                Android




 11




                                             11
La UI va rifatta...o no?                                (4/5)



  Ipse dixit: Martin Fowler
  http://martinfowler.com/bliki/CrossPlatformMobile.html


  To summarize:

• Don't use cross-platform toolkits
• For maximum reach: built a web app that looks
  like web app
• To appeal to a particular platform: build a native
  app 12 that platform, with a experience design
       for
  based on that platforms interaction style

                                                                   12
La UI va rifatta...o no?           (5/5)



Ste dixit: ma almeno riutilizziamo la
logica di business e di accesso dati...

          ... soprattutto in app offline!

    Riscrivere il codice in linguaggi
    diversi per ogni piattaforma è
   13
            molto costoso!

                                            13
Che strumenti abbiamo?                         (1/2)



• Objective-C (nativo per iOS)
  ‣ learning curve ulteriore x il linguaggio
  ‣ target: “solo” iPhone, iPad, Mac OS X



• Java (nativo per Android)
  ‣ minore learning curve x il linguaggio
  ‣ target: dove gira Java (no iOS)



     14




                                                       14
Che strumenti abbiamo?                                        (2/2)



• HTML 5 + JavaScript
  ‣ “Pure Web” (jQuery Mobile, ...)
  ‣ “Native Wrapper” (PhoneGap)

• “Write Once Run Anywhere”
  ‣ es. Titanium Appcelerator

• ”Cross-platform Core”
  ‣ es. MonoTouch & Mono for Android
     15
          Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp


                                                                          15
Con la diffusione di HTML5 e js...


                              pazzi?
                   Ma si   am
          aga zzi!
Oh      r
              ok, ma fare tutto in HTML5/JS è
            come fare cibo vegerariano perchè
                così lo mangiano (quasi) tutti
   16
                            (cit. @alexbream)

                                             16
Quando usare
“Cross-platform Core” approach

 If your application will contain a
 significant amount of business
 logic or will have lots of back-end
 service interatactions (rather than
 being focussing mostly on
 presentation logic) but you still
 want a very native feel then a
 Cross-Platform Core may be the best
 way to go.
   17




                                       17
Side effect del
“Cross-platform Core” approach
• nicely layered architecture

• non-presentation logic which is easy
  to get under solid test coverage




    18   Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp




                                                                         18
Cos’è MonoTouch? (1/3)
• Come Mono... ma diverso!
  ‣ Suite per portare C# e .NET su iPhone!

• Alcune limitazioni da ambiente Apple
  ‣ Usa compilazione statica (AOT, Ahead of
    Time) invece che a runtime (JIT)
    • http://www.mono-project.com/AOT

  ‣ No generazione codice
    • Reflection.Emit, DLR, Generic Virtual
    19

      Methods

                                              19
Cos’è MonoTouch? (2/3)
• MonoDevelop + XCODE 4 per UI

• Cosa c’è
  ‣ C# 4
  ‣ Garbage Collection
  ‣ LINQ / Lamba
  ‣ Generics
  ‣ Reflection / Static Reflection
  ‣ WCF
  ‣ Parallel Framework
  ‣ Async nelle prossime versioni (Mono 2.11)
     20




                                                20
Cos’è MonoTouch? (3/3)
• Thin layer sopra le API native
  ‣ rapidità di aggiornamento all’iOS SDK
  ‣ binding x utilizzo librerie Objective-C

‣ learning curve: conoscere le basi
  dell’ambiente nativo
  – Oltre alle HIG (Human Interface Guidelines)
  – Infrastruttura (view controllers, ...)
  – saper almeno leggere Objective-C
     21
• Prezzo:pro o contro?

                                                  21
Soddisfa i miei bisogni?            (1/3)



• App LOB (Line of Business)
  ‣ Online e soprattutto OFFLINE
    - Non si vive di soli servizi!
  ✴Si... e fa molto altro!

• Device:iPhone e iPad come riferimenti
  ‣ ma ci sono anche Android, WP7, netbook
  ✴Posso condividere BIZ e DAL!
    22




                                             22
Soddisfa i miei bisogni?                             (2/3)



• UX usabile e attraente!
  ✴Stesse possibilità di Objective-C (IB)

• Performante
  ‣ L’exe non deve essere per forza piccolo
  ✴Compilazione “nativa”, LLVM compiler
  ✴iCircuit test: http://news.ycombinator.com/item?id=2557047

• Controllo sul deploy dell’app
     23
  ✴Stesse possibilità di Objective-C!

                                                                23
Soddisfa i miei bisogni?              (3/3)



• Ridurre potenziali problemi x sviluppo
  ‣ No puntatori & rilascio memoria
  ✴C# e Garbage Collector => No puntatori!
  ✴Non è tutto oro...attenti ai memory leak!
    ✴Ora è fornito anche un profiler




    24




                                               24
Chi c’è dietro a
       MonoTouch e
     Mono for Android?


25




                          25
1 anno fa...
      Quale sarà il futuro di MT?

                                   No P anic

                                     Can	
  we	
  conDnue	
  
                                       working	
  with	
  
                                       MonoTouch?
   All	
  technology	
  
roadmaps	
  remain	
  
          intact
                                   You	
  should,	
  yes.	
  It	
  will	
  
                                      be	
  compaDble.
                26




                                                                              26
Xamarin oggi       (1/5)



• > 30 persone (di cui circa 20 del
  team Mono)

• Diverse posizioni aperte (Developer
  Evangelist/Advocate, Mobile Dev, ...)

• “We have competitive salary and
  benefits. We’re growing fast and are
  cash-flow positive”
    27




                                          27
Xamarin oggi                   (2/5)



• Numerosi rilasci
 (es. MonoTouch dalla 4.0.4.1 di Luglio alla 5.3.*)



• Compatibile in ~ 24 h dal rilascio di
  SDK Apple e Android

• Mailing list abbastanza frequentata
     28




                                                      28
Xamarin oggi                  (3/5)



• “Our main products are Mono on iOS
  and Mono on Android.” ...

• ... e molti altri progetti
  ‣ http://tirania.org/blog/archive/2011/Dec-21.html
  ‣ Mono, Sony PSSuite, Google Native Client, Compiler as a
    Service, Unity3D, MonoGame, MonoDevelop,
    XobotOS ...


     29




                                                              29
Xamarin oggi                          (4/5)



• Xamarin Identified as a Leader in Mobile
  Cross-Platform Application Development
  Tools




    30   Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/




                                                                               30
Xamarin oggi                          (5/5)




31
     Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/


                                                                      31
Come abbiamo organizzato
   il nostro progetto?



  32




                           32
Architettura
• Server (Web API, IIS)

• Client (iPad)

• Biz e DAL in comune

• Tool ‘home made’ per sincronizzare i
  progetti
    33




                                         33
Risorse per iniziare
• 2 Video da NDC 2010
  ‣ http://tekpub.com/conferences/ndc2010


• Stack Overflow / Mailing List

• Esempi: galleria su xamarin.com

• Libri
     34




                                            34
Ingredienti per iniziare
• Un computer Mac con Mac OS X

• iPhone SDK

• MonoTouch (+ Mono)
  – Simulator only (free), studenti (99$),
    Professional (399$), Enterprise (999$)

• MonoDevelop
    35




                                             35
Configurazione ambiente
• Boot Camp + Parallels =
  stessa (ma unica) partizione Windows

• Shortcuts per
  ‣ Mac OS X
  ‣ Windows da Parallels
  ‣ MonoDevelop

    36




                                         36
Visual Studio come IDE              (1/2)



• Perchè vorrei farlo?
  ‣ IDE migliore / Resharper, ...

• Si può fare! (cit)
  ‣ o quasi.... solo build, NO RUN

• Non solo per progetti BIZ e DAL,
  anche per UI
    37




                                             37
Visual Studio come IDE                   (2/2)



• Soluzione funzionante:
  ‣ https://github.com/follesoe/VSMonoTouch
  ‣ (anche su nuget)




    38




                                                  38
Poniamo le basi...

     ...per costruire la prima App!




39




                                      39
Cocoa Touch: il Framework
• Cocoa : .NET FX = Objective-C : C#

• Foundation
  ‣ objects, memory, ...

• UIKit, GameKit, MapKit, ...

• Intro per .Net Dev:
       40
  ‣   http://www.kevfoo.com/2011/05/quick-primer-cocoa-and-cocoa-touch/




                                                                          40
Window e Views
• Application / AppDelegate
  ‣ main, ...
  ‣ 10 secondi per caricare!

• Window
  ‣ 1 sola per App!!! Poi coi ViewControllers...

• View (UIView)
  ‣ Base per UI Controls (Button, Textbox, ...)
     41
  ‣ Base per User Control! No ViewController

                                                   41
1° Demo!
• Usare MonoDevelop (anche più istanze)
• Creare UI con / senza Interface Builder
• Utilizzo di immagini / risorse
• Creazione di custom control con UIView
• Utilizziamo le tabelle




      42




                                            42
ViewControllers
• Basato su MVC (o una specie...)

• Creazione di app con più screen
  ‣ Navigation
  ‣ Resize, orientamento

• “Infrastruttura” per UI Controls
  ‣ es. TableViewController
    43




                                     43
Esempi di ViewController   (1/4)



        TabBarController




  44




                                   44
Esempi di ViewController      (2/4)



       NavigationController




  45




                                      45
Esempi di ViewController            (3/4)



 SplitViewController / PopoverController




   46




                                            46
Esempi di ViewController     (4/4)



       TableViewController




  47




                                     47
2° Demo!
• Creare una form con UIViewController
• Resize e rotazione form
• Anchor e docking
• App con più form grazie ai ViewController.




      48




                                               48
Altri approcci per UI
• Tentativi di MVVM

• DSL?   (Domain-specific language)

  ‣ iCircuit:
   http://praeclarum.org/post/1520024382/interfaces-
   caches-cross-platform


  ‣ Post Antonio Ganci:
   http://blogs.ugidotnet.org/AntonioGanci/archive/
   2010/04/19/un-approccio-per-ottenere-una-
   architettura-malleabile.aspx
    49




                                                       49
Accesso ai dati locali (1/2)
• SQLite
  ‣ portabilità in altre piattaforme??
  ‣ Repository / DAO pattern? ORM?

• Tipi di accesso
  ‣ ADO.NET
  ‣ API di SQLite dirette
  ‣ ORM (es. Vici CoolStorage)
    50




                                         50
Accesso ai dati locali (2/2)
• Performance Tips
  ‣ DataReader via GetString, GetInt, ..
   http://www.bayshield.com/2010/6/29/monotouch-sqlite-
   performance-tip


  ‣ Uso di transazioni e connection pooling

  ‣ Quantificazione costi reflection (se usata)
   http://praeclarum.org/post/1572668275/quantifying-
   reflections-slowdown-in-sqlite-net
    51




                                                          51
Accesso ai dati remoti
• ASMX Web Service e WCF
  come in Silverlight

• REST via HttpRequest / Response

• JSON
  ‣ https://github.com/chrisntr/Newtonsoft.Json


     52




                                                  52
IoC / DI
• Diverse librerie
  ‣ TinyIoC (funziona :)

  ‣ OpenNETCF.IoC

  ‣ Funq, PicoContainer

  ‣ http://monotouch.info/Tags/IoC
    53




                                     53
Unit Testing
• Ora supporto per girare su device

• Testare la business logic / DAL

• Testare l’”MVC” Apple:
  ‣ Supervisor Controller
   http://ben.phegan.name/index.php/2011/02/28/
   monotouch-and-unit-testing/
    54




                                                  54
Alcune librerie di supporto                                             (1/2)



• MonoTouch.Dialog
  ‣   https://github.com/migueldeicaza/MonoTouch.Dialog



• MonoCross
  ‣ Stile MVC di ASP.NET MVC
  ‣   http://code.google.com/p/monocross/



• MvvmCross
  ‣   https://github.com/slodge/MvvmCross
  ‣   ATTENZIONE: Future direction (Under consideration): More tablet
       55
      support - for iPad, for Windows Metro and for Android



                                                                                55
Alcune librerie di supporto                                                   (1/2)



• ReactiveUX per MonoTouch
  ‣   http://code.google.com/p/proactive-framework/



• Localizzazione
  ‣   https://github.com/rdio/vernacular



• Event Aggregator (Message Broker)
  ‣   http://merbla.blogspot.com/2011/03/monotouch-and-eventaggregator.html



• Xamarin Mobile API
       56




                                                                                      56
Alcuni tool di supporto
• Workspace Reloader
  ‣   http://bit.ly/JM3FZe



• SourceTree
  ‣   http://www.sourcetreeapp.com/




       57




                                      57
Troubleshooting
• Eccezioni compilatore AOT

• Altro?




    58




                              58
Domande?




59




                59
Grazie!




60




               60

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Sviluppo di applicazioni mobile con MonoTouch e Mono for Android

  • 1. Sviluppo di app mobile con MonoTouch e Mono for Android • Stefano Ottaviani ‣ steott@gmail.com ‣ @ste8 1
  • 2. Cos’è TechBar Bar “Se ascolto dimentico, se vedo ricordo, se faccio capisco” – Confucio 2
  • 3. Conosciamoci un po’ • Chi ha utilizzato MonoTouch o Mono for Android? In produzione? Chi ha idea di cosa si tratta? • Che ambiente avete dietro? • Chi conosce già gli ambienti nativi iOS e Android? • Chi conosce il .NET Framework? 3 3
  • 4. Chi sono? • Dev / SEng @ KILOG Srl ‣ Da Palm OS a iPad, passando per Windows CE / Mobile (C++, .NET CF) • Communities ‣ DotNetMarche, XPUG Marche • Contatti ‣ steott@gmail.com ‣ @ste8 4 ‣ blogs.ugidotnet.org/ste8 4
  • 5. 5
  • 6. Cosa devo sviluppare? (1/2) • App LOB (Line of Business) ‣ Online e soprattutto OFFLINE ✴Non si vive di soli servizi! • Device:iPhone e iPad come riferimenti ‣ ma ci sono anche Android, WP7, netbook • UX usabile e attraente! 6 6
  • 7. Cosa devo sviluppare? (2/2) • Performante ‣ L’exe non deve essere per forza piccolo • Controllo sul deploy dell’app • Ridurre potenziali problemi x sviluppo ‣ No puntatori & rilascio memoria 7 7
  • 8. Considerazioni sullo sviluppo Cross Platform 8 8
  • 9. La UI va rifatta...o no? (1/5) Esempio MIX11 App http://tinyurl.com/442vt3t iPhone 9 9
  • 10. La UI va rifatta...o no? (2/5) Esempio MIX11 App http://tinyurl.com/442vt3t WP7 10 10
  • 11. La UI va rifatta...o no? (3/5) Esempio MIX11 App http://tinyurl.com/442vt3t Android 11 11
  • 12. La UI va rifatta...o no? (4/5) Ipse dixit: Martin Fowler http://martinfowler.com/bliki/CrossPlatformMobile.html To summarize: • Don't use cross-platform toolkits • For maximum reach: built a web app that looks like web app • To appeal to a particular platform: build a native app 12 that platform, with a experience design for based on that platforms interaction style 12
  • 13. La UI va rifatta...o no? (5/5) Ste dixit: ma almeno riutilizziamo la logica di business e di accesso dati... ... soprattutto in app offline! Riscrivere il codice in linguaggi diversi per ogni piattaforma è 13 molto costoso! 13
  • 14. Che strumenti abbiamo? (1/2) • Objective-C (nativo per iOS) ‣ learning curve ulteriore x il linguaggio ‣ target: “solo” iPhone, iPad, Mac OS X • Java (nativo per Android) ‣ minore learning curve x il linguaggio ‣ target: dove gira Java (no iOS) 14 14
  • 15. Che strumenti abbiamo? (2/2) • HTML 5 + JavaScript ‣ “Pure Web” (jQuery Mobile, ...) ‣ “Native Wrapper” (PhoneGap) • “Write Once Run Anywhere” ‣ es. Titanium Appcelerator • ”Cross-platform Core” ‣ es. MonoTouch & Mono for Android 15 Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp 15
  • 16. Con la diffusione di HTML5 e js... pazzi? Ma si am aga zzi! Oh r ok, ma fare tutto in HTML5/JS è come fare cibo vegerariano perchè così lo mangiano (quasi) tutti 16 (cit. @alexbream) 16
  • 17. Quando usare “Cross-platform Core” approach If your application will contain a significant amount of business logic or will have lots of back-end service interatactions (rather than being focussing mostly on presentation logic) but you still want a very native feel then a Cross-Platform Core may be the best way to go. 17 17
  • 18. Side effect del “Cross-platform Core” approach • nicely layered architecture • non-presentation logic which is easy to get under solid test coverage 18 Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp 18
  • 19. Cos’è MonoTouch? (1/3) • Come Mono... ma diverso! ‣ Suite per portare C# e .NET su iPhone! • Alcune limitazioni da ambiente Apple ‣ Usa compilazione statica (AOT, Ahead of Time) invece che a runtime (JIT) • http://www.mono-project.com/AOT ‣ No generazione codice • Reflection.Emit, DLR, Generic Virtual 19 Methods 19
  • 20. Cos’è MonoTouch? (2/3) • MonoDevelop + XCODE 4 per UI • Cosa c’è ‣ C# 4 ‣ Garbage Collection ‣ LINQ / Lamba ‣ Generics ‣ Reflection / Static Reflection ‣ WCF ‣ Parallel Framework ‣ Async nelle prossime versioni (Mono 2.11) 20 20
  • 21. Cos’è MonoTouch? (3/3) • Thin layer sopra le API native ‣ rapidità di aggiornamento all’iOS SDK ‣ binding x utilizzo librerie Objective-C ‣ learning curve: conoscere le basi dell’ambiente nativo – Oltre alle HIG (Human Interface Guidelines) – Infrastruttura (view controllers, ...) – saper almeno leggere Objective-C 21 • Prezzo:pro o contro? 21
  • 22. Soddisfa i miei bisogni? (1/3) • App LOB (Line of Business) ‣ Online e soprattutto OFFLINE - Non si vive di soli servizi! ✴Si... e fa molto altro! • Device:iPhone e iPad come riferimenti ‣ ma ci sono anche Android, WP7, netbook ✴Posso condividere BIZ e DAL! 22 22
  • 23. Soddisfa i miei bisogni? (2/3) • UX usabile e attraente! ✴Stesse possibilità di Objective-C (IB) • Performante ‣ L’exe non deve essere per forza piccolo ✴Compilazione “nativa”, LLVM compiler ✴iCircuit test: http://news.ycombinator.com/item?id=2557047 • Controllo sul deploy dell’app 23 ✴Stesse possibilità di Objective-C! 23
  • 24. Soddisfa i miei bisogni? (3/3) • Ridurre potenziali problemi x sviluppo ‣ No puntatori & rilascio memoria ✴C# e Garbage Collector => No puntatori! ✴Non è tutto oro...attenti ai memory leak! ✴Ora è fornito anche un profiler 24 24
  • 25. Chi c’è dietro a MonoTouch e Mono for Android? 25 25
  • 26. 1 anno fa... Quale sarà il futuro di MT? No P anic Can  we  conDnue   working  with   MonoTouch? All  technology   roadmaps  remain   intact You  should,  yes.  It  will   be  compaDble. 26 26
  • 27. Xamarin oggi (1/5) • > 30 persone (di cui circa 20 del team Mono) • Diverse posizioni aperte (Developer Evangelist/Advocate, Mobile Dev, ...) • “We have competitive salary and benefits. We’re growing fast and are cash-flow positive” 27 27
  • 28. Xamarin oggi (2/5) • Numerosi rilasci (es. MonoTouch dalla 4.0.4.1 di Luglio alla 5.3.*) • Compatibile in ~ 24 h dal rilascio di SDK Apple e Android • Mailing list abbastanza frequentata 28 28
  • 29. Xamarin oggi (3/5) • “Our main products are Mono on iOS and Mono on Android.” ... • ... e molti altri progetti ‣ http://tirania.org/blog/archive/2011/Dec-21.html ‣ Mono, Sony PSSuite, Google Native Client, Compiler as a Service, Unity3D, MonoGame, MonoDevelop, XobotOS ... 29 29
  • 30. Xamarin oggi (4/5) • Xamarin Identified as a Leader in Mobile Cross-Platform Application Development Tools 30 Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/ 30
  • 31. Xamarin oggi (5/5) 31 Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/ 31
  • 32. Come abbiamo organizzato il nostro progetto? 32 32
  • 33. Architettura • Server (Web API, IIS) • Client (iPad) • Biz e DAL in comune • Tool ‘home made’ per sincronizzare i progetti 33 33
  • 34. Risorse per iniziare • 2 Video da NDC 2010 ‣ http://tekpub.com/conferences/ndc2010 • Stack Overflow / Mailing List • Esempi: galleria su xamarin.com • Libri 34 34
  • 35. Ingredienti per iniziare • Un computer Mac con Mac OS X • iPhone SDK • MonoTouch (+ Mono) – Simulator only (free), studenti (99$), Professional (399$), Enterprise (999$) • MonoDevelop 35 35
  • 36. Configurazione ambiente • Boot Camp + Parallels = stessa (ma unica) partizione Windows • Shortcuts per ‣ Mac OS X ‣ Windows da Parallels ‣ MonoDevelop 36 36
  • 37. Visual Studio come IDE (1/2) • Perchè vorrei farlo? ‣ IDE migliore / Resharper, ... • Si può fare! (cit) ‣ o quasi.... solo build, NO RUN • Non solo per progetti BIZ e DAL, anche per UI 37 37
  • 38. Visual Studio come IDE (2/2) • Soluzione funzionante: ‣ https://github.com/follesoe/VSMonoTouch ‣ (anche su nuget) 38 38
  • 39. Poniamo le basi... ...per costruire la prima App! 39 39
  • 40. Cocoa Touch: il Framework • Cocoa : .NET FX = Objective-C : C# • Foundation ‣ objects, memory, ... • UIKit, GameKit, MapKit, ... • Intro per .Net Dev: 40 ‣ http://www.kevfoo.com/2011/05/quick-primer-cocoa-and-cocoa-touch/ 40
  • 41. Window e Views • Application / AppDelegate ‣ main, ... ‣ 10 secondi per caricare! • Window ‣ 1 sola per App!!! Poi coi ViewControllers... • View (UIView) ‣ Base per UI Controls (Button, Textbox, ...) 41 ‣ Base per User Control! No ViewController 41
  • 42. 1° Demo! • Usare MonoDevelop (anche più istanze) • Creare UI con / senza Interface Builder • Utilizzo di immagini / risorse • Creazione di custom control con UIView • Utilizziamo le tabelle 42 42
  • 43. ViewControllers • Basato su MVC (o una specie...) • Creazione di app con più screen ‣ Navigation ‣ Resize, orientamento • “Infrastruttura” per UI Controls ‣ es. TableViewController 43 43
  • 44. Esempi di ViewController (1/4) TabBarController 44 44
  • 45. Esempi di ViewController (2/4) NavigationController 45 45
  • 46. Esempi di ViewController (3/4) SplitViewController / PopoverController 46 46
  • 47. Esempi di ViewController (4/4) TableViewController 47 47
  • 48. 2° Demo! • Creare una form con UIViewController • Resize e rotazione form • Anchor e docking • App con più form grazie ai ViewController. 48 48
  • 49. Altri approcci per UI • Tentativi di MVVM • DSL? (Domain-specific language) ‣ iCircuit: http://praeclarum.org/post/1520024382/interfaces- caches-cross-platform ‣ Post Antonio Ganci: http://blogs.ugidotnet.org/AntonioGanci/archive/ 2010/04/19/un-approccio-per-ottenere-una- architettura-malleabile.aspx 49 49
  • 50. Accesso ai dati locali (1/2) • SQLite ‣ portabilità in altre piattaforme?? ‣ Repository / DAO pattern? ORM? • Tipi di accesso ‣ ADO.NET ‣ API di SQLite dirette ‣ ORM (es. Vici CoolStorage) 50 50
  • 51. Accesso ai dati locali (2/2) • Performance Tips ‣ DataReader via GetString, GetInt, .. http://www.bayshield.com/2010/6/29/monotouch-sqlite- performance-tip ‣ Uso di transazioni e connection pooling ‣ Quantificazione costi reflection (se usata) http://praeclarum.org/post/1572668275/quantifying- reflections-slowdown-in-sqlite-net 51 51
  • 52. Accesso ai dati remoti • ASMX Web Service e WCF come in Silverlight • REST via HttpRequest / Response • JSON ‣ https://github.com/chrisntr/Newtonsoft.Json 52 52
  • 53. IoC / DI • Diverse librerie ‣ TinyIoC (funziona :) ‣ OpenNETCF.IoC ‣ Funq, PicoContainer ‣ http://monotouch.info/Tags/IoC 53 53
  • 54. Unit Testing • Ora supporto per girare su device • Testare la business logic / DAL • Testare l’”MVC” Apple: ‣ Supervisor Controller http://ben.phegan.name/index.php/2011/02/28/ monotouch-and-unit-testing/ 54 54
  • 55. Alcune librerie di supporto (1/2) • MonoTouch.Dialog ‣ https://github.com/migueldeicaza/MonoTouch.Dialog • MonoCross ‣ Stile MVC di ASP.NET MVC ‣ http://code.google.com/p/monocross/ • MvvmCross ‣ https://github.com/slodge/MvvmCross ‣ ATTENZIONE: Future direction (Under consideration): More tablet 55 support - for iPad, for Windows Metro and for Android 55
  • 56. Alcune librerie di supporto (1/2) • ReactiveUX per MonoTouch ‣ http://code.google.com/p/proactive-framework/ • Localizzazione ‣ https://github.com/rdio/vernacular • Event Aggregator (Message Broker) ‣ http://merbla.blogspot.com/2011/03/monotouch-and-eventaggregator.html • Xamarin Mobile API 56 56
  • 57. Alcuni tool di supporto • Workspace Reloader ‣ http://bit.ly/JM3FZe • SourceTree ‣ http://www.sourcetreeapp.com/ 57 57