Bosses link
- First run the project to start the simulator, and then run the following command on the terminal:
xcrun simctl push --help
Copy the code
The remote push can be tested if the following information is displayed
Send a simulated push notification
Usage: simctl push <device> [<bundle identifier>] (<json file> | -)bundle identifier
The bundle identifier of the target application
If the payload file contains a 'Simulator Target Bundle' top-level key this parameter may be omitted.
If both are provided this argument will override the value from the payload.
json file
Path to a JSON payload or '-' to read from stdin. The payload must:
- Contain an object at the top level.
- Contain an 'aps' key with valid Apple Push Notification values.
- Be 4096 bytes or less.
Only application remote push notifications are supported. VoIP, Complication, File Provider, and other types are not supported.
Copy the code
- Then add code to the AppDelegate to get push permissions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let options:UNAuthorizationOptions = [.alert,.sound] UNUserNotificationCenter.current().requestAuthorization(options: options) { (success, error) in if let info = error? .localizedDescription { print(info) } } return true }Copy the code
- Create a playload.json file on your desktop
{" aps ": {" alert" : {" title ":" test ", "the subtitle" : "remote push", "body" : "this is a notification from the distance and"}, "sound" : "default", "badge" : 1}}Copy the code
- Run the following command
xcrun simctl push booted com.test.SwiftDemo /Users/roy/Desktop/playload.json
Copy the code
Com.test. SwiftDemo is the bundle ID of the project
/ Users/Roy/Desktop/playload. Json is the location of the json file