TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Dec 2014 |
Maintained by Arnaud Coomans.
SimulatorRemoteNotifications is a library to send mock remote notifications to the iOS simulator.
The library extends UIApplication by embedding a mini server that listen for UDP packets containing JSON-formated payload, and a service to send notifications to the mini server.
This project includes the iOS Simulator Notifications MacOSX app to help you send the mock notifications.
Note that SimulatorRemoteNotifications does not send notification through Apple's Push Service.
OTHER_LINKER_FLAGS="-ObjC"
for your targetOTHER_LINKER_FLAGS="-ObjC"
for your targetFirst add #import "UIApplication+SimulatorRemoteNotifications.h"
to your application delegate.
Then implement either application:didReceiveRemoteNotification: or application:didReceiveRemoteNotification:fetchCompletionHandler: (background notification, iOS7).
Finally call start listening for mock remote notifications:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
#if DEBUG
[application listenForRemoteNotifications];
#endif
return YES;
}
When listenForRemoteNotifications is called, application:didRegisterForRemoteNotificationsWithDeviceToken: receives a token in the following format instead of random characters: simulator-remote-notification=IP:PORT
The default port number is 9930. If you want to change the port, use setRemoteNotificationsPort before calling listenForRemoteNotifications:
application.remoteNotificationsPort = 1234;
Now, to send a remote notification, send an udp packet to localhost:9930.
Note that if you send a notification while the app is in the background, application:didReceiveRemoteNotification:fetchCompletionHandler: will only be called when you bring the app to the foreground.
The project comes with a OSX app called iOS Simulator Notifications to help you send notifications to the iOS Simulator.
Build and run the target and you'll have a nice interface to send notification to your app in the simulator (see screenshots).
First add #import "ACSimulatorRemoteNotificationsService.h"
to your test
Send you notification with
[[ACSimulatorRemoteNotificationsService sharedService] send:@{@"message":@"message"}];
You can change the host (default: 127.0.0.1) and port (default: 9930) with
[[ACSimulatorRemoteNotificationsService sharedService] setRemoteNotificationsPort:1234];
[[ACSimulatorRemoteNotificationsService sharedService] setRemoteNotificationsHost:@"10.0.0.1"];
You can also send mock remote notifications from the terminal by using netcat:
echo -n '{"message":"message"}' | nc -4u -w1 localhost 9930
You can look at SimulatorRemoteNotifications.xcodeproj for examples:
If you have appledoc installed, you can generate the documentation by running the corresponding target.
(Real) Apple remote notifications are limited to 256 bytes content length.