I'm using back4app and there documention socks... this was working fine two weeks ago, i lost my build and have had to rebuild my project from scratch, there doumention is missing replaced with errors or links to other usless info... and i can not get my app to recieve notifications at all! Ok rant aside heres what i have, Permisions and notifications done, and code below (app deligate) - My APP & Client ID (hidden from the forums.
import UIKit
import Parse
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let configuration = ParseClientConfiguration {
$0.applicationId = "Hidden"
$0.clientKey = "Hidden"
$0.server = "https:/
}
Parse.initialize(with: configuration)
saveInstallationObject()
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
}
}
func applicationWillResignActive(_ application: UIApplication) {
/
/
}
func applicationDidEnterBackground(_ application: UIApplication) {
/
/
}
func applicationWillEnterForeground(_ application: UIApplication) {
/
}
func applicationDidBecomeActive(_ application: UIApplication) {
/
}
func applicationWillTerminate(_ application: UIApplication) {
/
}
func saveInstallationObject(){
if let installation = PFInstallation.current(){
installation.saveInBackground {
(success: Bool, error: Error?) in
if (success) {
print("You have successfully connected your app to Back4App!")
} else {
if let myError = error{
print(myError.localizedDescription)
}else{
print("Uknown error")
}
}
}
}
}
}
Support finally reached out. The app sample and documention is outdated so this is the code that can be used temp for awhile.
import UIKit
import UserNotifications
import Parse
/
/
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
/
/
/
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
/
/
/
let configuration = ParseClientConfiguration {
/
$0.applicationId = "id"
/
$0.clientKey = "key"
/
$0.server = "https:/
/
/
$0.isLocalDatastoreEnabled = true
}
Parse.initialize(with: configuration)
/
/
/
/
/
/
PFUser.enableAutomaticUser()
let defaultACL = PFACL()
/
defaultACL.getPublicReadAccess = true
PFACL.setDefault(defaultACL, withAccessForCurrentUser: true)
if application.applicationState != UIApplicationState.background {
/
/
/
let oldPushHandlerOnly = !responds(to: #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:)))
var noPushPayload = false
if let options = launchOptions {
noPushPayload = options[UIApplicationLaunchOptionsKey.remoteNotification] == nil
}
if oldPushHandlerOnly || noPushPayload {
PFAnalytics.trackAppOpened(launchOptions: launchOptions)
}
}
if #available(iOS 10.0, *) {
/
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
print("Notifications access granted: \(granted.description)")
}
application.registerForRemoteNotifications()
} else {
/
let types: UIUserNotificationType = [.alert, .badge, .sound]
let settings = UIUserNotificationSettings(types: types, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
return true
}
/
/
/
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let installation = PFInstallation.current()
installation?.setDeviceTokenFrom(deviceToken)
installation?.saveInBackground()
PFPush.subscribeToChannel(inBackground: "") { succeeded, error in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n")
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error!)
}
}
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
if error._code == 3010 {
print("Push notifications are not supported in the iOS Simulator.\n")
} else {
print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
}
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
PFPush.handle(userInfo)
if application.applicationState == UIApplicationState.inactive {
PFAnalytics.trackAppOpened(withRemoteNotificationPayload: userInfo)
}
}
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
}