Google push notification not working in production

2019-06-14 17:25发布

问题:

I am getting this error on IOS google push notification

The operation couldn’t be completed. (com.google.gcm error 501.)

I get the registration id in development environment and production environment.

The message of development enviornment:

{"multicast_id":8145067860904395870,"success":1,"failure":0,"canonical_ids":0,"results":
[{"message_id":"0:1452842547360715%bc92eed1bc92eed1"}]}

and I successfully receive the message.

But in production environment I get this message.

{"multicast_id":8861850059359760561,"success":0,"failure":1,"canonical_ids":0,"results":
[{"error":"NotRegistered"}]}

and no notification is received.

I have tried every thing from revoking certificate and creating new certificate and new provisioning profile to cleaning build folder but notification is still not working in production.

回答1:

The solution for me is that i have to go to AppDelegate.swift file and search for kGGLInstanceIDAPNSServerTypeSandboxOption in development it should be true and for production it should be false. Just changed it to false for production and notification was working for me.



回答2:

You can do it like this for production environment.:

GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
    registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,
                           kGGLInstanceIDAPNSServerTypeSandboxOption:false]
    GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
                                                             scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)