ios 如何测试推送通知在我的应用程序中是否有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7361298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to test Push Notification is working in my application
提问by Naved
In my application I am implementing the Push Notification Service.
I have a Content Provider server, which contains some products in it.
I have generated the SSL Client Certificate and attached it to my development Provisioning profile. This profile is also added to my application.
I have written the code inside the delegate methods (guided by Apple guideline for implementing the Push Notification). All set.
在我的应用程序中,我正在实现推送通知服务。
我有一个 Content Provider 服务器,其中包含一些产品。
我已生成 SSL 客户端证书并将其附加到我的开发配置文件中。此配置文件也添加到我的应用程序中。
我已经在委托方法中编写了代码(由 Apple 指南指导以实现推送通知)。搞定。
Now I want to test my application whether it is handing the push notification as per the requirement. Any idea on how can I test it would help me a lot.
Should I have to add new product to the content provider server to test this?
现在我想测试我的应用程序是否按照要求处理推送通知。关于如何测试它的任何想法都会对我有很大帮助。
我是否必须将新产品添加到内容提供商服务器以进行测试?
If yes, how much will APNS take to send the push notification to my device?
如果是,APNS 将推送通知发送到我的设备需要多少时间?
采纳答案by Nekto
Very cool guide is posted here: Programming Apple Push Notification Services
非常酷的指南发布在这里:Programming Apple Push Notification Services
And an application here: PushMeBaby Mac Os Appwhich you can download and use for sending push-notifications to your devices from a Mac.
还有一个应用程序:PushMeBaby Mac Os App,您可以下载并使用它从 Mac 向您的设备发送推送通知。
APNS will send the push notification to your device as soon as your device will become available. If I'm not mistaken your device pings APNS every minute.
一旦您的设备可用,APNS 就会将推送通知发送到您的设备。如果我没记错的话,您的设备每分钟都会 ping APNS。
回答by LunaCodeGirl
I tried all 3 of the above suggestions with no success. In case someone else is ends up here looking for a solution to this, I found this and it works great:
我尝试了上述所有 3 个建议,但均未成功。如果其他人最终在这里寻找解决方案,我发现了这个并且效果很好:
回答by erkanyildiz
What about curl
:
怎么样curl
:
curl -d '{"aps":{"alert":"This is a test notification"}}' --cert YourCertificate.pem:YourPassword -H "apns-topic: com.example.yourapp" --http2 https://api.development.push.apple.com/3/device/YourDeviceToken
First you need curl
with http2
support.
And you need to convert your push certificate to pem
format using openssl
.
首先,你需要curl
与http2
支持。
您需要将推送证书转换为pem
使用openssl
.
回答by onmyway133
If you want to support both Certificate and Token based authentication with APNS, then you can try Push Notifications
如果您想通过 APNS 支持基于证书和令牌的身份验证,那么您可以尝试推送通知
回答by Helge Staedtler
You should try the the branch of PushMeBaby, it worked for me.
你应该试试PushMeBaby的分支,它对我有用。
回答by Helge Staedtler
Try this online application, through which you could paste in your device token and provide the certificate, and so send push notification to any devices and lets you customize the data as well. http://pushmebaby.herokuapp.com
试试这个在线应用程序,通过它您可以粘贴您的设备令牌并提供证书,然后将推送通知发送到任何设备并让您自定义数据。http://pushmebaby.herokuapp.com
回答by Tarun Seera
You can use APNS tester,its a very good tool for test APNS from Mac Machine link to download thissoftware. 2 things you need to provide to test push notification
你可以使用APNS测试器,它是一个非常好的测试APNS的工具,可以从Mac Machine链接下载这个软件。您需要提供 2 件事来测试推送通知
1.APNS certificate (.cer file) 2.Device token of user's iOS device
1.APNS 证书(.cer 文件) 2.用户 iOS 设备的设备令牌
回答by Victor Choy
PushMeBaby is frozen when I test iOS10 in Xcode8. Try NWPusher, https://github.com/noodlewerk/NWPusher. A friendly and simple tool with GUI.
当我在 Xcode8 中测试 iOS10 时,PushMeBaby 被冻结。试试 NWPusher,https://github.com/noodlewerk/NWPusher。带有 GUI 的友好且简单的工具。
回答by nupadhyaya
If you google you will see a number of websites that do this. I usually use https://www.apnstester.comand https://www.pushty.com
如果你用谷歌搜索,你会看到许多这样做的网站。我通常使用https://www.apnstester.com和https://www.pushty.com
回答by Oleshko
I created a small script to do that
我创建了一个小脚本来做到这一点
import json
import jwt
import time
from hyper import HTTPConnection
ALGORITHM = 'ES256'
# fill these items
APNS_KEY_ID = ''
TEAM_ID = ''
BUNDLE_ID = ''
# put path to p8 file
APNS_AUTH_KEY = ''
# put device token id (of the notification receiver)
REGISTRATION_ID = ''
# let's do the magic :)
f = open(APNS_AUTH_KEY)
secret = f.read()
token = jwt.encode(
{
'iss': TEAM_ID,
'iat': time.time()
},
secret,
algorithm= ALGORITHM,
headers={
'alg': ALGORITHM,
'kid': APNS_KEY_ID,
}
)
path = '/3/device/{0}'.format(REGISTRATION_ID)
equest_headers = {
'apns-expiration': '0',
'apns-priority': '10',
'apns-topic': BUNDLE_ID,
'authorization': 'bearer {0}'.format(token.decode('ascii'))
}
connection = HTTPConnection('api.development.push.apple.com:443')
# put the payload you need
payload_data = {
'aps': {
'content-available': '1',
},
}
payload = json.dumps(payload_data).encode('utf-8')
connection.request(
'POST',
path,
payload,
headers=request_headers
)
resp = connection.get_response()
print(resp.status)
print(resp.read())
https://gist.github.com/IvanivOleg/7ba4072128b2c05a068a6826be68a3d3
https://gist.github.com/IvanivOleg/7ba4072128b2c05a068a6826be68a3d3