How to use fastlane pem to automatically generate and renew your VoIP push notification profiles

In the previous tutorial, I showed you how easy it is to use fastlane pem to automatically generate and renew your push notification profiles.

In this tutorial, I’ll do the same thing, but for VoIP notifications. I found the solution in this Github issue.

In your project’s root folder create a new folder called fastlane.

Then, create a file called Fastfile in the fastlane folder.

Put the following content into Fastfile:

lane :voip_cert do
    app_identifier = "com.nikola.mygreatapp"
    apple_id = "[email protected]"
    output_path = "."
    p12_password = "password"

    UI.important "Creating a new push certificate for app '#{app_identifier}'."

    Spaceship.login(apple_id)
    Spaceship.client.select_team
    csr, pkey = Spaceship::Certificate.create_certificate_signing_request
    cert = Spaceship::Certificate::VoipPush.create!(csr:csr,bundle_id:app_identifier)

    x509_certificate = cert.download
    certificate_type = "voippush"
    filename_base = "#{certificate_type}_#{app_identifier}"

    p12_cert_path = File.join(output_path, "#{filename_base}.p12")
    p12 = OpenSSL::PKCS12.create(p12_password, certificate_type, pkey, x509_certificate)
    File.write(p12_cert_path, p12.to_der)
    UI.message("p12 certificate: ".green + Pathname.new(p12_cert_path).realpath.to_s)

    x509_cert_path = File.join(output_path, "#{filename_base}.pem")
    File.write(x509_cert_path, x509_certificate.to_pem + pkey.to_pem)
    UI.message("PEM: ".green + Pathname.new(x509_cert_path).realpath.to_s)
end

Make sure you enter the appropriate app_identifier and apple_id and password (if you’re using it).

Execute the following command from your app’s root directory:

fastlane voip_cert

You should see something like this in the output:

nikola in ~/DEV/TheOnlyAppThatMatters on git:feature/make-app-great-again ✖︎ [06:06:06]
→ fastlane voip_cert
[06:06:06]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[06:06:06]: Driving the lane 'voip_cert' ?
[06:06:06]: Creating a new push certificate for app 'com.nikola.mygreatapp'.
[06:06:06]: p12 certificate: /Users/nikola/DEV/TheOnlyAppThatMatters/fastlane/voippush_com.nikola.mygreatapp.p12
[06:06:06]: PEM: /Users/nikola/DEV/TheOnlyAppThatMatters/fastlane/voippush_com.nikola.mygreatapp.pem
[06:06:06]: fastlane.tools finished successfully ?

And that’s it! Hope this proves to be helpful for you! ?

Written by Nikola Brežnjak