2016년 4월 18일 월요일

Build a Cross Platform Application with Xamarin

죄송하게도 본 게시물은
아래 Xamarin 가이드를 보고 개인적으로 필요한 부분만을 정리한 것이므로
해당 링크를 직접 보시는 것이 좋습니다.

https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/


[Shared Projects vs Portable Class Libraries]

 : https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/

갑자기 좀 처음에 이게 나와서 좀 생뚱맞긴 하지만 Xamarin 개발 시 아래 두 방법 중 하나를 선택하는 것이 필수 이므로 설명하고 들어가는게 아닌가 함.

[Shared Projects]
 : Source code 수준(#if compiler를 사용)에서 platform-specific requirement를 처리하는 shared project를 만들어 Cross platform app 개발 방법
 : 장점은 잘 모르겠고 #if의 폐혜가 그대로 나오지 않을까 생각함.
 : 좀 더 찾아보니 Portable class libraries 방법에 비해 .NET framework feature를 모두 사용할 수 있다고 함.







[Portable Class Libraries]
 : Platform specific 기능을 사용할 수 있도록 Interface를 제공하는 PCL(Portable Class Library)를 만들어 사용하는 Cross platform app 개발 방법

 : 공통의 기능을 별도의 DLL로 분리해서 업데이트 함에 있어 코드의 분리, 유지보수의 편의성, 일관적인 공통 기능 제공 등에서의 장점을 가지겠지만 공통의 기능이 최소화 되어 도출 될 수 밖에 없고 platform specific한 부분이 각 app에서 따로 구현이 되어야 하는 점이 있음.



좀 더 찾아보니 장단점이 다양해서 각자 판단하시길.
사실 어찌 보면 다양함을 지원함과 공통의 부분을 최대화 하는 것은 상반되는지라 적당한 수준을 찾는게 맞을듯?

http://www.slideshare.net/gilbok/xamarinforms-mvp-comcamp-2015?qid=490ed12a-a153-4a9c-aa83-8d35eb19e105&v=&b=&from_search=1
 : PCL과 Shared Project의 장단점을 잘 소개 하고 있는 PT. 내용 괜찮음.

http://stackoverflow.com/questions/30634753/what-is-the-difference-between-a-shared-project-and-a-class-library-in-visual-st
http://hotkrossbits.com/2015/05/03/xamarin-forms-pcl-vs-shared-project/

[Overview]

https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_0_-_overview/

 : 일반 적인 Cross Platform은 "write-once, run everywhere" 즉, Common set을 정의하여 여러 플랫폼을 대응하는 방법을 취해 비용 최소화의 장점을 가지나 common set이 각 platform의 최소 기능으로 이뤄지는 점 GUI가 general 하게 구성된다는 단점이 있음.
그에 반해 Xamarin에서는 Naitve UI을 구현/제공할 수 있는 방법 제공과 UI를 제외한 data storage, business logic 등을 재사용할 수 있음 점을 장점으로 내세우고 있는 듯하다.



Xamarin Cross-Platform App을 만들 때 필요한 주요 Feature들은 다음과 같음.

 - C# 사용
  : C#으로 코드를 작성하고 iOS, Android, Windows Phone 대상 app으로 변환 가능
 - MVC design pattern
  : Core, User-Interface을 분리하여 app 개발을 할수 있다. MVC(Model-View-Controller), MVVM(Model-View-ViewModel) design approach를 사용할 수 있음.
 - Native UIs
  : 각 OS에 특화된 application을 작성하기 위해 다른 UI layer를 사용 가능?
  : iOS (MonoTouch), Android (Android.Views), Windows Phone (XAML/Silverlight), Windows 8 (Metro APIs)

Code Reuse를  확대를 위해 다음의 sub-system들을 사용할 수 있다고 함.

  1. SQLite-NET for local SQL storage,
  2. Xamarin Plugins for accessing device-specific capabilities including the camera, contacts and geolocation,
  3. Using framework features for networking, web services, IO and more.



[Part 1 – Understanding the Xamarin Mobile Platform]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_1_-_understanding_the_xamarin_mobile_platform/

Mobile에서 app개발을 할 수 있도록 하는 Xamarin platform은 다음으로 구성됨.
 - C# language
 - Mono .NET framework :
 - Compiler : Target OS, Platform 대상으로 필요한 것들을 빌드하고 최적화도 수행
 - IDE tools : Xamarin Studio IDE, plugin for VS

Complication
 - iOS
  : AOT(Ahead-Of-Time) 컴파일을 통해 C# 코드에서 ARM assembly 결과물로 생성함
  : iOS는 runtime code generation을 허용하지 않아 제약 존재 (Xamarin.iOS Limitations)
 - Android
  : 컴파일을 통해 C# 코드에서 IL 결과물을 생성하고 MonoMV, JIT 컴파일러?와 함께 packaging됨. App은 JAVA/ART(Android RumTime)와 함께 실행되며 JNI를 통해 native type을 접근할 수 있음.
  : Android에서의 제약들( Xamarin.Android Limitations)
 - Windows Phone
  : C#은 IL로 컴파일 되어 build-in된 runtime에서 실행된다. 뭐 당연하겠지..

[IDE]

Development OS
Mac OS X
Windows
IDE
Xamarin Studio
Xamarin Studio
Visual Studio
iOS
Y
-
Y
Android
Y
Y
Y
Windows Phone
-
-
Y
Visual Studio 2015 Update 2 부터는 Xamarin 포함

 - iOS 개발 시 Mac OS X 필요

[UI]
 - 코드로 UI를 작성할 수 도 있고 Visual Designer를 사용해서 편하게 만들 수도 있음.
 - 하지만 각 OS의 metaphor(일반적인 Look and feel?)를 참고할 필요 있음.
  : iOS
   . hierarchical navigation with soft back button, tabs on the bottom of the screen.
   . Apple's Human Interface Guidelines
  : Android
   . hardware/system-software back button, action menu, tabs on the top of the screen.
   . Google's User Interface Guidelines
  : Windows Phone
   . hardware back button, panorama layout control, live tiles.
   . User Experience Design Guidelines for Windows Phone

[Library and Code Re-Use]
 - C# library야 당연히 사용할 수 있겠고
 - Objective-C Bindings + Binding Projects : btouch 제공
  : Binding Objective-C Types documentation
 - .jar Bindings + Binding Projects
  : Binding a Java Library documentation 
 - C via PInvoke
  : P/Invoke(Platform Invoke)를 사용하여 C#에서 native library들 사용이나 native library에서 callback 호출을 하게할 수 있음.
  :  linking native libraries

예시 - SQLite-NET
[DllImport("sqlite3", EntryPoint = "sqlite3_open", CallingConvention=CallingConvention.Cdecl)]
public static extern Result Open (string filename, out IntPtr db);
 - C++ via CppSharp
  : https://github.com/mono/CppSharp

[Part 2 - Architecture]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_2_-_architecture/

[OOP 개념]
 : 참고
  . 나무위키 객체 지향 프로그래밍
  . 객체지향 개념 (쫌 아는체 하기) http://www.slideshare.net/plusjune/ss-46109239
 - Encapsulation
 - Separation of Responsibilities
 - Polymorphism

[Application Layers]
 : 누가 정의했는지는 모르겠지만 용어는 알아두자.
 - Data Layer
  : SQLite 같은 DBMS가 여기에 해당 될듯
 - Data Access Layer
  : Data Layer를 사용(CRUD)하기 위한 wrapper/DAO 같은 부분?
 - Business Layer/Business Logic Layer
 - Service Access Layer
  : Cloud나 다른 web service들을 Application이나 UI layer에서 사용하기 위한 API들을 제공한다.
 - Application Layer
  : platform/application specific한 code를 포함하는 layer.
  : User Interface Layer와의 차이는 UI component를 포함하는지 여부와 다른 screen이나 device에 대해서 공유되는지 여부라고 함.
 - User Interface Layer
  : 사용자가 직접 대면하는 화면들(screens, widgets 등)을 관리하고 제공함.

[Common Mobile Software Patterns]
 - MVC(Model, View, Controller) pattern
 - Business Facade (Manager Pattern) pattern
  : 복잡한 처리를 간단하게 수행할 수 있도록 단순화된 entry point(ex API, etc?)를 제공함.
  : https://ko.wikipedia.org/wiki/%ED%8D%BC%EC%82%AC%EB%93%9C_%ED%8C%A8%ED%84%B4
 - Singleton pattern
 - Provider (Strategy) pattern?
  : http://hyeonstorage.tistory.com/146
 - Async pattern?
  : Async keyword는 아니며 보통 network 처리 같이 시간이 필요한 동작 수행 시 UI나 application이 pending되거나 영향을 받지 않도록 처리할 때 사용하며 주로 thread를 사용한다. 이 때 thread life cycle 관리, 수행 후 notification등을 고려해야 함.

[Part 3 - Setting Up A Xamarin Cross Platform Solution]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_3_-_setting_up_a_xamarin_cross_platform_solution/

처음에 설명된 PCL 방법을 쓰던지 Shared Project 방법을 쓰던지 간에 Xamarin에서는 Core project와 Platform-specific application project로 나뉜다.



Core Project
 : 플랫폼에 상관없이 재사용 가능한 코드들로 구성
 : Data Layer, Data Access Layer, Service Access Layer, business Layer 들이 존재

Platform-Specific Application Projects
 : platform-specific한 feature들을 사용하고 platform SDK과 binding된 코드들이 포함됨
 : Application Layer, User Interface Layer 들이 존재


[Part 4 - Dealing with Multiple Platforms]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_4_-_platform_divergence_abstraction_divergent_implementation/

Universal UI attributes
 - Feature selection via tabs or menus
 - Lists of data and scrolling
 - Single views of data
 - Editing single views of data
 - Navigating back

Platform-specific attributes
 - Screen sizes
 - Navigation metaphors
 - Keyboards
 - Touch and gestures
 - Push notifications

Device-specific features
 - Camera
 - Geo-location & maps
 - Accelerometer, gyroscope and compass
 - Twitter and Facebook
 - Near Field Communications (NFC)

[Platform Divergence를 처리하는 방법]
 - Platform Abstraction
  : Facade pattern을 사용해서 unified API를 제공하여 platform 특화된 구현부를 추상화하는 방법
  : Interface나 상속을 통해서 class를 추상화하는 방법
  : Xamarin.Forms
  : Cross-Platform Plug-ins

 - Divergent Implementation
  : Conditional compilation을 이용하여 platform에 특화된 부분을 처리하는 방법

[Platform Abstraction]
- Class Abstraction
 : Interface를 사용하거나 Inheritance을 통해 처리하거나

- Xamarin.Forms
 : A cross-platform UI toolkit that allows developers to easily create native user interface layouts that can be shared across Android, iOS, and Windows Phone.

- Plug-in Cross-Platform Functionality
 : https://github.com/xamarin/plugins

- Other Cross-Platform Libraries
 - MvvmCross - https://github.com/slodge/MvvmCross/
 - Vernacular (for localization) - https://github.com/rdio/vernacular/
 - MonoGame (for XNA games) - http://monogame.codeplex.com/
 - NGraphics - NGraphics and its precursor https://github.com/praeclarum/CrossGraphics

[Divergenct Implementation]
- Conditional compilation
#if __MOBILE__
// Xamarin iOS or Android-specific code
#endif

iOS

Xamarin.iOS defines __IOS__ which you can use to detect iOS devices.
#if __IOS__
// iOS-specific code
#endif
There are also Watch- and TV-specific symbols:
#if __TVOS__
// tv-specific stuff
#endif

#if __WATCHOS__
// watch-specific stuff
#endif

Android

Code that should only be compiled into Xamarin.Android applications can use the following
#if __ANDROID__
// Android-specific code
#endif
Each API version also defines a new compiler directive, so code like this will let you add features if newer APIs are targeted. Each API level includes all the ‘lower’ level symbols. This feature is not really useful for supporting multiple platforms; typically the __ANDROID__ symbol will be sufficient.
#if __ANDROID_11__
// code that should only run on Android 3.0 Honeycomb or newer
#endif

[Part 5 - Practical Code Sharing Strategies]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_5_-_practical_code_sharing_strategies/

필요할 때 참고하면 될 듯
DBMS, File System, Network, Web Services 관련 Solution들


[Part 6 - Testing and App Store Approvals]

https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_6_-_testing_and_app_store_approvals/


[Case Study: Tasky]

https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/case_study-tasky/

댓글 없음:

댓글 쓰기