Quick Start
This article provides a rapid integration example of Altcraft mSDK v2 with Apple Push Notification System (APNS) and Firebase Cloud Messaging (FCM). After completing the steps, your app will be able to receive Altcraft push notifications.
To use Huawei Mobile Services, add the corresponding SDKs to the project and implement their interfaces using the same approach shown for APNS and FCM.
Step 0. Prerequisites
- APNS access obtained on the website;
- The app is configured in a Firebase project, and
GoogleServiceInfo.plistis downloaded.
Step 1. Add packages (Swift Package Manager)
Add packages from repositories using Swift Package Manager:
- Repository Altcraft SDK;
- Repository Firebase.
Step 2. Add GoogleServiceInfo to the app
Add GoogleServiceInfo.plist to your app folder:
Step 3. App preparation
Configure the following app target settings:
-
General:
- Ensure the Altcraft library is added under Frameworks, Libraries, and Embedded Content of the app target:
* Ensure the **FirebaseMessaging** library is added under **Frameworks, Libraries, and Embedded Content** of the app target:
-
Signing & Capabilities:
- PushNotifications;
- AppGroups — specify a group identifier (adding an App Group identifier is required for data exchange with the Notification Service Extension);
- Background Modes — enable Background fetch, Remote notification, Background processing.
-
Info:
- Add the following keys and values:
| Key | Type | Value |
|---|---|---|
| Permitted background task scheduler identifiers | Array | "lib.Altcraft.bgTask.systemControl" |
| FirebaseAppDelegateProxyEnabled | Boolean | NO |
The first key registers a bgTask that retries failed server requests in background mode. The second key disables the automatic method swizzling of AppDelegate that Firebase Messaging performs by default.
Step 4. Implement protocols
JWT
Implement the SDK protocol for providing a JWT token. Create a class that implements JWTInterface and override getJWT():
import Altcraft
class JWTProvider: JWTInterface {
func getToken() -> String? {
// your code returning JWT
}
}
getJWT() is a synchronous function. The SDK execution thread will be paused until JWT is obtained. It’s recommended that getJWT() returns immediately from cache (in-memory, SharedPreferences or EncryptedSharedPreferences) to speed up requests. Ideally, prepare a fresh JWT as early as possible (at app start) and store it in cache so the token is available without delays. Returning nil is acceptable if no value is available.