/macos-push-tester

Native mac app for easily sending Apple APNs push messages to iOS apps

Primary LanguageSwiftMIT LicenseMIT

Platform Compatibility Compatibility License Build Status

The macOS Push Tester App

The macOS Push Tester App allows you to send push notifications through APNS (Apple Push Notification Service) and receive them on a device.

It can also get device tokens from any iPhone on the same wifi network.

Notice: This app was created to be used by the SSED SDK team internally. Anyone is free to use it but please be aware that it is unsupported.

How to build/run from source

    1. Run pod install from root folder
    1. Open pusher.xcworkspace*
    1. Build and run

How to build with Fastlane

Install fastlane

    1. Using RubyGems sudo gem install fastlane -NV (or simply bundle install)
    1. Alternatively using Homebrew brew cask install fastlane

Run fastlane

Run fastlane ci

Make your iOS app discoverable by the macOS Push Tester App

    1. Add this class to your iOS app
import Foundation
import MultipeerConnectivity

public final class DeviceAdvertiser: NSObject {
    private var nearbyServiceAdvertiser: MCNearbyServiceAdvertiser?
    private let serviceType: String
    
    public init(serviceType: String) {
        self.serviceType = serviceType
        super.init()
    }

    public func setDeviceToken(_ deviceToken: String) {
        if let advertiser = nearbyServiceAdvertiser {
            advertiser.stopAdvertisingPeer()
        }

        let peerID = MCPeerID(displayName: UIDevice.current.name)
        
        nearbyServiceAdvertiser = MCNearbyServiceAdvertiser(
            peer: peerID,
            discoveryInfo: ["token": deviceToken, "appID": Bundle.main.bundleIdentifier ?? ""],
            serviceType: serviceType
        )
        
        nearbyServiceAdvertiser?.delegate = self
        nearbyServiceAdvertiser?.startAdvertisingPeer()
    }
}

extension DeviceAdvertiser: MCNearbyServiceAdvertiserDelegate {
    public func advertiser(_ advertiser: MCNearbyServiceAdvertiser, 
                            didReceiveInvitationFromPeer peerID: MCPeerID, 
                            withContext context: Data?, 
                            invitationHandler: @escaping (Bool, MCSession?) -> Void) {
        invitationHandler(false, MCSession())
    }
}
    1. Instantiate DeviceAdvertiser
let deviceAdvertiser = DeviceAdvertiser(serviceType: "pusher")
    1. Set the device token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    deviceAdvertiser.setDeviceToken(deviceToken.hexadecimal)
}
    1. Add this Data extension to convert deviceToken to String
import Foundation

extension Data {
    var hexadecimal: String {
        map { String(format: "%02x", $0) }.joined()
    }
}
    1. Add the following to your targets info.plist (required for iOS 14 and above)
<key>NSBonjourServices</key>
<array>
	<string>_pusher._tcp</string>
	<string>_pusher._udp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>To allow Pusher App to discover this device on the network.</string>

UI Preview

The macOS Push Tester App