Search code examples
iosswiftpush-notificationapple-push-notificationsprovisioning-profile

Are remote notifications possible for free provisioning account?


I'm slightly confused about the difference between "normal" push notifications vs. remote notifications, as well as which of them is possible with my free provisioning profile.

I'm able to send push notifications that appear on lock-screen with the following code:

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool {
        ...
        registerForPushNotifications()
        createNotification()
        return true
    }
    
    func registerForPushNotifications() {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { [weak self] granted, _ in
            print("Permission granted: \(granted)")
            guard granted else { return }
        }
    }
    
    static func createNotification() {
        let content = UNMutableNotificationContent()
        content.title = "test-title"

        // 2. create trigger
        var components = DateComponents.init()
        components.hour = 14
        components.minute = 39
        let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)

        content.badge = 1
        content.sound = UNNotificationSound.default
        
        // 4. create send request
        let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)

        // add request to send center
        UNUserNotificationCenter.current().add(request) { error in
            if error == nil {
                print("Time Interval Notification scheduled!")
            }
        }
    }

However, what I really want is to create a daily notification that is based on some HTTP request.
In other words, I would like to send an HTTP request to some API (say it returns a boolean value) and create a notification based on that value.

I've done some research and I think that remote notifications are capable of doing so.
Unfortunately, when I try to register for remote notifications:

DispatchQueue.main.async {
    UIApplication.shared.registerForRemoteNotifications()
}

I get an error: no valid “aps-environment” entitlement string found for application.

As I've stated - I do not have a paid Apple developer membership.

My questions are:

  1. will remote notifications actually fulfill my needs?
  2. Are remote notifications possible with free provisioning account?

I've found that "normal" push notifications are indeed possible.

Thanks!


Solution

    1. It seems you have a misunderstanding about how remote push notifications work. Your server needs to schedule the remote notifications, not your app. You can schedule a daily remote notification on your server, which should suffice your needs, but as I've said, you'll need server-side logic to achieve this.

    2. No - you need a paid developer membership to be able to use remote push notifications. Local notifications require no paid membership, but remote ones do.