logo资料库

Xamarin in Action.pdf

第1页 / 共610页
第2页 / 共610页
第3页 / 共610页
第4页 / 共610页
第5页 / 共610页
第6页 / 共610页
第7页 / 共610页
第8页 / 共610页
资料共610页,剩余部分请下载后查看
brief contents
contents
foreword
preface
acknowledgments
about this book
Who should read this book
How this book is organized
About the code
Software and hardware requirements
Online resources
Book forum
About the author
about the cover illustration
Part 1 Getting started with Xamarin
1 Introducing native cross-platform applications with Xamarin
1.1 Introducing Xamarin mobile apps
1.1.1 Vendor-specific native apps
1.1.2 Cordova
1.1.3 Xamarin native apps
1.1.4 Xamarin.Forms
1.1.5 Xamarin developer tools
1.1.6 Mobile-optimized development lifecycle
1.2 Creating production-quality mobile apps
1.2.1 Design
1.2.2 Develop
1.2.3 Test
1.2.4 Build
1.2.5 Distribute
1.2.6 Monitor
1.3 Rinse and repeat…
Summary
2 Hello MVVM—creating a simple cross-platform app using MVVM
2.1 What are UI design patterns?
2.2 MVVM—the design pattern for Xamarin apps
2.3 What is cross-platform code?
2.3.1 .NET Standard class libraries
2.4 Getting started—creating your first solution
2.4.1 Requirements—what hardware or software do you need for each mobile platform?
2.4.2 Creating the solution
2.4.3 What have we just created?
2.4.4 Building and running the apps
2.5 Is this really a cross-platform app?
Summary
3 MVVM— the model-view–view model design pattern
3.1 The model layer
3.2 The view-model layer
3.2.1 State and behavior
3.2.2 Value conversion
3.2.3 Testability
3.3 The view layer
3.4 Binding
3.4.1 Source and target
3.4.2 Binding mode
3.4.3 Binding is not cross-platform
3.4.4 Value converters
3.5 The application layer
3.6 Navigation
3.6.1 View-first
3.6.2 View-model–first
3.6.3 Which one to use?
3.7 Revisiting the square-root calculator app
Summary
4 Hello again, MVVM— understanding and enhancing our simple MVVM app
4.1 A deeper dive into our Hello Cross-Platform World app
4.1.1 The model
4.1.2 The view model
4.1.3 The application layer
4.1.4 The view
4.2 Expanding on our Hello World app
4.2.1 Using .NET Standard plugins to access device-specific code
4.2.2 Installing the Xamarin text-to-speech plugin
4.2.3 Adding the cross-platform code
4.2.4 Inversion of control
4.2.5 Wiring up the Android UI
4.2.6 Wiring up the iOS UI
Summary
5 What are we (a)waiting for? An introduction to multithreading for Xamarin apps
5.1 Why do we need multithreaded code?
5.2 What are threads?
5.2.1 Buying coffee
5.2.2 So what is a thread?
5.2.3 A quick roundup
5.3 UI thread and background threads
5.3.1 The UI thread
5.3.2 Background threads
5.4 Using tasks to run code in the background
5.4.1 Task and Task
5.4.2 Chaining tasks
5.5 Task results
5.5.1 Polling to see if the task has finished
5.5.2 Waiting on the task
5.5.3 Getting the result from a continuation
5.5.4 Task exceptions
5.6 Updating the UI
5.6.1 The UI task scheduler
5.6.2 Using the power of MVVM
5.7 Async and await
5.7.1 The async and await keywords
5.7.2 Writing your own async methods
5.7.3 Async commands
5.8 Make your app feel responsive
5.9 It’s time to start building things
Summary
Part 2 Building apps
6 Designing MVVM cross-platform apps
6.1 Introduction to designing a cross-platform app
6.2 Designing the UI and user flows
6.2.1 SquareRt—a simple app for calculating square roots
6.2.2 Countr—an app for counting multiple things
6.2.3 Defining user flows and UIs
6.3 Architecting the app
6.3.1 Which layer?
6.3.2 Which thread?
6.3.3 Mapping code to layers and threads
6.4 Creating the solutions
6.5 Application properties
6.5.1 Android manifest
6.5.2 iOS info.plist
6.6 SDK versions
6.6.1 Android SDK versions and the SDK manager
6.6.2 iOS SDK versions
6.7 Linking
6.7.1 Linking the apps
6.7.2 Linker options
6.7.3 Stopping the linker from doing too much
Summary
7 Building cross-platform models
7.1 Building simple model layers
7.2 Unit testing
7.2.1 Creating a unit-test project
7.2.2 Creating your first test
7.2.3 What do these tests tell you?
7.3 Building more complex model layers
7.3.1 Services, data models, and repositories
7.3.2 Accessing databases
7.3.3 Adding a service layer
7.3.4 Accessing web services
7.4 A quick recap
Summary
8 Building cross-platform view models
8.1 The view-model layer
8.1.1 The view-model layer inside SquareRt
8.1.2 The view-model layer inside Countr
8.2 Adding state and behavior to SquareRt
8.2.1 State inside SquareRt
8.2.2 Exposing behavior via property changes
8.3 Adding state and behavior to Countr
8.3.1 Single-value properties
8.3.2 Collections
8.3.3 Exposing behavior using commands
8.3.4 Messaging
8.3.5 Navigation
8.4 A quick roundup
Summary
9 Building simple Android views
9.1 Building Android UIs
9.1.1 Material design
9.1.2 Layout files
9.1.3 Resources
9.1.4 Resource locations
9.1.5 Editing layout files
9.1.6 Layout inflation
9.2 Creating the layout file for the SquareRt UI
9.2.1 Adding a toolbar
9.2.2 Adding an image
9.2.3 Adding an EditText control
9.2.4 Adding a result TextView control
9.3 Building the SquareRt view
9.3.1 What is an activity?
9.3.2 The activity lifecycle
9.3.3 Creating an activity for the view
9.3.4 Running the app
Summary
10 Building more advanced Android views
10.1 Building the UI for Countr
10.1.1 Creating the UI for the master view
10.1.2 Recycler views
10.1.3 Creating the UI for the recycler view items
10.1.4 Floating action buttons
10.1.5 Creating the UI for the detail view
10.1.6 Menu items
10.2 Building the Countr activities
10.2.1 Setting up master recycler views
10.2.2 The detail view
10.2.3 Running the app
10.3 App icons and launch screens
10.3.1 App icons
10.3.2 Launch screens
Summary
11 Building simple iOS views
11.1 Building iOS UIs
11.1.1 iOS human interface guidelines
11.1.2 Storyboards
11.1.3 Controls
11.1.4 Different screen resolutions
11.1.5 Auto layout with constraints
11.1.6 Image resources and asset catalogs
11.1.7 A quick recap
11.2 Creating the SquareRt storyboard
11.2.1 Adding our first view controller
11.2.2 Adding an image
11.2.3 Adding a text field
11.2.4 Adding the result label
11.2.5 Seeing the layout on different devices
11.2.6 Size classes
11.2.7 A quick recap
11.3 Building the SquareRt view
11.3.1 What is a view controller?
11.3.2 View lifecycle
11.3.3 Creating the view controller
11.3.4 Wiring up controls to the view controller
11.3.5 Binding the view controller
11.3.6 Another quick recap
11.3.7 Running the app
Summary
12 Building more advanced iOS views
12.1 Building the UI and view controllers for Countr
12.1.1 Creating the UI for the master view
12.1.2 Navigation bars and buttons
12.1.3 Creating the UI for the detail view
12.1.4 A quick recap
12.1.5 Running the app
12.2 App icons and launch screens
12.2.1 App icons
12.2.2 Launch screens
12.3 Making the apps production-ready
Summary
Part 3 From working code to the store
13 Running mobile apps on physical devices
13.1 Running Android apps on a real device
13.2 Signing Android apps for publishing
13.2.1 Setting the package name
13.2.2 Keystores
13.2.3 Creating keystores and signing builds
13.3 Running iOS apps on a real device
13.3.1 What is a provisioning profile?
13.3.2 Bundle identifiers
13.3.3 Creating a dummy app in Xcode
13.3.4 Running your app on a physical device
13.4 Creating iOS provisioning profiles
13.4.1 Certificates
13.4.2 App IDs
13.4.3 Devices
13.4.4 Provisioning profiles
13.4.5 Running your app using the new provisioning profile
13.4.6 Troubleshooting
Summary
14 Testing mobile apps using Xamarin UITest
14.1 Introduction to UI testing
14.1.1 Writing UI tests using Xamarin UITest
14.1.2 Setting up your app for UI testing
14.1.3 Running the auto-generated tests
14.2 Writing tests
14.2.1 The visual tree
14.2.2 The REPL
14.2.3 Identifying controls
14.2.4 Tapping the Add button
14.2.5 Entering text
14.2.6 Finding controls based on their text
14.2.7 Assertions
14.2.8 Proving your test by breaking things
14.3 Testing incrementing a counter
14.4 The app interface and app queries
14.4.1 The IApp interface
14.4.2 Queries
Summary
15 Using App Center to build, test, and monitor apps
15.1 Introducing Visual Studio App Center
15.1.1 Apps
15.1.2 Users and organizations
15.1.3 API
15.1.4 CLI
15.1.5 Getting help
15.2 Setting up builds
15.2.1 Creating your first App Center app
15.2.2 Configuring the Android build
15.2.3 Configuring the iOS build
15.3 Testing your apps using Test Cloud
15.3.1 What is Test Cloud?
15.3.2 Preparing your apps to be tested
15.3.3 Creating a test run configuration
15.3.4 Running tests from the command line
15.3.5 Viewing the test results on App Center
15.4 Analytics and crash reporting
15.4.1 Adding the App Center SDKs
15.4.2 Understanding your audience
15.4.3 Adding event tracking
15.4.4 Crash reporting
Summary
16 Deploying apps to beta testers and the stores
16.1 Distributing Android apps to beta testers
16.1.1 Enabling app distribution
16.1.2 Auto updates
16.2 Publishing Android apps on the Google Play store
16.2.1 Setting up your account
16.2.2 Creating your app
16.2.3 Alternative stores
16.3 Distributing iOS apps to beta testers
16.3.1 Enabling app distribution
16.3.2 Auto updates
16.4 Publishing iOS apps on the Apple App store
16.4.1 Provisioning your app for publishing
16.4.2 Setting up your app
Summary
Where to next?
Appendix A UI flows and threads for SquareRt and Countr
A.1 SquareRt
A.2 Countr
A.2.1 Loading counters
A.2.2 Adding a counter
A.2.3 Deleting a counter
A.2.4 Incrementing a counter
Appendix B Using MVVM Light instead of MvvmCross
B.1 MVVM Light
B.2 Installing MVVM Light
B.3 The model layer
B.4 The view model layer
B.5 The view layer
B.5.1 The Android view and application layer
B.5.2 The iOS view and application layer
Summary
index
Symbols
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Creating native cross-platform mobile apps Jim Bennett FOREWORD BY James Montemagno M A N N I N G
A sneak peak... By building Xamarin apps using the MVVM design pattern, you too can reuse 80% of your code across iOS and Android. iOS C# Android C# C# App layer UI layer C# C# View UI logic layer Business logic layer Binding C# C# View model Model Picking the right thread... We all hate mobile apps that are unresponsive. Here’s how to decide what to run on a background thread. Does this involve the UI? No Does this use external resources (DB, web)? No Does this take more than 100 ms on a slow device? No UI thread or background thread Yes Yes Yes UI thread Background thread Background thread
Xamarin in Action CREATING NATIVE CROSS-PLATFORM MOBILE APPS JIM BENNETT M A N N I N G SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com © 2018 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Development editor: Elesha Hyde Review editor: Aleksandar Dragosavljevic´ Technical development editor: Gary Park Project editor: Kevin Sullivan Copyeditor: Andy Carroll Proofreader: Corbin Collins Technical proofreader: Tomasz Cielecki Typesetter: Dottie Marsico Illustrator: April Milne Cover designer: Marija Tudor ISBN 9781617294389 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 23 22 21 20 19 18
for your unwavering love and support whilst I was glued to my laptop. To the amazing Nat and Evie,
brief contents PART 1 GETTING STARTED WITH XAMARIN ....................................1 Introducing native cross-platform applications with Xamarin 3 1 ■ 2 ■ Hello MVVM—creating a simple cross-platform app using MVVM 25 3 ■ MVVM—the model-view–view model design pattern 50 4 ■ Hello again, MVVM—understanding and enhancing our simple MVVM app 81 5 ■ What are we (a)waiting for? An introduction to multithreading for Xamarin apps 113 PART 2 BUILDING APPS............................................................. 153 6 ■ Designing MVVM cross-platform apps 155 7 ■ Building cross-platform models 195 8 ■ Building cross-platform view models 241 9 ■ Building simple Android views 288 10 ■ Building more advanced Android views 319 11 ■ Building simple iOS views 345 12 ■ Building more advanced iOS views 385 v
vi BRIEF CONTENTS PART 3 FROM WORKING CODE TO THE STORE............................409 13 ■ Running mobile apps on physical devices 411 14 ■ Testing mobile apps using Xamarin UITest 436 15 ■ Using App Center to build, test, and monitor apps 467 16 ■ Deploying apps to beta testers and the stores 505
分享到:
收藏