Giter Club home page Giter Club 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 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 felipesabino avatar mwhuss avatar

Watchers

 avatar  avatar  avatar

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.