func showNotification() ->Void {
var notification =NSUserNotification()
notification.title ="Test from Swift"
notification.informativeText ="The body of this Swift notification"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
}
self.showNotification()
Posted by: Guest
on June-06-2020
1
register for remote notifications swift
// Import the UserNotifications framework and add the UNUserNotificationCenterDelegate in AppDelegate.swiftimport UserNotifications
// Request user permission
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) ->Bool {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
application.registerForRemoteNotifications()
returntrue
}
// Getting device token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0+String(format: "%02X", $1)})
print(deviceTokenString)
}
// In case of error
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("i am not available in simulator \(error)")
}
// In case if you need to know the permissions granted
UNUserNotificationCenter.current().getNotificationSettings(){ (settings) in
switch settings.soundSetting{
case.enabled:
print("enabled sound setting")
case.disabled:
print("setting has been disabled")
case.notSupported:
print("something vital went wrong here")
}
}
Posted by: Guest
on January-31-2020
Code answers related to "custom notification ios swift"
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email