使用Xcode 7和iOS 9的Google Cloud Messaging [英] Google Cloud Messaging with Xcode 7 and iOS 9

查看:124
本文介绍了使用Xcode 7和iOS 9的Google Cloud Messaging的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地将GCM用于Android设备,但现在我试图在iOS应用上实现。



我认为我遵循了所有必要的步骤能够使用GCM服务。我已遵循 https://developers.google.com/cloud-messaging/ios/client ?配置=真正的将服务添加到现有的应用程序。



我认为一切都配置正确,但我无法收到任何通知。我有APN证书和GoogleService-info.plist文件,在控制台上输出:


2016-01-05 13 :47:53.864:GCM |无效的密钥在签入plist:GMSInstanceIDDeviceDataVersion
连接到GCM
2016-01-05 13:47:57.501:GGLInstanceID |将来无效的上次签入时间戳。
2016年1月5日13:47:57.501 TerneraGallega [1014:444977]与AUTHID签到成功:4958686017822257121,消化:KSJNg + Aj82uavBXrFeOAfA ==,lastCheckinTimestamp:1451998077000
注册令牌:NC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7 -RkQlg1durYSEQRD
已经订阅了/ topics / global


只要我收到这个消息,




{
按钮: NC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7-RkQlg1durYSEQRD,
的content_available:真,
通知:{
body:很棒的比赛!,
title:葡萄牙对丹麦
}
} p>

第一次尝试返回成功消息,但未显示日志和通知(使用前台应用程序)

几分钟后,在POST请求的另一次尝试中,现在它返回一个失败,带有


{
multicast_id:7256343774952522277,
成功:0,
失败:1,
canonical_ids:0,
results:[
{
error:NotRegistered
}
]
}


现在,我从Google页面下载了GCM示例,配置了APN并获取了GoogleService-info.plist,当启动GCM示例时Swift文件一旦在设备上打开,它就会说:


注册成功!检查xcode调试控制台是否可以使用注册令牌...


在此之后,如果您将POST请求设置为




{
按钮: mVEtHyTXEOg:APA91bGvK_Uf2ZKgpguWUOto3CXQzIT1z22uJ446mYkNqMwL9VLDYdGtdm_4vS8rcl3T9OeqEC1UWbdKAOyuoweW1GiU0mv0cDSPW03y4XGx19JcR6rxsiWRNUjtADX6iNAW8wM8UBJl,
的content_available:真的,
通知:{
body:很棒的比赛!,
title:葡萄牙对丹麦
}
} $ / b $ b

它再次返回一个


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


在应用程序上实施GCM可以指出我缺少什么?



-------编辑-------



最后,我通过使用分发证书而不是一个开发证书...似乎我已经配置好了所有的东西,但是我缺少一些开发证书。



PS:在IDN I的APN Profile页面已启用两个推送通知证书(这就是为什么我认为一切都配置良好)



但我会离开这个问题打开,因为我无法使用此开发中情况

解决方案

我能够在编辑时有效地完成与修复相同的事情,而不会弄乱证书​​。显然,如果你已经拥有了一切设置,并且正在使用开发和生产环境,那么这将不起作用,但是如果你刚刚处于开发阶段,就很容易进行更改。



在应用程序中的Gcm示例项目(for objective-c)中:didRegisterForRemoteNotificationsWithDeviceToken我简单地更改了代码:

  _registrationOptions = @ {kGGLInstanceIDRegisterAPNSOption:deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};

  _registrationOptions = @ {kGGLInstanceIDRegisterAPNSOption:deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};

我明白这不完全是一个真正的解决方法,但它至少可以在不更改的情况下工作证书(只要生产证书已设置)。

I've managed to use GCM with Android devices, but now I'm trying to implement on an iOS app.

I think I followed all the necessary steps to be able to use the GCM service. I've followed the https://developers.google.com/cloud-messaging/ios/client?configured=true to add the service to an existing app.

I think that everything is configured correct but I'm not able to receive any notification. I have the APN certificates and the GoogleService-info.plist file, on the console this is the output:

2016-01-05 13:47:53.864: GCM | Invalid key in checkin plist: GMSInstanceIDDeviceDataVersion Connected to GCM 2016-01-05 13:47:57.501: GGLInstanceID | Invalid last checkin timestamp in future. 2016-01-05 13:47:57.501 TerneraGallega[1014:444977] Checkin successful with authId: 4958686017822257121, digest: KSJNg+Aj82uavBXrFeOAfA==, lastCheckinTimestamp: 1451998077000 Registration Token: nC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7-RkQlg1durYSEQRD Already subscribed to /topics/global

As soon as I receive this if I made a POST request with:

{ "to" : "nC-dd9fCvFs:APA91bHMfbvLczxSPLQsLeEJASU_RfV4wvVuPs2u4VJDtpC8oB2cm1AKr6cH_LFeLsQzb94Kk9iwez8fsOvgzNns_9DU3i8Ema1oCKIwcNFzenNpAhViyGHah4E7-RkQlg1durYSEQRD", "content_available" : true, "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark" } }

The first attempt it returns a success message but no log nor notification is shown in the device (with the application on the foreground)

After a few minutes, on another try of the POST request now it returns a failure with

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

Now, I downloaded the GCM Example from the Google page, configured the APN and also got the GoogleService-info.plist, when launching the GCM Example Swift file as soon as it opens on the device it says:

Registration Succesful! Check the xcode debug console fot the registration token that you can use...

After this, if you set a POST Request with

{ "to" : "mVEtHyTXEOg:APA91bGvK_Uf2ZKgpguWUOto3CXQzIT1z22uJ446mYkNqMwL9VLDYdGtdm_4vS8rcl3T9OeqEC1UWbdKAOyuoweW1GiU0mv0cDSPW03y4XGx19JcR6rxsiWRNUjtADX6iNAW8wM8UBJl", "content_available" : true, "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark" } }

it again returns a

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

Can someone who has implemented GCM on an app could point me what I'm missing?

-------EDIT-------

Finally I've made it work by using a distribution certificate instead of a development certificate... it seems that I have all good configured but I'm missing something with the development certificate.

PS: In the APN Profile page under ID I have enabled both Push notification certificates (that's why I thought that everything was good configured)

But I'll leave this question open because I'm unable to use this under development circumstances

解决方案

I was able to do effectively the same thing as the fix in your edit without messing with the certificates. Obviously this won't work if you already have everything setup, and are using both the development and production environments, but if you're just in the development stage it's easy enough to change.

In the Gcm example project (for objective-c) in application: didRegisterForRemoteNotificationsWithDeviceToken I simply changed the code from:

    _registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};

To

    _registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};

I understand this isn't exactly a real fix, but it at least made it work without changing any certificates (as long as the production certificate is setup.

这篇关于使用Xcode 7和iOS 9的Google Cloud Messaging的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆