Library to send mock remote notifications to the iOS simulator

Last update: May 14, 2022

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.

GitHub

https://github.com/acoomans/SimulatorRemoteNotifications
Comments
  • 1. 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.

    Reviewed by mwhuss at 2013-11-06 18:48
  • 2. 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?

    Reviewed by yunzixun at 2014-03-11 03:49
  • 3. 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.

    Reviewed by DevAlloy at 2013-07-15 08:19
  • 4. 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 ?

    Reviewed by grifas at 2017-08-04 07:52
  • 5. 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.

    Reviewed by 5teveroy at 2014-02-21 02:18
  • 6. 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 ?

    Reviewed by iziz at 2014-02-18 08:15
  • 7. 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.

    Reviewed by crafterm at 2021-07-06 07:40
  • 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)

    Reviewed by Dev-iL at 2015-10-04 18:32
  • 9. 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.

    Reviewed by adamtootle at 2015-07-21 21:21
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

Nov 6, 2021
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!

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.

Mar 3, 2022
Facebook Analytics In-App Notifications Framework
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

Mar 6, 2022
Pushkin is a free open source tool for sending push notifications
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

Mar 13, 2022
Easily create Local Notifications in swift - Wrapper of UserNotifications Framework
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

May 3, 2022
See all your scheduled local notifications in one place
See all your scheduled local notifications in one place

ScheduledNotificationsViewController Nice Photon is available for hire! Talk to

Apr 23, 2022
Custom in-app notifications.
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

Jan 9, 2022
A fully customizable library to easily display Animated Toast Messages in iOS using Swift!
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

Mar 28, 2022
FNotify - Notification Library For iOS

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

Jan 9, 2022
SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.
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.

May 2, 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

Mar 3, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)
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

May 17, 2022
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS
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

Apr 2, 2022
Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.
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

May 18, 2022
SNPnotificationBar - Notification Bar for ios
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

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

Mock UIImagePickerController to simulate the camera in iOS simulator.

Jun 21, 2021
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
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

May 23, 2022
Jan 7, 2022
MockSwift is a Mock library written in Swift.

Welcome to MockSwift MockSwift allows you to write mocks and make better tests. Because MockSwift is an open source library 100% written in Swift, it

Mar 28, 2022
A Popover that mock iOS SkinTone Selection Popover.

IMessage SkinTone Popover This is a popover mock the iOS iMessage Skin Tone Selection Menu (Popover) Features Long press to invoeke the popover, and t

Dec 9, 2021