user3606833 user3606833 - 4 months ago 46
Swift Question

Hide iOS 10 notification on lock screen

I have a situation where I want to get iOS 10 notification data (from dictionary),but I don't want to display any notification on the lock screen.

Any solution? Is this possible ?

if #available(iOS 10.0, *)
let content = UNMutableNotificationContent()
content.body = "Test"

var userInfo = [String:String]()
userInfo["identifier"] = Identifier as String
userInfo["Time"] = DateString as String
content.userInfo = userInfo

I want to get data from dictionary but it shows alert notification on lock screen.

let trigger = UNCalendarNotificationTrigger.init(dateMatchingComponents: components, repeats: false)
let request = UNNotificationRequest.init(identifier: "hello", content: content, trigger: trigger)


You can achieve this thing by sending Silent Push Notification to your device.

To get silent push notification,

You've to set content-available flag to 1 in your push notification payload.

Silent push notifications won't be shown on your lock screen.