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
Related
I'm just trying to have a form for users to create a ticket in my app. Nothing else is needed besides that.
I have used the methods here https://developer.zendesk.com/embeddables/docs/ios_support_sdk/requests
Here is my code
//Create a configuration object
let config = RequestUiConfiguration()
config.subject = "App Ticket"
config.tags = ["ios", "testing"]
config.ticketFormID = 20
//Present the SDK
let requestScreen = RequestUi.buildRequestUi(with: [config])
self.navigationController?.pushViewController(requestScreen, animated: true)
But the screen that shows in my app doesn't have a send button or back. I also set the color to orange, but I don't see that change either.
Theme.currentTheme.primaryColor = UIColor.orange
That bottom bar with the Zendesk logo just takes me to a zendesk page
I have the proper set up in app delegate as well
Zendesk.initialize(appId: "myAppID",
clientId: "myClientID",
zendeskUrl: "myURL")
Support.initialize(withZendesk: Zendesk.instance)
Ok, I am new to URL querying and this whole aspect of Swift and need help. As is, I have an iMessage app that contains and SKScene. For the users to take turns playing the game, I need to send the game back and forth in messages within 1 session as I learned here : https://medium.com/lost-bananas/building-an-interactive-imessage-application-for-ios-10-in-swift-7da4a18bdeed.
So far I have my scene all working however Ive poured over Apple's ice cream demo where they send the continuously-built ice cream back and forth, and I cant understand how to "query" everything in my SKScene so I can send the scene.
I'm unclear as to how URLQueryItems work as the documentation does not relate to sprite kit scenes.
Apple queries their "ice cream" in its current state like this:
init?(queryItems: [URLQueryItem]) {
var base: Base?
var scoops: Scoops?
var topping: Topping?
for queryItem in queryItems {
guard let value = queryItem.value else { continue }
if let decodedPart = Base(rawValue: value), queryItem.name == Base.queryItemKey {
base = decodedPart
}
if let decodedPart = Scoops(rawValue: value), queryItem.name == Scoops.queryItemKey {
scoops = decodedPart
}
if let decodedPart = Topping(rawValue: value), queryItem.name == Topping.queryItemKey {
topping = decodedPart
}
}
guard let decodedBase = base else { return nil }
self.base = decodedBase
self.scoops = scoops
self.topping = topping
}
}
fileprivate func composeMessage(with iceCream: IceCream, caption: String, session: MSSession? = nil) -> MSMessage {
var components = URLComponents()
components.queryItems = iceCream.queryItems
let layout = MSMessageTemplateLayout()
layout.image = iceCream.renderSticker(opaque: true)
layout.caption = caption
let message = MSMessage(session: session ?? MSSession())
message.url = components.url!
message.layout = layout
return message
}
}
But I cant find out how to "query" an SKScene. How can I "send" an SKScene back and forth? Is this possible?
You do not need to send an SKScene back and forth :) What you need to do is send the information relating to your game set up - such as number of turns, or whose turn it is, or whatever, as information that can be accessed by your app at the other end to build the scene.
Without knowing more about how your scene is set up and how it interacts with the information received for the other player's session, I can't tell you a lot in terms of specifics. But, what you need to do, if you are using URLQueryItems to pass the information, simply retrieve the list of query items in your scene and set up the scene based on the received values.
If you have specific questions about how this could be done, if you either share the full project, or post the relevant bits of code as to where you send out a message from one player and how the other player receives the information and sets up the scene, I (or somebody else) should be able to help.
Also, if you look at composeMessage in the code you posted above, you will see how in that particular code example the scene/game information was being sent to the other user. At the other end of the process, the received message's URL parameter would be decomposed to get the values for the various query items and then the scene would be set up based on those values. Look at how that is done in order to figure out how your scene should be set up.
iOS10 notifications allow us to add images as media-attachments to them.
Unfortunately, I haven't found any good way to control attachment's appearance inside the notification.
For example, I'm adding as attachment this image:
And it shows as:
I'm passing square-images and want to avoid image-crop (as you can see one ear of cat has been cut).
I'm sending notifcation (as a local one) via this snippet:
let content = UNMutableNotificationContent()
content.title = "Test notification"
content.body = "Test notification"
content.categoryIdentifier = "myNotificationCategory"
let attachement = try! UNNotificationAttachment(identifier: "image",
url: Bundle.main.url(forResource: "cat", withExtension: "png")!,
options: nil)
content.attachments = [ attachement ]
let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: nil)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in
if (error != nil){
}
}
So the questions are:
Can I avoid image crop? (If not - how to remove image at all?)
Bonus question: is there a way to show 2 media-attachments in one notification (while it's collapsed)
Thanks!
You should - as #larme comments - be able to use UNNotificationAttachmentOptionsThumbnailClippingRectKey. However, there seems to be a bug there somewhere:
https://openradar.appspot.com/27708976?
https://forums.developer.apple.com/message/154320#154320
I return to this very old thread… The solution I have found (not gorgeous !), is to create another image (in resource) with a square format. Because the rect is in fact a square that clips the original.
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>))
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