Question

Is it possible test the Apple Push Notification Services without an iPhone application? (Creating an emulator on windows?)

If isn't, how could I test that? Is there a free sample application compiled to do that?

I created the Server provider, but I need test the functionallity.

Was it helpful?

Solution

(This answer may be outdated after 2013)

Sorry to say, but you'll need to find some hardware to test this functionality.

Push notifications are not available in the simulator. They require a provisioning profile from iTunes Connect, and thus are required to be installed on a device. That also means you'll probably have to be accepted into the apple iPhone developer program and pay your $99.

On the bright side, with the iPhone OS 3.0 update, you can test this functionality on any device, including the first gen iPhones.

OTHER TIPS

You can't test real push notifications. However, you can test your app's response to a simulated push notification by creating one programmatically and manually triggering your AppDelegate's - application:application didReceiveRemoteNotification:notification method.

To trigger this from a different class (like a UIViewController):

[[[UIApplication sharedApplication] delegate]
                    application:[UIApplication sharedApplication]
   didReceiveRemoteNotification:testNotification];

The testNotification should have the same format as a real notification, namely an NSDictionary that contains property list objects plus NSNull.

Here's an example of how to provide the testNotification above:

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"];

This should create a reasonable notification NSDictionary to work with.

Nowadays, we can test push notifications with this library.

It's pretty easy to send push via terminal:

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

The simulator does not do Push Notifications.

And to push from a server, you have to have device(s) to push to as well as your app on that device.

The token contains the app identity as well as the device ID.

you have to use

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];

Yes you can check push notification on simulator but you have to use a library in your app Named SimulatorRemoteNotifications. By which by using just 4-5 steps you can test push notification on Simulator.

They Also Provide PODs too

pod 'SimulatorRemoteNotifications', '~> 0.0.3'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top