Library to send mock remote notifications to the iOS simulator

Overview

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.

Comments
  • Added support for iOS 7

    Added support for iOS 7

    As outlined in:

    https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:

    If your delegate also implements the application:didReceiveRemoteNotification:fetchCompletionHandler: method, the app object calls that method instead of this one.

    opened by mwhuss 5
  • Does this support IOS7?

    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?

    opened by yunzixun 2
  • Error with Code = 3840

    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.

    opened by DevAlloy 2
  • didReceiveRemoteNotification: fetchCompletionHandler - background

    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 ?

    opened by grifas 1
  • Enabled didReceiveRemoteNotification: for iOS 7 apps that use old API

    Enabled didReceiveRemoteNotification: for iOS 7 apps that use old API

    It seems that application:didReceiveRemoteNotification: should be called even if the app is running in iOS 7 because not all apps will have migrated to use the newer method that has a completion block.

    opened by 5teveroy 1
  • Change NULL to '\0'

    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 ?

    opened by iziz 1
  • 4k buffer for modern iOS versions

    4k buffer for modern iOS versions

    This PR updates the notification buffer size to 4k matching current documentation modern http/2 non voip based notification payload sizes.

    We hit the previous size limit during development/testing of our app, and this patch fixed the issue.

    opened by crafterm 0
  • Updated notification payload size for iOS >= 8

    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)

    opened by Dev-iL 3
  • Disabling automaticQuoteSubstitutionEnabled for payloadTextView in the iOS Simulator Notifications Mac app.

    Disabling automaticQuoteSubstitutionEnabled for payloadTextView in the iOS Simulator Notifications Mac app.

    Currently the NSTextView replaces any input quotes with quotes that break the JSON validation.

    So "key":"value" becomes “key”:”value”. This just disables that in applicationDidFinishLaunching.

    opened by adamtootle 0
Owner
Arnaud Coomans
Arnaud Coomans
How to Add Local Push Notification With timeInterval & Test On Simulator

Technicalisto How to Add Local Push Notification With timeInterval & Test On Simulator In Project Target ( Signing & Capapilities ) Add Capapility : 1

Aya Baghdadi 0 Jun 24, 2022
Push notifications allow developers to reach users, even when users aren't actively using an app!

Push notifications allow developers to reach users, even when users aren't actively using an app! With the latest update of iOS Apple provide very useful extensions which are user-friendly. In this tutorial, I am going to share the configuration, set up of Notification with the media attachments like.

MindInventory 16 Mar 3, 2022
Facebook Analytics In-App Notifications Framework

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications, based on the a

Meta Archive 496 Nov 17, 2022
Pushkin is a free open source tool for sending push notifications

Unmaintained This repository is no longer maintained. Pushkin Introduction Pushkin is a free open source tool for sending push notifications. It was d

Nordeus 257 Nov 3, 2022
Easily create Local Notifications in swift - Wrapper of UserNotifications Framework

In IOS 10, apple updated their library for Notifications and separated Local and push notifications to a new framework: User Notifications This librar

Devesh Laungani 208 Dec 14, 2022
See all your scheduled local notifications in one place

ScheduledNotificationsViewController Nice Photon is available for hire! Talk to

Nice Photon 171 Oct 8, 2022
Custom in-app notifications.

CRNotifications CRNotifications are custom in-app notifications with 3 types of layouts. The notifications will animate in and out. They will hide whe

Casper Riboe 112 Sep 2, 2022
Gently notifies you about 'important' GitHub notifications

OctoBlast Gently notifies you about important GitHub notifications Setup Personal access token Head to preferences, and pop in your a new GitHub perso

Jason Watson 6 Nov 14, 2022
A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

CustomToastView-swift A fully customizable library to easily display Animated Toast Messages in iOS using Swift! Preview - All the custom toasts you c

Leticia Rodriguez 13 Aug 20, 2022
FNotify - Notification Library For iOS

FNotify Notification Library For IOS FNotify.mov Requirements: xcode 12+ swift 5

Frameworks 1 Jan 9, 2022
A Swift Library for Dynamic Island Push Notification.

Push Notification With Dynamic Island Handle Push Notification with Dynamic Island ?? Descreption: Since there is not library for Apple Push Notificat

Amir Diafi 5 Nov 12, 2022
SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

SystemNotification is a SwiftUI library that lets you mimic the native iOS system notification in your iOS apps.

Daniel Saidi 153 Dec 22, 2022
Push Notification Registration for iOS

Orbiter Note: This project is no longer being maintained. For most iOS client / server applications, push notifications are negotiated through an inte

Mattt 672 Nov 17, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

noodlewerk 6.2k Dec 22, 2022
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS

FocusPlsNoBadges Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS, in a really gross and hacky way. Getting started Build the X

Ayden Panhuyzen 18 Dec 14, 2022
Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify English | 简体中文 Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications wit

Chanify 156 Jan 4, 2023
SNPnotificationBar - Notification Bar for ios

SNPnotificationBar Screenshot Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements S

Ahmad Almasri 7 Nov 20, 2019
Mock UIImagePickerController for testing camera based UI in simulator

Mock UIImagePickerController to simulate the camera in iOS simulator.

Yonat Sharon 18 Aug 18, 2022
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.

Puffery An iOS App written in SwiftUI to send push notifications fueled by Siri Shortcuts. You can follow other's channels and directly receive update

Valentin Knabel 29 Oct 17, 2022
Joseph Miller 0 Jan 7, 2022