Zan*_*oni 65 iphone apple-push-notifications
是否可以在没有iPhone应用程序的情况下测试Apple推送通知服务?(在Windows上创建模拟器?)
如果不是,我该怎么测试呢?是否有编译的免费样本应用程序?
我创建了服务器提供程序,但我需要测试functionallity.
cas*_*ora 73
(这个答案可能会在2013年之后过时)
很抱歉,但您需要找一些硬件来测试此功能.
推送通知在模拟器中不可用.它们需要iTunes Connect的配置文件,因此需要安装在设备上.这也意味着你可能不得不接受苹果iPhone开发者计划并支付99美元.
从好的方面来说,通过iPhone OS 3.0更新,您可以在任何设备上测试此功能,包括第一代iPhone.
Jam*_*ren 55
您无法测试真实推送通知.但是,您可以通过以编程方式创建一个并手动触发AppDelegate的方法来测试应用程序对模拟推送通知的响应- application:application didReceiveRemoteNotification:notification.
要从另一个类(如UIViewController)触发它:
[[[UIApplication sharedApplication] delegate]
application:[UIApplication sharedApplication]
didReceiveRemoteNotification:testNotification];
Run Code Online (Sandbox Code Playgroud)
testNotification应该具有与真实通知相同的格式,即包含属性列表对象和NSNull的NSDictionary.
以下是如何提供testNotification以上内容的示例:
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
[notification setValue:@"Test" forKey:@"alert"];
[notification setValue:@"default" forKey:@"sound"];
NSMutableDictionary *testNotification = [[NSMutableDictionary alloc] init];
[testNotification setValue:notification forKey:@"aps"];
Run Code Online (Sandbox Code Playgroud)
这应该创建一个合理的通知NSDictionary来使用.
kas*_*tus 30
如今,我们可以使用此库测试推送通知.
通过终端发送推送非常容易:
echo -n '{"message":"message"}' | nc -4u -w1 localhost 9930
echo -n '{"aps":{"alert" : "message","badge" : 99,"sound" : "default"}, "myField" : 54758}' | nc -4u -w1 localhost 9930
Run Code Online (Sandbox Code Playgroud)
fre*_*dpi 25
作为Xcode的11.4,现在有可能通过模拟推送通知拖放一个.apns文件到iPhone模拟器。在Xcode的11.4版本说明有以下要说的新功能:
Simulator 支持模拟远程推送通知,包括后台内容获取通知。在模拟器中,将 APNs 文件拖放到目标模拟器上。该文件必须是具有有效 Apple 推送通知服务有效负载的 JSON 文件,包括“aps”键。它还必须包含一个顶级“模拟器目标捆绑包”,其字符串值与目标应用程序的捆绑包标识符相匹配。
simctl还支持发送模拟推送通知。如果文件包含“Simulator Target Bundle”,则不需要包标识符,否则您必须将其作为参数提供 (8164566):
xcrun simctl push <device> com.example.my-app ExamplePush.apns
这是此类.apns文件的示例,针对系统设置应用程序:
{
"Simulator Target Bundle": "com.apple.Preferences",
"aps": {
"alert": "This is a simulated notification!",
"badge": 3,
"sound": "default"
}
}
Run Code Online (Sandbox Code Playgroud)
将其拖放到目标模拟器上将显示通知并设置徽章:
现在,要将其用于调试目的,您只需将更改Simulator Target Bundle为您自己的应用程序标识符并根据您的调试需要调整有效负载!
jce*_*ile 13
在 macOS 13 和 Xcode 14 中,当在配备 Apple Silicon 或 T2 处理器的 Mac 计算机上时,它\xe2\x80\x99 现在可以接收真正的推送通知,并didRegisterForRemoteNotificationsWithDeviceToken返回真实的令牌。
请参阅 Xcode 14 发行说明:
\n\n\n当模拟器在配备 Apple 芯片或 T2 处理器的 Mac 电脑上运行 macOS 13 时,现在支持 iOS 16 中的远程通知。模拟器支持Apple推送通知服务沙箱环境。您的服务器可以通过连接到 APNS 沙箱 (api.sandbox.push.apple.com) 向在该模拟器中运行的应用程序发送远程通知。每个模拟器都会生成该模拟器与其运行的 Mac 硬件\xe2\x80\x99s 组合所特有的注册令牌。
\n
https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
\nApple 支持模拟器的推送通知。iOS 13.4 及更高版本或 Xcode 11.4 及更高版本。
通常创建Xcode项目并实现用户通知和授权权限。
在模拟器 iOS 13.4 及更高版本中运行您的应用程序。
将您的应用程序置于后台。
{
"aps": {
"alert": {
"title": "Test Push",
"body": "Success! Push notification in simulator! ",
"sound": "default"
},
"badge": 10
},
"Simulator Target Bundle": "com.company.app"
}
Run Code Online (Sandbox Code Playgroud)
现在您的推送通知将出现在模拟器上。
您也可以通过终端模拟推送通知
通过打开Window->Devices and Simulators获取您的模拟器标识符并选择您的目标模拟器并右键单击并复制您的标识符来标识符。
现在构建一个终端命令,如
xcrun simctl push <simulator-identifier> <path-to-payload-file>
Run Code Online (Sandbox Code Playgroud)
前任:
xcrun simctl push 27A23727-45A9-4C12-BE29-8C0E6D1E5360 payload.apns
Run Code Online (Sandbox Code Playgroud)
运行此命令并在模拟器中模拟推送通知
| 归档时间: |
|
| 查看次数: |
62724 次 |
| 最近记录: |