Ios-Devel Ws2018.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
© 2019 published by FH JOANNEUM Gesellschaft mbH Cover image by Mathias Knoll Layout by Mathias Knoll FH JOANNEUM Gesellschaft mbH Publishing Alte Poststraße 149 A-8020 Graz www.fh-joanneum.at Last modification: Tuesday 12th March, 2019 at 14:01. Xcode 10.1 and Swift Version 4.2.1. ISBN eBook: 978-3-902103-83-3 The work is published under a Creative Commons Attribution-ShareAlike 3.0 Austria license. CC BY-SA 3.0 AT https://creativecommons.org/licenses/by-sa/3.0/at ii Contents 1 iOS Development – The Big Picture 1 1.1 Introduction . 1 1.2 WIIFM – What is In It For Me . 1 1.3 Overall Concepts . 3 1.3.1 Philosophy . 3 1.3.2 App Design on Storyboards . 3 1.3.3 Selected Frameworks . 3 1.4 Development Tools . 3 1.4.1 Finding Help . 4 1.4.2 Xcode . 4 1.4.3 Deployment on Real Devices . 5 1.4.4 App Store Deployment . 6 1.4.5 Package Manager . 6 2 Programming watchOS 15 2.1 watchOS . 15 2.2 The Apple Watch . 15 2.3 Apples Philosophy . 16 2.4 Overall Architecture . 16 2.5 Basic Concepts . 18 2.5.1 Views and Navigation . 18 2.5.2 The Navigation Flow . 20 2.5.3 Watch Kit Interface Elements . 20 2.5.4 Interaction . 20 2.5.5 Views and Controllers . 21 2.5.6 The Life Cycle of an Interface Controller . 22 2.5.7 Programming Navigation with/without Segues . 24 2.5.8 Controls and Views . 25 iii 2.5.9 Complications . 26 2.5.10 Notifications . 26 2.5.11 Features . 27 2.5.12 The Life Cycle of a Watch Application . 27 2.5.13 Communication with iOS . 29 2.5.14 Security and Privacy . 34 2.6 Technical Data . 35 3 Swift I Programming Basics 39 3.1 Introduction . 39 3.1.1 Programming in Swift . 39 3.1.2 Swift Scripts . 40 3.1.3 REPL in the Playground . 40 3.1.4 Documentation in Playgrounds . 40 3.2 The Swift Language . 42 3.2.1 Coding Style Guides and Documentation . 43 3.2.2 Type Inference . 43 3.2.3 Optionals . 44 3.2.4 Functions and Parameters . 44 3.2.5 Closures . 46 3.3 Data Types . 46 3.3.1 Map and Reduce . 47 3.4 Object-Oriented Programming . 48 3.4.1 Inheritance, Polymorphism . 49 3.4.2 Extensions . 50 3.4.3 Protocols . 50 3.4.4 Protocol Extensions . 51 3.5 Further Hints . 51 3.6 Completely Unnecessary Knowledge . 51 4 Swift II Advanced Programming 55 4.1 Introduction . 55 4.2 Advanced Programming in Swift . 56 4.2.1 ARC – Automatic Reference Counting . 56 4.2.2 LLVM and LLDB – Compiler and Debugger . 57 4.3 Advanced OOP . 57 4.3.1 Properties . 57 4.3.2 Operator-Overloading . 58 iv 4.4 Asserts, Exceptions and Preconditions . 59 4.5 Nested Functions and Function Pointers . 61 4.6 Generics . 62 4.7 Structs and Mutating Functions . 63 4.8 Design Patterns in Swift . 63 4.9 Limitations of Swift . 64 4.10 The Future of Swift . 64 5 Programming iOS 69 5.1 Introduction . 69 5.2 Coding for iOS . 69 5.3 General App Design . 70 5.3.1 Performance . 70 5.3.2 Energy Consumption . 70 5.4 App Life Cycle . 70 5.5 Unit Tests . 71 5.6 Widgets . 73 5.7 Accessibility . 75 5.8 UI Tests . 75 5.9 Auto Layout . 76 5.10 Navigation Flow . 78 5.11 Interaction Design for Multitouch Input . 80 5.12 Internationalisation . 81 6 Concurrency 85 6.1 Introduction . 85 6.2 Concurrency . 85 6.3 Dispatch Queues . 86 6.4 Fetching Data . 86 6.5 Web Services . 90 6.6 Deserialisation . 91 7 Persistency 99 7.1 Introduction . 99 7.2 Persistency . 99 7.2.1 Default Configurations . 99 7.2.2 Persistency with Shared Preferences . 100 7.2.3 Cloud-Based KeyValue Store . 101 v 7.2.4 Object/Relational Mapping (O/R-M) . 101 7.2.5 Persistency with Core Data . 101 7.2.6 Alternatives to Core Data . 106 7.2.7 Secure Persistency . 106 8 Location-Based Services 109 8.1 Introduction . 109 8.2 Location-Based Services . 109 8.2.1 Users Context . 110 8.2.2 GPS and GLONASS Location . 110 8.2.3 Geofencing and Location-Based Services . 112 8.2.4 Maps . 112 8.2.5 Overlays on Maps . 114 8.2.6 Geocoding and Reverse Geocoding . 114 8.2.7 Remarks for Enterprises . 114 9 Animation 119 9.1 Introduction . 119 9.2 Animation . 119 9.2.1 Game Loop . 120 9.2.2 2D Drawing . 120 9.2.3 SpriteKit and SceneKit . 123 10 Sensors 127 10.1 Introduction . 127 10.2 Sensors and Actuators . 127 10.2.1 Actuators . 128 10.2.2 Sensors . 128 10.2.3 Sample Code . 131 10.2.4 More Frameworks . 133 11 Security 137 11.1 Introduction . 137 11.2 General Aspects . 138 11.3 The Operating System . 138 11.4 Apps and the Operating System . 139 11.4.1 Deployment and Installation . 139 11.4.2 App Separation . 139 vi 11.4.3 IPC-Channels . 139 11.4.4 The Keychain . 139 11.4.5 Biometric Sensor . 140 11.4.6 Machine Learning and Privacy . 140 11.5 Networking and Cloud . 140 11.5.1 Networking . 140 11.5.2 Cloud Services . 140 11.5.3 Secure the Infrastructure . 141 11.6 Secure Coding . 141 11.6.1 Web Application Security . 141 11.6.2 Testing . 142 11.7 Forensics . 142 11.8 Analysis Tools . 142 11.9 Jailbreaks . 145 11.10Selected Issues . 146 11.13Books on Security . 147 12 System Services 151 12.1 Introduction . 151 12.2 System Services . 151 12.2.1 Review of the iOS Layers . 152 12.2.2 Access to Photos and Contacts . 152 12.2.3 Sharing . 154 12.2.4 Inter Process Communication . 155 12.2.5 watchOS . 157 13 Cloud Services 161 13.1 Introduction . 161 13.2 Cloud . 161 13.2.1 iCloud – Ideas and Concepts . 162 13.2.2 iCloud Development with CloudKit . 163 13.2.3 CloudKit JS . 166 14 Local and Push Notifications 171 14.1 Introduction . 171 14.2 Notifications ..