Enabling Apple Push Notifications for ad hoc distr

2019-01-22 15:24发布

问题:

I have successfully implemented APN for development Environment. But i am facing problems while implementing the same for ad-hoc distribution environment. Can anybody please suggest me do i need to create different App Id , Certificate and Provisioning Profile for that? And is there any change in Sandbox? A tutorial of steps will be very much appriciated.

Thanks Saleel Karkhanis

回答1:

For Adhoc distribution, Please follow the instructions below:

  1. In Provisioning Portal, Create a Distribution certificate.
  2. Get the "Device ID" of the iPhone that you intend to use for testing. Open iTunes -> Connect your device -> Select your device -> In Summary Pane, Click on Serial Number label, it will change to identifier (40 Hex characters) -> Choose Edit, Copy.
  3. In Provisioning portal, Go to Devices -> Add new Device -> Enter the copied Device ID and give it a name.
  4. In Provisioning portal, Create a Distribution Provisioning Profile. (Go to Provisioning -> Distribution). For Distibution type , Check "AdHoc". Select the App Id, If you have a distribution certificate, it will automatically be selected here. Select the newly entered device and Submit. Download this Provisioning Profile.
  5. In Xcode, Window -> Organiser. Click on Devices and select Library -> Provisioning Profiles. If you are the admin, then Clicking on Refresh should fetch the newly created provisioning profile. If not, Drag and Drop the Adhoc Provisioning Profile to this list.
  6. In Xcode, in your project Build Settings -> Code Signing Identity -> Release section, Select "iPhone Distribution". For "Any iOS SDK", Select the newly created Provisioning Profile. It will be available in the list.
  7. In Xcode, Product -> Archive. Once it finishes, Archiving, it will open the Archive window automatically. Select the project and click Distribute, In the Distribute window, Select "Save for Enterprise or AdHoc Deployment" -> Select the "Code Signing Identity" which corresponds to the new Provisioning Profile. Continue the process and this will create an ".ipa" file.
  8. Send this .ipa file and the new provisioning profile for testing adHoc distribution.

How to load the adHoc distribution on the test device:

  1. Open iTunes, Connect your test device.
  2. Drag and Drop the new provisioning profile to iTunes.
  3. Drag and Drop the .ipa file iTunes.
  4. Sync ur device. This would load the app.

For Push Notifications to work on Adhoc distribution:

  1. Use the production certificates.
  2. Use production APN Host: gateway.push.apple.com
  3. Use production APN Feedback Host: feedback.push.apple.com.


回答2:

I had major problems with this as well. I had absolutely no errors in my code. I just never got a push notification on the phone in Ad Hoc.

It turns out that I had some sort of problem with my certificates. I created

I'm not really certain what the problem was, exactly, but I solved it by logging into my developer account as the team agent and recreating everything under that login. I had originally created the certificates as a team admin.

Your development mode may work just fine, since any team member can create development distribution profiles. But only certain team members can create distribution profiles. Have your team agent create everything and try it again.



回答3:

There is a separate persistent connection to the push service for each environment (Development and Production). The operating system establishes a persistent connection to the sandbox environment for development builds; ad hoc and distribution builds connect to the production environment.

If you are using GCM. Go to your AppDelegate.swift. Find method: didRegisterForRemoteNotificationsWithDeviceToken and replace

registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,
                           kGGLInstanceIDAPNSServerTypeSandboxOption:true]

with

registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,
                           kGGLInstanceIDAPNSServerTypeSandboxOption:false


回答4:

In addition to Sushma Satish's answer , When you change certificates from developement to distributon , the device token generated for your phone is different. So make sure you're changing the device token on the server.