Apple watch notification mirroring - ios

I'm trying to create a notification with an action on the Apple Watch. However the documentation is not really saying what is native and what should be made.
Currently I'm creating a UILocalNotification on the iPhone. However what I'm wondering is that the action button will be mirrored on the Apple Watch.
The code I'm using to create the notification on the iPhone is:
let incrementAction = UIMutableUserNotificationAction()
incrementAction.identifier = "OPEN_ACTION"
incrementAction.title = "Open"
incrementAction.activationMode = UIUserNotificationActivationMode.Background
incrementAction.authenticationRequired = false
incrementAction.destructive = false
let counterCategory = UIMutableUserNotificationCategory()
counterCategory.identifier = "SLAGBOOM_CATEGORY"
counterCategory.setActions([incrementAction],
forContext: UIUserNotificationActionContext.Default)
counterCategory.setActions([incrementAction],
forContext: UIUserNotificationActionContext.Minimal)
let types = UIUserNotificationType.Alert
let settings = UIUserNotificationSettings(forTypes: types, categories: NSSet(object: counterCategory) as? Set<UIUserNotificationCategory>)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
let notification:UILocalNotification = UILocalNotification()
notification.alertBody = message
notification.category = "SLAGBOOM_CATEGORY"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
Am I supposed to do anything to make sure the button will work on the Apple Watch? Or do I need to create a watchkit app only for a notification?

You get default notifications for free but the users only option is to dismiss it.
If you want something custom then you want to create your own watch target and build out the different notification views in the watch targets storyboard
Here's the page on Apple's Watch Programming Kit the explains the different custom notifications you can make

Related

Swift: FCM change sound of notification

I use this code:
let userInfo = notification.request.content.userInfo
let position = userInfo["TITLE"] as? NSString
completionHandler([.alert, .badge, .sound])
This code play default sound, but i want change it to system files mysound.mp3
How i can ?
To play a custom sound when notification received you will have to add sound key to your notification payload and sound file into xcode project.
Add files to the Xcode project root. Make sure Add to targets is selected when adding files so that they are automatically add to the bundle resources. Sound must be less than 30 seconds.
See below exapmple.
{
aps =
{
alert = "notification message";
sound = "example.wav";
};
}

Local Notifications delivering multiple times instead of just one

I am writing an application and want to include local notifications. I want the notification to deliver at a set time and repeat everyday.
I programmed this into my application, and it does notify the user. However, instead of the user just being notified one time everyday at the set time, the application sends the user 13+ notifications at that set time. The number of notifications is only increasing every day.
How do I fix this issue? I just want the notification to notify the user only once everyday.
Here is my code that I have been using. It is set in the Did Finish Launching with Options of the App Delegate.
let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Alert, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
let title: String = "Read Today's Pulse Habit!"
let calendar = NSCalendar.currentCalendar()
let calendarComponents = NSDateComponents()
calendarComponents.hour = 15
calendarComponents.minute = 30
calendarComponents.second = 0
calendar.timeZone = NSTimeZone.defaultTimeZone()
let dateToFire = calendar.dateFromComponents(calendarComponents)
let notification = UILocalNotification()
notification.alertBody = "\(title)"
notification.alertAction = "Read Now"
notification.fireDate = dateToFire
notification.alertTitle = "PULSE"
notification.repeatInterval = NSCalendarUnit.Day
notification.soundName = UILocalNotificationDefaultSoundName
notification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(notification)
I've even tried taking out the line that includes the incrementing icon badge number and that did not make any difference.

How can we add textfield to push notification in objective c? [duplicate]

This question already has answers here:
Adding text field in Remote Notification, iOS 8
(3 answers)
Closed 6 years ago.
I want to add textfield to push notification i.e when app in back ground.I add couple of code to UIUserNotificatioSetting.But I am not getting texfield to push notification,Any one can solve this Problem?
Check this post it will be useful for you
Adding text field in Remote Notificaton, iOS 8
//creating the inline reply notification action
let replyAction = UIMutableUserNotificationAction()
replyAction.title = "Say Something"
replyAction.identifier = "inline-reply"
replyAction.activationMode = .Background
replyAction.authenticationRequired = false
replyAction.behavior = .TextInput
//creating a category
let notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
notificationCategory.identifier = "INVITE_CATEGORY"
notificationCategory .setActions([replyAction], forContext: UIUserNotificationActionContext.Default)
//registerting for the notification.
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes:[ UIUserNotificationType.Sound, UIUserNotificationType.Alert,
UIUserNotificationType.Badge], categories: NSSet(array:[notificationCategory]) as? Set<UIUserNotificationCategory>))

UILocalNotification Minimal Actions – One Blue, One Clear?

I’m screwing around with UILocalNotification and notification actions – all working as I’d expect, except that when I provide the two Minimal actions in my category, when revealing the actions via a swipe in the Notification Center, the right-most action is always blue.
Since the actions in my app are equal, I’d rather them both be the clear grey colour, rather than one blue, one clear. I know that I can make them both red with destructive, but that’s wrong too, and if I explicitly set destructive to false, I still get one blue, one clear.
Here’s an image showing what I’m talking about:
And here’s the code I used to make it:
let note = UILocalNotification()
note.fireDate = NSDate(timeIntervalSinceNow: 5)
note.timeZone = NSTimeZone.defaultTimeZone()
note.alertBody = "Actions: A and B"
note.alertTitle = "Notification!"
let action1 = UIMutableUserNotificationAction()
action1.identifier = “ACTION_A"
action1.title = "A"
action1.activationMode = .Background
let action2 = UIMutableUserNotificationAction()
action2.identifier = “ACTION_B"
action2.title = "B"
action2.activationMode = .Background
let category = UIMutableUserNotificationCategory()
category.identifier = "ANSWERS_CATEGORY"
category.setActions([action1, action2], forContext: .Default)
note.category = “ACTIONS_CATEGORY"
let categories = Set(arrayLiteral: category)
let settingsRequest = UIUserNotificationSettings(forTypes: [.Alert, .Sound, .Badge], categories: categories)
UIApplication.sharedApplication().registerUserNotificationSettings(settingsRequest)
UIApplication.sharedApplication().scheduleLocalNotification(note)
Both the HiG and the notification programming guide do not suggest that is possible to set the buttons' background colour. The most specific reference I found is in the latter, that states:
If the destructive property is NO, the action’s button appears blue; if it’s YES, the button is red.
This is obviously not precise, since two non-destructive actions are not both blue, but it implicitly suggests that the colour for each is automatically set by iOS

UILocalNotification not doing anything

This may seem like a silly question, but this is my first time using UILocalNotification and I can't get it to work for a quick test. It just doesn't do anything.
1. I've created 2 variables in the AppDelegate
let today = NSDate()
let notification: UILocalNotification = UILocalNotification()
2. Then in the applicationDidEnterBackground function, I have the following
notification.fireDate = today.dateByAddingTimeInterval(10)
notification.alertTitle = "My App Test"
notification.alertBody = "Testing Notification \n :)"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
3. Also added this to the applicationDidBecomeActive function
UIApplication.sharedApplication().cancelAllLocalNotifications()
After reading the documentation again, I realized I missed a crucial first step which is to register my App first for user notifications. The Apple doc was written in OBJ-C, but I was able to figure it out in order to convert it to swift. This is what I did:
1. I added this to my AppDelegate didFinishLaunchingWithOptions function and it now works
var types: UIUserNotificationType = UIUserNotificationType()
types.insert(UIUserNotificationType.Alert)
types.insert(UIUserNotificationType.Badge)
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)

Resources