skip to Main Content

What do you do when you don’t have an entitlements file already?

2

Answers


  1. Chosen as BEST ANSWER

    There are several sources that can help you implement critical alerts for your iOS app. I found two that were very helpful:

    https://www.tapcode.co/2018/10/17/how-to-implement-critical-alerts-in-ios-12/

    https://medium.com/@shashidharyamsani/implementing-ios-critical-alerts-7d82b4bb5026#:~:text=iOS%2012%20has%20the%20critical,allowed%20to%20send%20critical%20alerts.

    Both describe what is necessary to request approval from Apple and how to update your project to include critical alerts notifications – with one exception. The articles explain how to update your entitlements file to add the critical alerts key. But what do you do when your app currently does not have an entitlements file? After a bit of research, I arrived at the following steps that can be used as a guide for dealing with this dilemma. When you get to the part of the articles that tackle updating the entitlements file please proceed as follows:

    1. Under the Capabilities tab, click on + (plus) to add a capability (I picked Keychain Sharing). This will cause Xcode to generate a .entitlements file (major hurdle overcome).
    2. Click on that file in the Project Navigator to open it. You will see the key for the capability that you have chosen (Keychain Sharing) if the disclosure triangle next to Entitlements File is open. If the disclosure triangle is not open, please click it to open it.
    3. Click on + (plus) next to Entitlements File to add an entitlement. A dropdown with selections will appear but you will have to type the key for critical alerts notifications in order to enter it manually.
    4. Enter the key for critical alerts notifications that is in the articles: com.apple.developer.usernotifications.critical-alerts
    5. Change the type to Boolean and select YES as the value.
    6. Click on – (dash) next to the capability that you used to create the entitlements file in step 1 (Keychain Sharing) to delete it. You now have an entitlements file with the critical alerts key that you need.
    7. Build and run your app and you should see the prompt that asks the user to allow critical alerts.

    Mission accomplished!

    Terry Chaisson


  2. GUIDE OF HOW TO IMPLEMENT IOS CRITICAL ALERTS [JULY 2021]

    First Steps

    1. You need to request a Critical Alert Notifications Entitlement on the Apple website.

    2. Then you need to wait for the approval of your request from the Apple side. They will send you an email. In my case, I waited only 3 days. Some developers waited for answers for around 1-4 weeks.

    WHAT DO YOU NEED TO DO AFTER REQUEST APPROVAL?

    1. Open the Identifiers page on developer.apple.com and select the identifier of the application where you are want to enable critical alerts.
      enter image description here

    2. On the page that opens, click «Additional features» and tick the «Critical Alerts» box. Then click the«Save» button.
      enter image description here

    3. Navigate to the Profile page and click plus button to register a New Provisioning Profile.
      enter image description here

    4. Select the «iOS App Development» option and click the «Continue» button.
      enter image description here

    5. Select your application ID and click the «Continue» button.
      enter image description here

    6. Select all certificates and click the «Continue» button.
      enter image description here

    7. Select your device(s) and click the «Continue» button.
      enter image description here

    8. Type the name of your Provisioning Profile and click Generate button. The name can be for example your app name.
      enter image description here

    9. Your Provisioning Profile is ready. Click the Download button. Then double click the following file to install your Provisioning Profile.
      enter image description here

    HOW TO SELECT YOUR PROVISIONING PROFILE IN XCODE

    1. Open your Xcode project.

    2. Select your Target.

    3. Select «Signing & Capabilities».

    4. Uncheck «Automatically manage signing».

    5. In the Provisioning Profile field select the Profile that you downloaded and installed in previous steps.
      enter image description here

    6. Check entitlements.
      enter image description here

    HOW TO ADD ENTITLEMENTS FILE

    Guide by mobiledev99

    1. Click on plus to add a capability.
      enter image description here
    2. Pick «Keychain Sharing»
      enter image description here
    3. Open .entitlements file. Hover your cursor to the «Entitlements File» field and click plus button.
      enter image description here
    4. Change value key name to «com.apple.developer.usernotifications.critical-alerts»,
      type to «Boolean» and value to «1».
      enter image description here
    5. Then hover your cursor to the «Keychain Access Groups» field and click the minus button.
      enter image description here

    WHAT WE NEED TO ADD TO THE CODE

    Request authorization

    let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .badge, .sound, .criticalAlert]) { (granted, error) in}
    

    For local notifications

    Change your UNMutableNotificationContent sound to the next one:

    let notificationContent = UNMutableNotificationContent()
    notificationContent.sound = UNNotificationSound.defaultCritical
    

    If you want to use your custom sound, you need to replace the code with this one:

    let notificationContent = UNMutableNotificationContent()
    notificationContent.sound = UNNotificationSound.criticalSoundNamed(UNNotificationSoundName(rawValue:"YourCustomSound.mp3"))
    

    For push notifications(From Tapcode tutorial)

    {  
       "aps":{  
           "alert": "This is a Critical Alert!",
           "badge": 1,
           "sound": {  
             "critical": 1,
             "name": "your_custom_sound.aiff",
             "volume": 1.0
            }
         }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search