Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
AlexGiguere
Contributor
When writing an iOS native app using the SCP Fiori SDK, small details matters.

Here are 5 tips & tricks.

1: How to remove the hairline between a navigation bar and a header section (FUIKPIHeader, FUIObjectHeader, FUIProfileHeader)




To remove the 1 pixel border line, add this line of code into the viewDidLoad method:
navigationController?.navigationBar.setValue(true, forKey: "hidesShadow")

you can also do it in the storyboard if your prefer, locate your navigation controller and from the document outline pane, select the navigation bar and add this to the User Defined Runtime Attributes



 

2: Sending descriptions/texts from ABAP in the iOS logon language


If you app is localized in different languages, you backend will need to send you the descriptions in the language of your device.

In ABAP, we used the system field SY-LANGU (system language) when selecting data from text tables. But you must be logged in the same language as your device to return the correct description properly localized.

In Xcode, inside the file OnlineODataController, add these lines at the end of the configureOData method:
if let language = Locale.preferredLanguages.first?.uppercased() {
odataProvider.httpHeaders.setHeader(withName: "sap-language", value: language)
}

this will add a header parameter, named sap-language, to all your requests. It will force SAP Gateway to use this language for logon. SAP Gateway will then do an RFC call to your SAP Backend (ECC) by passing this language.

 

3: OData PUT Request


Your backend developer has coded an update entity but when you trace your request it is sent using MERGE and not PUT, not sure why this is the default, but here is how you can resolve it
let requestOptions = RequestOptions()
requestOptions.updateMode = .replace

odataService.updateEntity(store, options: requestOptions) { (error) in
...
}

Create a RequestOptions object and then set the update mode to replace, this will force an HTTP PUT instead of MERGE.

 

4: How to leverage Swift Enum into your entity classes generated by the assistant


You have an entity field value which is linked to a domain in your backend and you don't want to hardcode the values, one way to do it would be to create some constants but in Swift we could use Enum.

We could create some constants for the possible domain values, but a better way to do that is to encapsulate the constants into an enumeration.

Example: You have an entity which represent a site, in SAP ECC, this is the table T001W.

There is a field called VLFKZ which is the site category, the possible values are A for Store and B for Distribution Center.

The backend developer has exposed you this field, named CategoryValue, 1 character.

The Swift file generated by the assistant containing this field is named Site.swift

Create a new file, name it Site+Extension.swift and add this code. You don't want to do this in the Site.swift file because it could be overwritten by the assistant or when you regenerate your proxy classes from the CLI.
import Foundation

extension Site {

enum Category: String {
case store = "A"
case distributionCenter = "B"
}

var category: Category {
get {
return Category(rawValue: categoryValue) ?? .store
}
set {
categoryValue = newValue.rawValue
}
}
}

Now if you want to test the site category for an equality, you could do like this:
if site.category == .store {
...
}

this is much cleaner and it will make your code more readable.

 

5: You want to consume a service where the CSRF protection has been disabled in your SAP Gateway frontend server.


Personally, I never seen any native API using the CSRF protection, this is mostly used in web development. This protection is on by default in SAP Gateway.

How to check if the CSRF protection has been disabled? Go in transaction SICF, locate you service under sap/opu/odata/sap, double-click the service node, from the first tab, click on the GUI Configuration button at the bottom of the screen check for this parameter:



Let's say you have a case where this protection has been disable in SAP Gateway. If you don't do nothing, all your CRUD HTTP requests will failed.

You will need to pass a special HTTP header parameter to indicate you would like to bypass this validation.

In iOS, before calling any CRUD functions, make sure you supply this parameter:
let requestHeaders = HTTPHeaders()
requestHeaders.setHeader(withName: "X-Requested-With", value: "X")

odataService.updateEntity(store, headers: requestHeaders, options: requestOptions) { (error) in
...
}

SAP should add an option in their SDK to turn off the CSRF protection

 

I hope these 5 simple tips & tricks could help you.

thanks

Alex
Labels in this area