iOS SDK setup
Add the Swift package, turn on the push capability, and initialize the SDK at launch.
The iOS SDK is a Swift package for iOS 13 and later. It installs straight from GitHub, so there is no account, token or private repository to set up.
Quick start
- Create the app in the portal. Choose Apple iOS (APNs) and upload your APNs key (
.p8) or certificate (.p12). The channel shows Active only once that file is saved. Copy the App ID from the install page. - Add the package. In Xcode choose File → Add Package Dependencies and enter
https://github.com/pushfyre-hub/pushfyre-sdk. - Enable the capabilities: Push Notifications and Background Modes → Remote notifications.
- Initialize at launch with your App ID and API address, and forward the APNs device token.
- Check it works on a physical device (the Simulator never receives an APNs token). Open Audience in the portal and the device appears there. Send yourself a push from Test Subscription.
Add the package
In Xcode choose File → Add Package Dependencies, paste https://github.com/pushfyre-hub/pushfyre-sdk, and add the PushFyre library to your app target. Or add it to your own Package.swift:
dependencies: [
.package(url: "https://github.com/pushfyre-hub/pushfyre-sdk.git", from: "1.0.2")
],
targets: [
.target(name: "YourApp", dependencies: ["PushFyre"])
]Enable capabilities
Target → Signing & Capabilities → + Capability
- Push Notifications
- Background Modes → Remote notificationsYour provisioning profile must include the Push Notifications entitlement (aps-environment).
Initialize the SDK
The Objective-C tab calls the Swift SDK through a small bridge in the same target. Import the generated header (YourApp-Swift.h) from AppDelegate.m.
import PushFyre
func application(_ application: UIApplication,
didFinishLaunchingWithOptions options: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
let environment = PushFyreEnvironment.test
#else
let environment = PushFyreEnvironment.prod
#endif
PushFyre.initialize(
PushFyreConfig(
appId: "app_49e692ad",
apiBaseUrl: "https://push.example.com/api/v1",
environment: environment
)
)
// Prompts for permission, then registers with APNs once granted.
PushFyre.requestAuthorization()
return true
}Forward the device token
These callbacks belong to your UIApplicationDelegate, so you must forward them yourself:
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
PushFyre.register(deviceToken: deviceToken)
}
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
PushFyre.registrationFailed(with: error)
}Identify and tag the device
PushFyre.login(externalUserId: userId)
PushFyre.sendTag(key: "isPremium", value: "true")
PushFyre.sendTags(["plan": "annual", "segmentId": "8"])
PushFyre.removeTag("plan")WhatsApp phone number
Ask for the number in your own screen, and explain that it will be used for WhatsApp messages from your business. Call this only after the person agrees. The SDK does not show that dialog for you.
PushFyre.setWhatsAppPhone("+14155552671")
// When they withdraw consent
PushFyre.clearWhatsAppPhone()setWhatsAppPhone unless the person has agreed. A WhatsApp campaign reaches only devices that opted in this way. See WhatsApp.Handle taps
PushFyre.setTapHandler { targetUrl, actionId in
switch actionId {
case "view_chart":
openChart()
return true
default:
return false // let the SDK open targetUrl
}
}Show images and action buttons
iOS can only show a campaign image or action buttons from a Notification Service Extension, which has to be a separate target in your app. Create one with File → New → Target → Notification Service Extension, add PushFyre to it, and replace the generated class with:
import PushFyre
class NotificationService: PushFyreNotificationService {}In-app messages
The same SDK shows in-app messages created in the portal. Nothing extra is needed for a message set to appear on app open. To show one on a particular screen or action, call PushFyre.trigger("event_name", properties: [...]). In the campaign, add an In-App Trigger whose key is event_name and whose value is true. That call is also stored as a custom event. An in-app Action name click action reaches your tap handler with that action id. See In-app messages and Custom events.
See it, then create an account
The demo shows a sample notification. It does not send a message. Create an account when you are ready to register a device.