Push Notifications for Existing iOS
8 min
this guide is for teams that already have firebase cloud messaging wired up — your own messagingdelegate, your own unusernotificationcenterdelegate, and possibly your own notification service extension you don't need to replace any of it on ios, appstorys doesn't own firebase — it never sets messaging messaging() delegate or unusernotificationcenter current() delegate itself instead, you add a few one line calls into the delegate methods you already have each of these calls checks the incoming payload for an appstorys notification id; if it's not present (i e the push is one of your own, not an appstorys campaign), the call is a no op and your existing handling runs exactly as before setting this up for the first time with no prior push integration? use the push notifications guide instead step 1 — enable app groups on both targets this is still needed even with an existing setup — it's how appstorys tracks "viewed" events when your app is backgrounded or killed you'll enable the same identifier on two targets your main app and your nse (step 3 below) choose an identifier in this format group com yourcompany yourapp for both targets select the target → signing & capabilities click + capability → app groups add / tick the same identifier on both step 2 — link the framework if appstorys ios isn't already linked to your nse target select your existing nse target go to general → frameworks and libraries → + add appstorys ios step 3 — merge into your appdelegate add these two calls into your existing application( didfinishlaunchingwithoptions ) and messagingdelegate conformance update the identifier to match step 1 func application( application uiapplication, didfinishlaunchingwithoptions \[uiapplication launchoptionskey any]? = nil ) > bool { // your existing firebaseapp configure() and setup stays here appstorysmessagingservice configureappgroup("group com yourcompany yourapp") // ← add this, before appstorys initialize // rest of your existing setup return true } extension appdelegate messagingdelegate { func messaging( messaging, didreceiveregistrationtoken fcmtoken string?) { if let token = fcmtoken { appstorysmessagingservice handlenewtoken(token) // ← add this // your existing token handling stays here } } } appstorysmessagingservice handlenewtoken is equivalent to calling appstorys shared setfirebasetoken(token) directly — either works this registers the device with the appstorys outreach backend so push campaigns can be delivered through your existing fcm token step 4 — merge into your unusernotificationcenterdelegate add one call into each of your two existing delegate methods func usernotificationcenter( unusernotificationcenter, willpresent notification unnotification, withcompletionhandler completionhandler @escaping (unnotificationpresentationoptions) > void) { appstorysmessagingservice handlemessagereceived( // ← add this userinfo notification request content userinfo ) // your existing foreground presentation logic stays here completionhandler(\[ banner, list, sound]) } func usernotificationcenter( unusernotificationcenter, didreceive response unnotificationresponse, withcompletionhandler completionhandler @escaping () > void) { appstorysmessagingservice handlenotificationclick( // ← add this userinfo response notification request content userinfo ) // your existing tap handling stays here completionhandler() } step 5 — merge into your notification service extension (if you have one) only one nse runs per app, so don't create a second target — add these two lines into your existing didreceive( withcontenthandler ), before your own attachment/image logic override func didreceive( request unnotificationrequest, withcontenthandler contenthandler @escaping (unnotificationcontent) > void ) { self contenthandler = contenthandler self bestattempt = (request content mutablecopy() as? unmutablenotificationcontent) let userinfo = request content userinfo appstorysmessagingservice configureappgroup("group com yourcompany yourapp") // ← add this = appstorysmessagingservice handlemessagereceivedblocking(userinfo userinfo) // ← add this // your existing image download / attachment logic stays here } handlemessagereceivedblocking is the nse safe variant — it blocks until the "viewed" event is sent (or the tracker's internal cap is hit), which matters here because the nse process gets terminated shortly after didreceive returns don't have an nse yet and want appstorys's background "viewed" tracking? you'll need to add one — see steps 1, 3, and 4 of the main push notifications guide for the nse target creation and full code, and drop that into your project as a new target rather than merging managing push opt in/opt out if your app has its own notification preference toggle (separate from the os permission), use appstorys shared subscribenotifications() appstorys shared unsubscribenotifications() call unsubscribenotifications() when the user turns your in app push toggle off, and subscribenotifications() when they turn it back on this only affects whether appstorys sends campaigns to the user server side — it doesn't remove the fcm token os level permission changes (user denies/allows notifications from system settings) are already detected and synced automatically — you don't need to call this yourself for that case requires the sdk to already be initialized and userid to be set