Giter VIP home page Giter VIP logo

simulatorremotenotifications's Introduction

SimulatorRemoteNotifications

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.

Build Status Cocoapods

Install

Install with CocoaPods

Add a pod entry to your Podfile:

pod 'SimulatorRemoteNotifications', '~> 0.0.3'

Install the pod(s) by running:

pod install

Install the static library

  1. Copy the project file in your project
  2. Link your binary with the library, under Target > Build Phases > Link binary with libraries then add the libSimulatorRemoteNotifications.a
  3. set OTHER_LINKER_FLAGS="-ObjC" for your target

Install manually

  1. clone this repository
  2. add the files in the SimulatorRemoteNotifications directory to your project
  3. set OTHER_LINKER_FLAGS="-ObjC" for your target

Usage

Listening for mock remote notifications

First 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.

Sending a mock remote notification with the iOS Simulator Notifications app

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).

Sending a mock remote notification in tests

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

Sending a mock remote notification from the command line

You can also send mock remote notifications from the terminal by using netcat:

echo -n '{"message":"message"}' | nc -4u -w1 localhost 9930

Screenshot

screenshots screenshots

Examples

You can look at SimulatorRemoteNotifications.xcodeproj for examples:

  • in SimulatorRemoteNotificationsExample, the application:didReceiveRemoteNotification: method is called
  • in SimulatorRemoteNotificationsBackgroundExample, the application:didReceiveRemoteNotification:fetchCompletionHandler: method is called

Documentation

If you have appledoc installed, you can generate the documentation by running the corresponding target.

Note

(Real) Apple remote notifications are limited to 256 bytes content length.

simulatorremotenotifications's People

Contributors

5teveroy avatar acoomans avatar crafterm avatar felipesabino avatar mwhuss avatar sobolevn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simulatorremotenotifications's Issues

didReceiveRemoteNotification: fetchCompletionHandler - background

Hi, thanks a lot for this library !

didReceiveRemoteNotification: fetchCompletionHandler is called even if the app is in background when I send a notification from your iOS Simulator Notifications. (on 4s 9.0)

In your documentation, you said:
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.

How to call it only when I bring the app to the foreground ?

cordova plugin?

Is there a Cordova/Phonegap available?

How easy/hard would it be to use it in Cordova apps?

real remote notificate

Is that could be possible awake my App after i end it, just like a Apple push server?

Error with Code = 3840

I send two JSON's:
echo -n '{"aps":{"alert" : "message","badge" : 99,"sound" : "default"},"storeId" : 5475878}' | nc -4u -w1 localhost 9930

echo -n '{"aps":{"alert" : "message","badge" : 99,"sound" : "default"},"storeId" : 54758}' | nc -4u -w1 localhost 9930

Difference only in storeId. First works fine, but second causes error:
SimulatorRemoteNotification: error = Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0xb23dc90 {NSDebugDescription=Garbage at end.}

I tried to resolve this issue but failed:
When we take string from buffer in second case string looks like this:
{"aps":{"alert" : "message","badge" : 99,"sound" : "default"},"storeId" : 54758 }}

Two braces instead of one in first case.

I don't understand how could it be.

Change NULL to '\0'

at 44 line in UIApplication+SimulatorRemoteNotifications.m

How about change

__buffer[size] = NULL;
to
__buffer[size] = '\0';

for turn of [ Incompatible pointer to integer conversion assigning to 'char' from 'void *' ] warning ?

Does this support IOS7?

It seems that it does not work in IOS7. My environment is MAC OSX 10.9/Xcode5.0.2/IOS7.

I excited the commands in terminal but nothing happened,why?

Updated notification payload size for iOS >= 8

Hello!
First of all, I'd like to thank you for this nice tool!

I'm trying to simulate some notifications on an iOS 9 device, which supports a new payload size limit of either 2KB or 4KB. However, SimulatorRemoteNotification seems to truncate the payload after a certain amount of bytes (256?), which results in the following error:

SimulatorRemoteNotification: error = Error Domain=NSCocoaErrorDomain Code=3840
"Unterminated string around character 313." UserInfo={NSDebugDescription=Unterminated
 string around character 313.}

I tried multiplying the values of the following constants by 8, but this seemed to have no effect:

UIApplication+SimulatorRemoteNotifications.m\SimulatorRemoteNotificationsBufferLength
ACSimulatorRemoteNotificationsService.m\SimulatorRemoteNotificationsServiceBufferLength

How can the code be modified to support the increased payload size?

P.S.
I know the payload I'm testing is valid because it gets delivered successfully through APNS when testing with a real device.

(Edit: updated the link to the documentation where the payload size is discussed)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.