0
votes

I'm trying to get silent push from CloudKit. But it only works when my app in foreground (OR when its launched from Xcode, in that case notifications are delivered in background too).

I've enabled all corresponding Background Modes.

enter image description here

Registered for remoteNotifications and specified background fetchInterval in didFinishLaunchingWithOptions

    UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

    application.registerForRemoteNotifications()

I'm getting didRegisterForRemoteNotificationsWithDeviceToken no problems here.

I've implemented method for handling remoteNotifications:

  func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        NSLog(__FUNCTION__)

        let identifier : UIBackgroundTaskIdentifier = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler(){
        }
        CoreDataStack.sharedInstance.ensemblesSynchronizeWithCompletion(){

            UIApplication.sharedApplication().endBackgroundTask(identifier)
            completionHandler(UIBackgroundFetchResult.NewData)
        }
    }

I've tried switching CloudKit container to Production and testing with TestFlight. There results are always the same : In the foreground I'm getting CKNotifications,but for background in console I see this:

Error: apsd[81] : Silent Push: Deny app not available

Additionally I've tried: Changing container completely - no luck.

I've also edited my AppID accordingly, but I don't think its necessary for CloudKit notifications (or is it?) : enter image description here

in Settings everything is enabled : enter image description here

Console output when started from device (not from Xcode)

App running foreground : enter image description here

App running background :

enter image description here

When started from Xcode I get notification in background & foreground.

1
Is it a case of requesting permission from the user to use push? Maybe your app doesn't have permission in the Settings app.Drew McCormack
Background App Refresh, Notifications are allowed in Settings.CryingHippo
What are you trying to accomplish by using a background task from inside a method that is executed from the background state? That is not clear from your code.quellish

1 Answers

0
votes

If you force quit your application then iOS stops delivering push notifications to your app in the background. When you are running your app from Xcode and want to quit make sure you "Stop" the process from Xcode instead of swiping up from the app switcher on the device.

You may just have to restart your phone to get the silent push notifications to start working again.