Use terminal to test push notification with single line command
Install Houston in your Mac, run below command in terminal.
gem install houston
If you are facing error like this,
Fetching houston-2.4.0.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
First run below commands in terminal to install Ruby
brew install ruby
export GEM_HOME="$HOME/.gem"
gem install rails
after successful installation run again
gem install houston
Go to the pem files folder and open terminal from that folder.
Run below command like
apn push "Device Token" -c PEM_FILE_NAME -m "MESSAGE"
Like:
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_dev.pem -m "Testing"
after successful run of above command it will ask for PEM pass phrase which is password of your pem file.
If your app is lived then use production pem file name
like this,
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_pro.pem -m "Testing"
Done.
For UI Testing you can use Local notification,
You have to set categoryIdentifier for local notification also make sure that same categoryIdentifier set into UNNotificationExtensionCategory in your AppExtension Info.plist file
For more in detail kindly refer below link
https://levelup.gitconnected.com/custom-push-notification-in-ios-swift-5-210552643e86#:~:text=Go%20to%20xcode%20select%20File,have%20its%20unique%20category%20Identifier.
Below is the sample code to fire local notification with Category Identifier
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.categoryIdentifier = "LOCAL_NOTIFICATION"
if let info = userInfo {
let dic = ["body" : "Custom Data"]
content.userInfo = dic as [AnyHashable : Any]
}
content.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: sound))
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: "LOCAL_NOTIFICATION", content: content, trigger: trigger)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if let error = error {
print("Error \(error.localizedDescription)")
}
}