测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | BSD |
发布最后发布 | 2014年12月 |
由 Arnaud Coomans 维护。
SimulatorRemoteNotifications 是一个用于向 iOS 模拟器发送模拟远程通知的库。
该库通过嵌入一个监听包含 JSON 格式负载的 UDP 数据包的迷你服务器,并提供了向迷你服务器发送通知的服务来扩展 UIApplication。
该项目包括名为 iOS Simulator Notifications 的 MacOSX 应用程序,以帮助您发送模拟通知。
请注意,SimulatorRemoteNotifications 不通过 Apple 的推送服务发送通知。
OTHER_LINKER_FLAGS="-ObjC"
OTHER_LINKER_FLAGS="-ObjC"
首先将以下代码 #import "UIApplication+SimulatorRemoteNotifications.h"
添加到您的应用程序代理中。
然后实现 application:didReceiveRemoteNotification: 或 application:didReceiveRemoteNotification:fetchCompletionHandler: (后台通知,iOS7)。
最后调用开始监听模拟远程通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
#if DEBUG
[application listenForRemoteNotifications];
#endif
return YES;
}
当调用 listenForRemoteNotifications 时,application:didRegisterForRemoteNotificationsWithDeviceToken: 会收到以下格式的令牌,而不是随机字符:simulator-remote-notification=IP:PORT
默认端口号是 9930。如果您想更改端口号,请在调用 listenForRemoteNotifications 之前使用 setRemoteNotificationsPort
application.remoteNotificationsPort = 1234;
现在,要发送一个远程通知,向 localhost:9930 发送一个 UDP 数据包。
请注意,如果您在应用后台发送通知,只有在将应用带到前台时才会调用 application:didReceiveRemoteNotification:fetchCompletionHandler:。
该项目附带一个名为 iOS Simulator Notifications 的 OSX 应用程序,用于帮助您向 iOS 模拟器发送通知。
构建并运行目标,你将获得一个友好的界面来向模拟器中的应用程序发送通知(请参阅截图)。
首先将 #import "ACSimulatorRemoteNotificationsService.h"
添加到你的测试中
使用以下方法发送你的通知
[[ACSimulatorRemoteNotificationsService sharedService] send:@{@"message":@"message"}];
你可以使用以下方法更改主机(默认:127.0.0.1)和端口号(默认:9930)
[[ACSimulatorRemoteNotificationsService sharedService] setRemoteNotificationsPort:1234];
[[ACSimulatorRemoteNotificationsService sharedService] setRemoteNotificationsHost:@"10.0.0.1"];
你也可以通过使用 netcat 从终端发送模拟远程通知
echo -n '{"message":"message"}' | nc -4u -w1 localhost 9930
您可以通过查看 SimulatorRemoteNotifications.xcodeproj 获取示例
如果你已经安装了 appledoc,你可以运行相应的目标来生成文档
(真实)Apple远程通知的内容长度限制为256字节。