MonoTouch, un anno dopo
-
Upload
stefano-ottaviani -
Category
Technology
-
view
1.893 -
download
3
description
Transcript of MonoTouch, un anno dopo
Programmiamo iPhone e iPad (e non solo!) con
• Stefano Ottaviani‣ [email protected]‣ @ste8
1 anno dopo
1
Della serie...
2
2
Conosciamoci un po’• Hai seguito la sessione di 1 anno fa?
• Hai usato MonoTouch in produzione?
• Conosci MonoTouch?
3
3
Chi sono?
• Dev / SEng @ KILOG Srl‣ Da Palm OS a iPad, passando per Windows CE / Mobile
(C++, .NET CF) - 10 anni sul mobile!
• Communities‣ DotNetMarche, XPUG Marche, TechBar
• Contatti‣ [email protected]‣ @ste8 ‣ blogs.ugidotnet.org/ste84
4
Conclusioni :)
5
5
... e C# non è solo“la copia” di Java
(since 3.5)
6
6
7
8
Cosa devo sviluppare? (1/4)
9
• Line of Business Applications (LoB)Online e soprattutto OFFLINE
• Sales Force Automation, CRM, assistenze tecniche, ...
• Ciclo di vita: medio / lungo
• Porting / Reengineering di app esistenti (WM6, netbook, ...)
9
Cosa devo sviluppare? (2/4)
10
10
Cosa devo sviluppare? (3/4)
• Device:iPhone e iPad come riferimenti‣ ma ci sono anche Android, WP7, netbook
• UX usabile e attraente!
11
11
Cosa devo sviluppare? (4/4)
• Performante‣ L’exe non deve essere per forza piccolo
• Controllo sul deploy dell’app
• Ridurre potenziali problemi x sviluppo‣ No puntatori & rilascio memoria
12
12
Che strumenti abbiamo?
13
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
Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp15
15
Con la diffusione di HTML5 e js...
ok, ma fare tutto in HTML5/JS è come fare cibo vegerariano perchè
così lo mangiano (quasi) tutti(cit. @alexbream)
16
Oh ragazzi! Ma siam pazzi?
16
Considerazioni sullo sviluppo
Cross Platform
17
17
La UI va rifatta...o no? (1/5)
Esempio MIX11 App http://tinyurl.com/442vt3t
iPhone
18
18
La UI va rifatta...o no? (2/5)
Esempio MIX11 App http://tinyurl.com/442vt3t
WP7
19
19
La UI va rifatta...o no? (3/5)
Esempio MIX11 App http://tinyurl.com/442vt3t
Android
20
20
La UI va rifatta...o no? (4/5)
Ipse dixit: Martin Fowlerhttp://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 for that platform, with a experience design based on that platforms interaction style
21
21
La UI va rifatta...o no? (5/5)
... ma almeno riutilizziamo la logica di business e di accesso dati...
... soprattutto in app offline!
Riscrivere il codice in linguaggi diversi per ogni piattaforma è
molto costoso!22
22
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.
23
23
• nicely layered architecture
• non-presentation logic which is easy to get under solid test coverage
24
Side effect del“Cross-platform Core” approach
Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp
24
Cos’èMonoTouch
25
25
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, Dynamic, ... =>
Attenzione! Usati da molti ORM ‘light’26
26
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)27
27
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
• Prezzo:pro o contro?28
28
Soddisfa i miei bisogni? (1/3)
• App LOB (Line of Business)‣ Online e soprattutto OFFLINE✴Si... e fa molto altro!
• Device:iPhone e iPad come riferimenti‣ ma ci sono anche Android, WP7, netbook✴Posso condividere BIZ e DAL!
29
29
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✴Stesse possibilità di Objective-C!
30
30
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
31
31
Chi c’è dietro a MonoTouch e
Mono for Android?
32
32
Quale sarà il futuro di MT?
33
All technology roadmaps remain
intactYou should, yes. It will
be compaDble.
Can we conDnue working with MonoTouch?
No Panic
1 anno fa...
33
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”34
34
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
35
35
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 ...
36
36
Xamarin oggi (4/5)
• Xamarin Identified as a Leader in Mobile Cross-Platform Application Development Tools
37 Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/
37
Xamarin oggi (5/5)
38
Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/
38
Risorse per iniziare
• 2 Video da NDC 2010‣ http://tekpub.com/conferences/ndc2010
• Stack Overflow / Mailing List
• Esempi: galleria su xamarin.com
• Libri 39
39
Come abbiamo organizzato il nostro progetto?
40
40
Ingredienti per iniziare
• Un computer Mac con Mac OS X
• iPhone SDK
• MonoTouch (+ Mono)– Simulator only (free), studenti (99$),
Professional (399$), Enterprise (999$)
• MonoDevelop41
41
Configurazione ambiente
• Boot Camp + Parallels = stessa (ma unica) partizione Windows
• Shortcuts per ‣ Mac OS X‣ Windows da Parallels‣ MonoDevelop
42
42
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
43
43
Visual Studio come IDE (2/2)
• Soluzione funzionante:‣ https://github.com/follesoe/VSMonoTouch ‣ (anche su nuget)
44
44
Architettura
• “Progetto” Server (Web API, IIS)
• “Progetto” Client (iPad)
• Biz e DAL in comune
• Tool ‘home made’ per sincronizzare i progetti
45
45
UI Patterns
• No Data Binding :(
• MVP e Presentation Model‣ http://martinfowler.com/eaaDev/PresentationModel.html
‣ http://martinfowler.com/eaaDev/SupervisingPresenter.html
• Soluzioni ‘MVVM’‣ MonoCross, MvvmCross‣ ATTENZIONE: Future direction (Under
consideration): More tablet support - for iPad, for
Windows Metro and for Android46
46
UI: XCode vs Codice
• Approcci 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
47
47
Request / Response Service Layer (1/3)
• Cos’è e perchè ?‣ http://davybrion.com/blog/2009/11/requestresponse-
service-layer-series/‣ http://davybrion.github.com/Agatha/
‣ Video workshop DotNetMarche:• https://vimeo.com/album/1490635/video/17700408• https://vimeo.com/album/1490635/video/18120319
48
48
Request / Response Service Layer (2/3)
49
49
Request / Response Service Layer (3/3)
50
50
UI + Request/Response SL
51
51
Data Access Layer (1/3)
• TransactionScope è supportato‣ Utile per Request / Response SL
• Sqlite su iPad, Sql Server sul server
• No Core Data
• ORM o no? (es. Vici CoolStorage o altri ‘light’ per Sqlite)52
52
DAL: Sqlite (2/3)
• Supporta subset query DDL!‣ ALTER TABLE, DROP COLUMN, ...‣ Attenti ai generatori di script!
• Molto lasco sui tipi di dati!!‣ Lunghezza stringhe?‣ Valori decimal?‣ DateTime salvati come stringhe!
53
53
DAL: Performance Tips (3/3)
• 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
54
54
Accesso ai dati remoti
• ASMX Web Service e WCFcome in Silverlight
• REST via HttpRequest / Response
• JSON‣ https://github.com/chrisntr/Newtonsoft.Json
55
55
Sincronizzazione
• Quanti dati?‣ oltre 100K - 1M records per tabella
• Sync Framework(s) ?
• Soluzioni ‘home made’ ?
56
56
DDD è un buon amico (1/3)
• Domain Driven Design: si può fare!
• Entity, Value Object, Repository... chissené....
57
57
DDD è un buon amico (2/3)
• Applicabile anche a “rich” UI
• Task Based UI‣ “It is possible to bring forward the
intention of the user; this will allow the Application Server to process behaviors as opposed to saving data”
‣ http://cqrs.wordpress.com/documents/task-based-ui/
58
58
DDD è un buon amico (3/3)
• Separare il comportamento dai dati
• Capire che entità state trattando‣ Una fattura è la stessa fattura per tutti?‣ Bounded Context‣ Mandare il vostro DBA nei matti in tre semplici mosse
https://vimeo.com/31739391
• Command Handler di CQRS (vedi Request Response Service Layer)
59
59
IoC / DI
• Diverse librerie‣ TinyIoC (funziona :)
‣ OpenNETCF.IoC, Funq, PicoContainer
‣ http://monotouch.info/Tags/IoC
60
60
Testing (Unit, Integration) (1/2)
• Ora supporto per girare su device
61
61
Testing (Unit, Integration)(2/2)
• Testare la business logic / DAL
• Testare l’”MVC” Apple:‣ Supervisor Controller
http://ben.phegan.name/index.php/2011/02/28/
monotouch-and-unit-testing/
62
62
Alcune librerie di supporto (1/3)
• MonoTouch.Dialog‣ https://github.com/migueldeicaza/MonoTouch.Dialog
‣ ATTENZIONE su iPad (se UITableViewController non full-screen)
63
63
Alcune librerie di supporto (2/3)
• Framework per MVVM•MonoCross
‣ http://code.google.com/p/monocross/
• MvvmCross‣ https://github.com/slodge/MvvmCross
‣ ATTENZIONE: Future direction (Under consideration): More tablet support - for iPad, for Windows Metro and for Android
64
64
Alcune librerie di supporto (3/3)
• 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 API65
65
Alcuni tool di supporto
• Workspace Reloader‣ http://bit.ly/JM3FZe
• SourceTree‣ http://www.sourcetreeapp.com/
66
66
Troubleshooting
67
67
Troubleshooting (1/2)
• Eccezioni compilatore AOT‣ specialmente con LINQ
• Encoding non unicode dei caratteri
• Qualche problema con MonoDevelop in full-screen
68
68
Troubleshooting (2/2)
• Attenzione ai Trampolini!‣ Ran out of trampolines of type 0,1,2
http://docs.xamarin.com/ios/troubleshooting#Ran_out_of_trampolines_of_type_0
‣ Understanding the impact http://monotouch.2284126.n4.nabble.com/Understanding-the-impact-of-trampolines-td4495086.html
69
69
Bonus
70
70
Cosa è possibile fare a questo punto...
• Riutilizzo di Biz e Dal in servizi esposti sul web
• Creazione di client in qualsiasi tecnologia su questi servizi
71
71
Domande?
72
72