Examples - themobilitybox/mobilitybox-ticketing-ios GitHub Wiki
Static Coupon List
The following example showing how to create a static list of Coupons in your App.
import SwiftUI
import Mobilitybox
struct CouponsView: View {
let couponIds = ["mobilitybox-coupon-abcdef1", "mobilitybox-coupon-abcdef2", "mobilitybox-coupon-abcdef3", ...]
@State var coupons: [MobilityboxCoupon]!
init() {
Mobilitybox.setup(apiConfig: MobilityboxAPI.Config(apiURL: "https://api.themobilitybox.com/v2"))
}
var body: some View {
NavigationView {
VStack {
List {
ForEach($coupons, id: \.id) { coupon in
VStack {
MobilityboxCardView(coupon: $coupon)
}
.listRowInsets(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
.listRowBackground(Color.white.opacity(0.0))
}
}
}
}.onAppear(perform: loadCoupons)
}
private func loadCoupons() {
for couponId in couponIds {
MobilityboxCouponCode(couponId: couponId).fetchCoupon(completion: { fetchedCoupon in
self.coupons.append(fetchedCoupon)
})
}
}
}
Subscription - Reactivate Ticket
The following example showing how to reactivate a ticket and add the reactivated one to your list. When a user not using the app frequently and the subscription was reordered multiple times without reactivating the ticket, it is useful to check if the new ticket can be reactivated again.
var ticketList: [MobilityboxTicket] = [...] // array with a list of tickets
func reactivateTicket(ticket: MobilityboxTicket, completion: (MobilityboxTicket) -> ()) {
ticket.reactivate { reactivatedTicketCode in
reactivatedTicketCode.fetchTicket { reactivatedTicket in
completion(reactivatedTicket)
reactivateTicket(ticket: reactivatedTicket, completion: completion) // try to reactivate the reactivated Ticket again
}
}
}
for ticket in ticketList {
reactivateTicket(ticket: ticket) { reactivatedTicket in
ticketList.append(reactivatedTicket) // add new ticket into your list
}
}