Integra Willy Push nella tua app iPhone e iPad. Tutte le push sono cifrate con chiavi nel Keychain del device. Su Enterprise puoi aggiungere la firma HMAC per autenticare ogni richiesta API.
| Requisito | Dettaglio |
|---|---|
| iOS minimo | iOS 14.0+ |
| Xcode | Xcode 15+ (consigliato) |
| Linguaggio | Swift 5.9+ (compatibile Objective-C) |
| Certificato push | APNs Key (.p8) o certificato push configurato nell'Apple Developer Portal |
| Piano Willy Push | Qualsiasi piano (Starter, Pro, Enterprise) |
| Capabilities | Push Notifications + Background Modes (Remote notifications) |
appId + appKey. Il server valida le credenziali e verifica che il Bundle ID dell'app corrisponda a quello registrato nella dashboard. Un'app non autorizzata viene rifiutata.Per le app mobile il server valida il Bundle ID (equivalente del dominio per il web) al posto dell'header Origin del browser. Questo impedisce che un'altra app possa usare le stesse credenziali.
WillyPush.xcframework e la documentazioneWillyPush.xcframework nel progetto XcodeInizializza il SDK in AppDelegate. Servono appId e appKey (li trovi nella dashboard → Impostazioni → API). Il server valida queste credenziali insieme al Bundle ID della tua app.
import WillyPush class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { WillyPush.configure( appId: "IL_TUO_APP_ID", // Dashboard → Impostazioni → API appKey: "LA_TUA_APP_KEY", // Dashboard → Impostazioni → API tags: ["app:ios", "role:customer"] ) WillyPush.registerForPush() return true } }
WillyPush.configure( appId: "IL_TUO_APP_ID", appKey: "LA_TUA_APP_KEY", hmacSecret: "LA_TUA_HMAC_SECRET", // Enterprise: firma ogni richiesta API tags: ["app:ios", "role:customer"] )
appId + appKey + Bundle ID ad ogni richiesta. Se qualcuno prova ad usare le tue credenziali da un'app con un Bundle ID diverso, la richiesta viene rifiutata. Su Enterprise, la firma HMAC aggiunge un ulteriore livello: anche con credenziali valide, senza il secret HMAC non si possono forgiare richieste.
import SwiftUI import WillyPush @main struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate var body: some Scene { WindowGroup { ContentView() } } }
| Parametro | Tipo | Default | Descrizione |
|---|---|---|---|
appId | String | — | Obbligatorio. ID dell'app (Dashboard → Impostazioni → API) |
appKey | String | — | Obbligatorio. Chiave segreta dell'app (Dashboard → Impostazioni → API) |
hmacSecret | String? | nil | Solo Enterprise. Secret HMAC per firmare ogni richiesta API |
tags | [String] | [] | Tag iniziali per la segmentazione (ruolo, categoria, città, piattaforma...) |
autoRegister | Bool | true | Registra automaticamente il device su Willy |
debug | Bool | false | Abilita log dettagliati nella Console |
Con autoRegister: true (default), il SDK gestisce automaticamente tutto il flusso E2EE.
Permesso notifiche — Il SDK richiede il permesso all'utente (alert, sound, badge)
Token APNs — iOS genera il device token e il SDK lo cattura
Chiavi E2EE — Genera una coppia di chiavi e le salva nel Keychain (protette da Secure Enclave se disponibile)
Segmentazione — Associa i tag configurati (ruolo, categoria, piattaforma) al device
Registrazione API — Invia token APNs + chiave pubblica + tag + Bundle ID alle API Willy, autenticando con appId + appKey. Su Enterprise aggiunge la firma HMAC
Push cifrata — Willy cifra ogni push con la chiave pubblica del device. Solo quel telefono può leggerla
Decrypt locale — La Notification Service Extension decripta il payload con la chiave privata e mostra la notifica
Gestione del token APNs in AppDelegate:
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { WillyPush.didRegisterForRemoteNotifications(deviceToken: deviceToken) } func application( _ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error ) { WillyPush.didFailToRegisterForRemoteNotifications(error: error) }
autoRegister: false, puoi controllare il momento della registrazione:
// Registra quando vuoi, ad esempio dopo il login WillyPush.register { result in switch result { case .success(let deviceId): print("Registrato: \(deviceId)") case .failure(let error): print("Errore: \(error)") } }
Il decrypt avviene nella Notification Service Extension (vedi sezione successiva). Per gestire il tap sulla notifica, implementa il delegate:
import WillyPush extension AppDelegate: WillyPushDelegate { func willyPush(didReceiveDecrypted payload: WillyPayload) { // Notifica ricevuta con app in foreground // payload.title, payload.body, payload.data, payload.image } func willyPush(didTapNotificationWith payload: WillyPayload) { // L'utente ha toccato la notifica if let url = payload.data["url"] { // Naviga alla schermata giusta } } }
Registra il delegate dopo l'inizializzazione:
WillyPush.delegate = self
La Notification Service Extension è il componente Apple che intercetta la push prima di mostrarla e permette al SDK di decriptare il payload con la chiave privata del device.
NotificationServiceExtension (o come preferisci)import UserNotifications import WillyPush class NotificationService: WillyPushNotificationService { // Il SDK gestisce automaticamente: // 1. Intercetta la push cifrata // 2. Legge la chiave privata dal Keychain // 3. Decripta il payload // 4. Sostituisce il contenuto della notifica // 5. Mostra la notifica decriptata all'utente // Opzionale: override per personalizzare override func didDecrypt( _ payload: WillyPayload, content: UNMutableNotificationContent ) { // Personalizza il contenuto se necessario content.title = payload.title content.body = payload.body content.sound = .default } }
$(TeamIdentifierPrefix)it.willypush.shared).
I tag permettono di segmentare gli utenti per creare campagne mirate dalla dashboard Willy Push.
// Aggiungi tag in qualsiasi momento WillyPush.addTags(["categoria:pizza", "citta:roma", "piano:premium"]) // Utile dopo il login WillyPush.addTags(["role:customer", "user_id:12345"])
WillyPush.removeTags(["role:guest", "categoria:pizza"])
WillyPush.setTags(["role:admin", "app:ios"])
let tags = WillyPush.getTags() // ["role:customer", "citta:roma", "app:ios"]
| Caso d'uso | Tag |
|---|---|
| Utente loggato vs guest | role:customer / role:guest |
| Città dell'utente | citta:roma, citta:milano |
| Categoria preferita | cat:pizza, cat:sushi |
| Piano/abbonamento | piano:free, piano:premium |
| Lingua | lang:it, lang:en |
| Piattaforma | app:ios |
Se la tua app ha un e-commerce, puoi tracciare eventi per campagne automatiche:
WillyPush.trackEvent("product_view", data: [ "productId": "SKU-123", "productName": "Pizza Margherita", "price": "8.50", "category": "pizza" ])
WillyPush.trackEvent("cart_abandoned", data: [ "cartValue": "32.00", "items": "3" ])
WillyPush.trackEvent("purchase_completed", data: [ "orderId": "ORD-456", "total": "32.00", "items": "3" ])
Il SDK gestisce automaticamente i seguenti scenari:
| Evento | Comportamento SDK |
|---|---|
| Token APNs cambia | Re-registra automaticamente su Willy con il nuovo token |
| Chiave E2EE nel Keychain | Persiste tra aggiornamenti e reinstallazioni (se il Keychain non viene cancellato) |
| App aggiornata | Verifica la registrazione e aggiorna se necessario |
| App reinstallata | Recupera la chiave dal Keychain se presente, altrimenti ne genera una nuova |
| Permesso revocato | Notifica Willy di disattivare il device |
// Quando l'utente fa logout WillyPush.removeTags(["role:customer", "user_id:12345"]) WillyPush.addTags(["role:guest"]) // Per cancellare completamente il device da Willy: WillyPush.unregister()
WillyPush.configure( appId: "IL_TUO_APP_ID", appKey: "LA_TUA_APP_KEY", debug: true // log nella Console di Xcode )
Filtra i log nella Console con il sottosistema it.willypush.
let isRegistered = WillyPush.isRegistered() let deviceId = WillyPush.getDeviceId() let tags = WillyPush.getTags()
app:ios| Metodo | Descrizione |
|---|---|
WillyPush.configure(...) | Inizializza il SDK con la configurazione |
WillyPush.registerForPush() | Richiede il permesso notifiche e registra il device |
WillyPush.register(completion:) | Registra manualmente il device su Willy |
WillyPush.unregister() | Cancella il device da Willy |
WillyPush.addTags([String]) | Aggiunge tag al device |
WillyPush.removeTags([String]) | Rimuove tag dal device |
WillyPush.setTags([String]) | Sostituisce tutti i tag |
WillyPush.getTags() -> [String] | Restituisce i tag attuali |
WillyPush.trackEvent(name, data:) | Traccia un evento e-commerce/custom |
WillyPush.isRegistered() -> Bool | Verifica se il device è registrato |
WillyPush.getDeviceId() -> String? | Restituisce l'ID device Willy |
WillyPush.didRegisterForRemoteNotifications(deviceToken:) | Passa il token APNs al SDK |
Si. L'inizializzazione avviene in AppDelegate (usa @UIApplicationDelegateAdaptor con il protocol App). Il resto dell'app può usare qualsiasi architettura UI.
Su tutti i piani le push sono cifrate E2EE: il device genera le chiavi nel Keychain, Willy cifra, la Notification Service Extension decripta. Il codice è identico.
La differenza è che su Enterprise puoi aggiungere hmacSecret per firmare ogni richiesta API con HMAC-SHA256. Questo aggiunge un livello di sicurezza extra: impedisce registrazioni non autorizzate e garantisce che solo la tua app possa comunicare con il tuo account.
Poiché tutte le push sono cifrate, Apple non permetterebbe di mostrarle direttamente (il contenuto sarebbe illeggibile). La Notification Service Extension è l'unico punto dove il SDK può decriptare il payload prima che venga mostrato all'utente. È obbligatoria su tutti i piani.
Si. Su Starter e Pro non serve. Le push sono comunque cifrate E2EE. L'HMAC è un livello aggiuntivo disponibile su Enterprise.
Si. Il SDK funziona su iPhone e iPad con lo stesso codice. Le push arrivano su entrambi i device se registrati.
Si. Le API pubbliche del SDK sono annotate con @objc e compatibili con Objective-C.
Il framework pesa meno di 100 KB. Non ha dipendenze esterne oltre ai framework Apple standard.
Si. Il SDK rileva automaticamente se stai usando l'ambiente sandbox (development) o production. Willy Push gestisce entrambi.
Scarica il SDK, segui la guida e in meno di 15 minuti la tua app iOS riceve push cifrate E2EE su qualsiasi piano.