Skip to content

Commit a6718a5

Browse files
authored
Merge pull request #2426 from qualiture/master
Theme download for iOS apps
2 parents d00fc9b + aa30614 commit a6718a5

6 files changed

Lines changed: 168 additions & 0 deletions
217 KB
Loading
411 KB
Loading
337 KB
Loading
327 KB
Loading
27.6 KB
Loading
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
title: Download Stylesheet from SAP Cloud Platform to your iOS App
3+
description: Upload a stylesheet to SAP Cloud Platform mobile service for development and operations and download it to your app during the onboarding flow
4+
primary_tag: products>sap-cloud-platform-sdk-for-ios
5+
tags: [ tutorial>beginner, operating-system>ios, topic>mobile, products>sap-cloud-platform, products>sap-cloud-platform-sdk-for-ios ]
6+
---
7+
8+
## Prerequisites
9+
- **Proficiency:** Beginner
10+
- **Tutorials:** [Sign up for a free trial account on SAP Cloud Platform](https://www.sap.com/developer/tutorials/hcp-create-trial-account.html) and [Enable SAP Cloud Platform mobile service for development and operations](https://www.sap.com/developer/tutorials/fiori-ios-hcpms-setup.html)
11+
- **Development environment:** Apple iMac, MacBook or MacBook Pro running Xcode 9.3 or higher
12+
- **SAP Cloud Platform SDK for iOS:** Version 2.2
13+
14+
## Details
15+
### You will learn
16+
In tutorial [Customize theme and on-boarding of iOS app](https://www.sap.com/developer/tutorials/fiori-ios-scpms-custom-app-theming.html) you created a custom [`NUI`](https://github.com/tombenner/nui) stylesheet which was then included in the app's project. The biggest drawback to this approach is that for every style change, you need to rebuild and deploy your app.
17+
18+
Since version 2.2 of the SAP Cloud Platform SDK for iOS, you can now upload stylesheets to SAP Cloud Platform mobile service for development and operations, and during the onboarding flow, your app will then download the latest changes. In this tutorial, you will create a stylesheet and upload it to SAP Cloud Platform mobile service for development and operations. You will then modify the app's onboarding flow so it will download and apply the stylesheet.
19+
20+
For this tutorial, you can use any iOS app you have previously created with the SAP Cloud Platform SDK for iOS Assistant. However, the screenshots and parameters used in this tutorial are taken from the `OfflineDemo` app created in tutorial [Create an iOS App with Offline Capabilities](https://www.sap.com/developer/tutorials/fiori-ios-scpms-offline-odata.html). If you want to follow this tutorial to the letter, make sure you have finished creating the `OfflineDemo` app.
21+
22+
### Time to Complete
23+
**15 Min**
24+
25+
---
26+
27+
[ACCORDION-BEGIN [Step 1: ](Create a NUI stylesheet)]
28+
29+
Create a file named `CustomTheme.nss`. There are various ways to create a file on macOS, but the simplest is to open a terminal, and type the following:
30+
31+
```bash
32+
cd ~/Desktop
33+
touch CustomTheme.nss
34+
```
35+
36+
This will create the `CustomTheme.nss` file on your desktop.
37+
38+
Right-click the newly created file on your desktop, and open it with your text editor of choice.
39+
40+
Add the following content:
41+
42+
```css
43+
NavigationBar {
44+
bar-tint-color: #B0D450;
45+
}
46+
47+
BarButton {
48+
font-color: #3A835B;
49+
}
50+
51+
fdlFontStyle_subheadline {
52+
font-style: subheadline;
53+
font-color: #3A835B;
54+
}
55+
56+
fdlFUIWelcomeScreen_headlineLabel {
57+
font-color: #3A835B;
58+
}
59+
```
60+
61+
Save the file when done, and close the text editor.
62+
63+
[ACCORDION-END]
64+
65+
[ACCORDION-BEGIN [Step 2: ](Upload the stylesheet)]
66+
67+
Log on to SAP Cloud Platform mobile service for development and operations cockpit at `https://hcpmsadmin-<your_user_id>trial.dispatcher.hanatrial.ondemand.com/` and navigate to **Mobile Applications > Native/Hybrid**:
68+
69+
![Upload the stylesheet](fiori-ios-scpms-theme-download-01.png)
70+
71+
Click on the application you want to have universal link support, and under **Assigned Features**, click the **Client Resources** feature:
72+
73+
![Upload the stylesheet](fiori-ios-scpms-theme-download-02.png)
74+
75+
In the page that opens, click the **Upload Client Resource** button on the right. The **New Client Resource** popup opens.
76+
77+
Add the following details:
78+
79+
| Field Name | Value |
80+
|----|----|
81+
| Bundle Name | `CustomTheme` |
82+
| Version | `1.0` |
83+
| Upload Client Resource | Click the **Browse** button and point to the `CustomTheme.nss` file on your desktop |
84+
85+
![Upload the stylesheet](fiori-ios-scpms-theme-download-03.png)
86+
87+
Click **OK** when done. The uploaded stylesheet is now listed:
88+
89+
![Upload the stylesheet](fiori-ios-scpms-theme-download-04.png)
90+
91+
92+
[ACCORDION-END]
93+
94+
95+
[ACCORDION-BEGIN [Step 3: ](Implement the stylesheet download steps)]
96+
97+
Open your app's `Onboarding/OnboardingManager.swift` file. In class `OnboardingManager`, just above the `delegate` field, add the following private fields:
98+
99+
```swift
100+
private var nssResource: SAPcpmsClientResourcesDownloadStep.ClientResourceInfo? = nil
101+
private var nssResourceURL: URL? = nil
102+
```
103+
104+
The first field will store the stylesheet as an instance of `SAPcpmsClientResourcesDownloadStep.ClientResourceInfo`. The second field will hold the internal URL to the downloaded stylesheet.
105+
106+
Now, create two helper functions. One will retrieve the uploaded stylesheet, and the other will construct a URL based on the results of the first method:
107+
108+
```swift
109+
private func getNssResource() -> SAPcpmsClientResourcesDownloadStep.ClientResourceInfo {
110+
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
111+
let nssResource = SAPcpmsClientResourcesDownloadStep.ClientResourceInfo(mandatory: true, canOverwrite: true, name: "CustomTheme", version: nil, folderURL: path)
112+
113+
return nssResource
114+
}
115+
116+
private func getNssResourceURL(nssResource: SAPcpmsClientResourcesDownloadStep.ClientResourceInfo) -> URL {
117+
let url = nssResource.folderURL!.appendingPathComponent("\(nssResource.name ?? "Theme").nss").standardizedFileURL
118+
return url
119+
}
120+
```
121+
122+
And finally, you need to modify the variables `onboardingSteps` and `restoringSteps` by adding a step for the download of the stylesheet, and a step for applying the stylesheet.
123+
124+
In both `onboardingSteps` and `restoringSteps` variables, add the following variable assignments:
125+
126+
```swift
127+
nssResource = getNssResource()
128+
nssResourceURL = getNssResourceURL(nssResource: nssResource!)
129+
```
130+
131+
These variables are now assigned with the results from the two helper methods you created.
132+
133+
Then, in `onboardingSteps`, add the following step right after the `settingsDownload` step:
134+
135+
```swift
136+
SAPcpmsClientResourcesDownloadStep(clientResourceInfoList: [nssResource!]),
137+
```
138+
139+
and add the following right after the `applyDuringOnboard` step:
140+
141+
```swift
142+
NUIStyleSheetApplyStep(fileURL: nssResourceURL!),
143+
```
144+
145+
Similarly, in `restoringSteps`, add the following step right after the `settingsDownload` step (which may be commented out, depending if you're using an online or offline enabled app):
146+
147+
```swift
148+
SAPcpmsClientResourcesDownloadStep(clientResourceInfoList: [nssResource!]),
149+
```
150+
151+
and add the following right after the `applyDuringRestore` step:
152+
153+
```swift
154+
NUIStyleSheetApplyStep(fileURL: nssResourceURL!)
155+
```
156+
157+
[ACCORDION-END]
158+
159+
[ACCORDION-BEGIN [Step 4: ](Build and run the app)]
160+
161+
Build and run the app. After you have logged on, you'll notice the app now uses the stylesheet you uploaded to SAP Cloud Platform:
162+
163+
![Upload the stylesheet](fiori-ios-scpms-theme-download-05.png)
164+
165+
166+
[ACCORDION-END]
167+
168+
---

0 commit comments

Comments
 (0)