Skip to content

FioriAR 2.0 Migration Guide

MarcoEidinger edited this page Dec 7, 2021 · 2 revisions

FioriAR 2.0 contains breaking changes if you want to upgrade from 1.x version.

The following highlights the most important changes which help you transitioning your code from 1.x to 2.0

  • Module FioriARKit was renamed to FioriAR. Also the Swift Package depends on SAP BTP SDK for iOS binary frameworks SAPCommon and SAPFoundation.
    • Hence you have to remove the package library and and re-add the appropriate package library. Otherwise you will encounter Package Loading: Error "Missing package product 'FioriARKit'".
      • Choose FioriAR if you did not already embed binary frameworks from SAP BTP SDK for iOS.
      • Choose FioriAR-requiresToEmbedXCFrameworks if you already embedded SAPCommon and SAPFoundation binary frameworks to your target.
    • You also have to adjust the import statements or otherwise you will encounter Swift Compile Error: "No such module 'FioriARKit'".
  • SwiftUI View SingleImageARCardView was renamed to ARAnnotationsView.
  • ARAnnotationsView initialization parameter image was renamed to guideImage and its type changed from a Image to UIImage.
  • Struct DecodableCardItem was renamed to CodableCardItem as it conforms to Codable nowadays.
  • Function ARAnnotationViewModel.load(loadingStrategy) can throw now and requires to be marked with try.
  • Several changes to CardItemModel protocol
    • New optional properties, i.e. actionContentURL and position
    • Renamed property: descriptionText_ was renamed to subtitle_
    • Changed data type for properties, i.e type of detailImage_ was changed from Image? to Data?, type of icon_ was changed from Image? to String?

Example

The following code compiled with 1.x

import FioriARKit
import SwiftUI

struct FioriAR_Example: View {
    @StateObject var arModel = ARAnnotationViewModel<DecodableCardItem>()

    var body: some View {
        SingleImageARCardView(arModel: arModel, image: Image("qrImage"), cardAction: { id in
            print("handle action for \(id)")
        })
        .onAppear(perform: loadInitialData)
    }

    func loadInitialData() {
        let usdzFilePath: URL! // URL to a local .usdz file
        guard let anchorImage = UIImage(named: "qrImage"),
              let jsonUrl = Bundle.main.url(forResource: "Tests", withExtension: "json") else { return }

        do {
            let jsonData = try Data(contentsOf: jsonUrl)
            let strategy = try UsdzFileStrategy(jsonData: jsonData, anchorImage: anchorImage, physicalWidth: 0.1, usdzFilePath: usdzFilePath)
            arModel.load(loadingStrategy: strategy)
        } catch {
            print(error)
        }
    }

but does not compile with 2.0 and therefore requires the following code changes

Before After
import FioriARKit
import FioriAR
SingleImageARCardView(
  arModel: arModel,
  image: Image("qrImage"),
  cardAction: { id in
    print("handle action for \(id)")
})
ARAnnotationsView(
  arModel: arModel,
  guideImage: UIImage(named: "qrImage"),
  cardAction: { id in
    print("handle action for \(id)")
})
arModel.load(loadingStrategy: strategy)
try arModel.load(loadingStrategy: strategy)

The adjusted example looks like the following and will compile successfully in 2.0

import FioriAR // CHANGED !!
import SwiftUI

struct FioriAR_Example: View {
    @StateObject var arModel = ARAnnotationViewModel<CodableCardItem>() // CHANGED !!

    var body: some View {
        // CHANGED !!
        ARAnnotationsView(arModel: arModel, guideImage: UIImage(named: "qrImage"), cardAction: { id in
            print("handle action for \(id)")
        })
        .onAppear(perform: loadInitialData)
    }

    func loadInitialData() {
        let usdzFilePath: URL! // URL to a local .usdz file
        guard let anchorImage = UIImage(named: "qrImage"),
              let jsonUrl = Bundle.main.url(forResource: "Tests", withExtension: "json") else { return }

        do {
            let jsonData = try Data(contentsOf: jsonUrl)
            let strategy = try UsdzFileStrategy(jsonData: jsonData, anchorImage: anchorImage, physicalWidth: 0.1, usdzFilePath: usdzFilePath)
            try arModel.load(loadingStrategy: strategy) // CHANGED !!
        } catch {
            print(error)
        }
    }
Clone this wiki locally