Project Goal: Create a clean, user-friendly tourism booking app that supports iOS, iPadOS, and watchOS. The prototype focuses on Hong Kong as a destination and integrates hotel booking and nearby attractions, while ensuring data consistency and synchronization across devices (iPhone and Apple Watch).
Project Duration: 14 days (12/3 - 12/17)
Existing tourism products (e.g., many domestic travel apps) may contain excessive ads and redundant features. The goal is to develop a cleaner, more streamlined travel booking experience. Additionally, integrating iOS and Apple Watch adds convenience for users to view, book, and track their trips on multiple devices.
Key Features:
- Target destination: Hong Kong tourism.
- Hotel booking and nearby attraction suggestions.
- Support across Apple ecosystem: iOS, iPad, Apple Watch.
- After booking, record logs in a SQL database (for potential future integration).
- Ultimately, build a minimal, clean, and efficient travel application.
Tasks:
- Identify Core Requirements:
- Browse hotels and attractions.
- Allow booking of hotels.
- Display nearby points of interest.
- Sync bookings and data across iOS and Apple Watch.
- Potential Apple Pay integration for a smoother payment experience.
- Initial Codebase Selection & Open-Source Resources: We researched existing SwiftUI-based open-source travel apps as a starting point. One promising codebase is “Travel-Booking-App-SwiftUI”, which already includes hotel browsing, MapKit integration, and Apple Pay support. This can serve as a strong foundation.
Some Useful Open-Source Repositories Studied:
- Travel-Booking-App-SwiftUI: E-commerce-like travel booking with hotel and activities booking, SwiftUI, MapKit, Apple Pay.
- NearMe: SwiftUI + MapKit app for discovering nearby places.
- swiftui-hike-app: SwiftUI-based hiking route discovery application.
- Other curated lists from “awesome-swift” and “awesome-swiftui” repositories.
Before modifying the selected codebase, a quick refresher and learning session on Swift, SwiftUI, and Apple frameworks:
References:
- Swift Language: Swift Official Docs
- SwiftUI Tutorials: Apple SwiftUI Tutorials
- Xcode Playground: Explore SwiftUI features interactively.
Key Takeaways:
- SwiftUI’s declarative UI simplifies building interfaces that respond to data changes.
- Swift’s property wrappers like
@StateObject
,@Published
, and@EnvironmentObject
help maintain and share state across views. - Understanding MVVM architecture for cleaner code maintenance.
Chosen Base Project: Travel-Booking-App-SwiftUI
Features Identified:
- Hotel & activity browsing.
- Shopping cart-like booking mechanism.
- MapKit integration for showing locations.
- Apple Pay for quick payments.
- MVVM architecture for maintainable code.
Planned Modifications:
- Integrate Apple Watch support.
- Ensure data consistency across iOS and watchOS.
- Add Hong Kong-specific hotels and attractions data.
- Streamline UI/UX and remove unnecessary components.
- Prepare logging system for booking operations (SQL integration planned).
Goal: Enable browsing and booking hotels on Apple Watch, and sync those bookings back to the iOS app’s shopping cart.
Key Steps:
- Shared Data Models:
Place shared data models (e.g.,
Hotels
,HotelType
) in a “Shared” folder. Enable Target Membership for both iOS and watchOS targets so both apps share identical data definitions. - Data Synchronization with WatchConnectivity:
- Use
WCSession
to communicate between watchOS and iOS. - When a hotel is booked on watchOS, send its data to iOS via
sendMessage
. - On iOS, upon receiving the data, update
HotelType.shared
so the shopping cart view refreshes automatically.
- Use
- Maintaining Data Consistency:
By relying on a single source of truth (
HotelType.shared
), data changes on iOS propagate to all views. Similarly, watchOS initiates changes via messages, and iOS updates the single data store.
Icon Generation: Use a tool like appicon.co to generate app icons and ensure a professional look on all platforms.
WatchConnectivity Setup:
-
iOS Side (
iOSAppSessionManager
):class iOSAppSessionManager: NSObject, WCSessionDelegate { static let shared = iOSAppSessionManager() let session = WCSession.default override init() { super.init() if WCSession.isSupported() { session.delegate = self session.activate() } } func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { // Parse hotel data and update HotelType.shared } }
-
watchOS Side (
WatchSessionManager
):class WatchSessionManager: NSObject, WCSessionDelegate, ObservableObject { static let shared = WatchSessionManager() let session = WCSession.default override init() { super.init() if WCSession.isSupported() { session.delegate = self session.activate() } } func sendHotelToiPhone(hotel: Hotels) { // Send hotel data dictionary via session.sendMessage(...) } }
HotelType Singleton:
class HotelType: ObservableObject {
static let shared = HotelType()
@Published var hotelComponent: [Hotels] = []
func addHotels(newItem: Hotels) {
hotelComponent.append(newItem)
}
}
By injecting HotelType.shared
into the ContentView
environment, both iOS and watchOS UIs update automatically when hotelComponent
changes.
Completed Tasks:
- Data consistency between iOS and watchOS.
- A working example of sending a booked hotel from Apple Watch to iOS.
- UI updates in the iOS CartView upon receiving new bookings.
- Cleaned up code, documented steps, and prepared final demonstration.
- Initialized Project & Researched: Chose a strong base (Travel-Booking-App-SwiftUI).
- Learned Swift & SwiftUI Basics: Ensured understanding of the language and framework.
- Analyzed and Modified the Codebase: Integrated watchOS target, shared data models, applied MVVM architecture.
- Implemented Data Synchronization: Used WatchConnectivity for seamless cross-device updates.
- Refined & Documented: Cleaned code, added icons, tested communication, and prepared final docs.
- iOS Simulation: Run app in iOS Simulator.
- watchOS Simulation: Run the watch app in Watch Simulator, ensure both are paired and connected.
- Book a Hotel on Apple Watch: Tapping "Register" on the watch sends hotel info to iOS. iOS receives the data and updates the cart instantly.
- UI Refresh: iOS cart view automatically shows new bookings from watchOS without manual refresh.
- Data Not Syncing?
Check that
WCSession
is activated andsession.isReachable
is true. - No UI Update on iOS?
Ensure
HotelType.shared
is injected into the environment and that the UI uses@EnvironmentObject var hotelType: HotelType
. - "Modifying state during view update" Warning:
Use
DispatchQueue.main.async
for updates. If warnings persist, ensure data updates happen outside the immediate view-render cycle or slightly delay updates.
- SQL Logging: Implement a database to log bookings. When
hotelComponent
updates, add a database write operation. - Additional Payment Integrations: Expand Apple Pay features and add more robust payment handling.
- More Destinations & Enhanced UI: Introduce multiple city support, richer maps, and more interactive views.
This documentation outlines the entire development process—from initial idea and open-source code selection to integrating watchOS and ensuring data synchronization. By following these steps and best practices, you have a framework for building a coherent, multi-device travel booking app with clean architecture and a streamlined user experience.
References: