如何测试苹果推送通知服务没有iPhone?
-
22-08-2019 - |
题
是否有可能测试苹果推送通知服务没有一个iPhone应用程序? (创建的窗口上的仿真器?)
如果不是,我怎么能测试?有没有编译做一个免费的示例应用程序?
我创建的服务器供应商,但我需要测试后的功能。
解决方案
(适用此答案可能2013之后是过时)强>
遗憾地说,但你需要找到一些硬件来测试此功能。
推送通知不能在模拟器可用。他们需要从iTunes Connect的一个供应配置文件,因此被要求要在设备上安装。这也意味着你可能不得不被接受为苹果iPhone开发者计划,并支付$ 99
在光明的一面,与iPhone OS 3.0更新,可以在任何装置上测试此功能,包括第一代的iPhone。
其他提示
您无法测试真正的推送通知。的然而下,可以测试应用程序的响应于模拟的推送通知通过创建一个编程和手动触发AppDelegate中的- application:application didReceiveRemoteNotification:notification
方法。
要从不同的类(像一个UIViewController)触发此:
[[[UIApplication sharedApplication] delegate]
application:[UIApplication sharedApplication]
didReceiveRemoteNotification:testNotification];
在testNotification应具有相同的格式作为一个真正的通知,即一个NSDictionary包含属性列表对象加NSNull。
下面是如何提供上述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"];
此应该创建一个合理通知的NSDictionary一起工作。
现在,我们可以测试与推这个库。
这是很容易通过终端发送推送:
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
在模拟器不会执行推送通知。
和从服务器推,你必须有设备(一个或多个)推向以及该设备上您的应用程序。
在令牌包含应用的身份信息以及设备ID。
你必须使用
NSString *notificationString = @"{\"aps\":{\"alert\":\"Test alert\",\"sound\":\"default\"}}";
NSData *notificationData = [notificationString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *testNotification = [NSJSONSerialization JSONObjectWithData:notificationData options:0 error:&error];
[[[UIApplication sharedApplication] delegate] application:[UIApplication sharedApplication] didReceiveRemoteNotification:testNotification fetchCompletionHandler:nil];
是的,你可以检查模拟器推送通知,但你必须在你的应用程序命名 SimulatorRemoteNotifications 。通过只用4-5步骤可以在模拟器测试推送通知。
它们也提供POD中太
pod 'SimulatorRemoteNotifications', '~> 0.0.3'