I’m trying to configure push notifications with back4app backend in my iOS app using this guide: https://www.back4app.com/docs/ios/push-notifications/ios-send-push-notification-from-server
import UIKit
import ParseSwift
import StoreKit
import UserNotifications
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let server: ServerFeaturesProtocols = ParseServerService()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
ParseSwift.initialize(applicationId: "applicationID", clientKey: "clientKey", serverURL: URL(string: "https://serverURl")!)
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound, .carPlay]) { granted, error in
guard granted else { return }
self.getNotificationSettings()
}
print("sessionToken (PSUser.current?.sessionToken)")
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
if let receiptData = try? Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped) {
let receiptString = receiptData.base64EncodedString(options: [])
}
}
SKPaymentQueue.default().add(SubscriptionManager.shared)
SubscriptionManager.shared.fetchAvailableProducts()
return true
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
print("Notification settings: (settings)")
guard settings.authorizationStatus == .authorized else { return }
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
createInstallationOnParse(deviceTokenData: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register for remote notifications: (error.localizedDescription)")
}
func applicationWillTerminate(_ application: UIApplication) {
SKPaymentQueue.default().remove(SubscriptionManager.shared)
}
func createInstallationOnParse(deviceTokenData:Data){
if let installation = PFInstallation.current {
installation.setDeviceTokenFrom(deviceTokenData)
installation.saveInBackground {
(success: Bool, error: Error?) in
if (success) {
print("You have successfully saved your push installation to Back4App!")
} else {
if let myError = error {
print("Error saving parse installation (myError.localizedDescription)")
} else {
print("Uknown error")
}
}
}
}
}
}
I receive an error: Cannot find ‘PFInstallation’ in scope although I have all imports
I tried replace PFInstallation with ParseInstallation but it didn’t work
1