-
Notifications
You must be signed in to change notification settings - Fork 8
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 toFioriAR
. Also the Swift Package depends on SAP BTP SDK for iOS binary frameworksSAPCommon
andSAPFoundation
.- 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 embeddedSAPCommon
andSAPFoundation
binary frameworks to your target.
- Choose
- You also have to adjust the import statements or otherwise you will encounter
Swift Compile Error: "No such module 'FioriARKit'"
.
- Hence you have to remove the package library and and re-add the appropriate package library. Otherwise you will encounter
- SwiftUI View
SingleImageARCardView
was renamed toARAnnotationsView
. -
ARAnnotationsView
initialization parameterimage
was renamed toguideImage
and its type changed from aImage
toUIImage
. - Struct
DecodableCardItem
was renamed toCodableCardItem
as it conforms toCodable
nowadays. - Function
ARAnnotationViewModel.load(loadingStrategy)
can throw now and requires to be marked withtry
. - Several changes to
CardItemModel
protocol- New optional properties, i.e.
actionContentURL
andposition
- Renamed property:
descriptionText_
was renamed tosubtitle_
- Changed data type for properties, i.e type of
detailImage_
was changed fromImage?
toData?
, type oficon_
was changed fromImage?
toString?
- New optional properties, i.e.
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)
}
}