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>))
Related
I've got a UITest that succeeds in iOS 10 (10.3):
let app = XCUIApplication()
let pageTitle = app.navigationBars["Module.ContainerView"].staticTexts["page title"]
XCTAssert(pageTitle.exists)
This however fails in iOS 11 (11.1). The app.navigationBars["Module.ContainerView"] exists, the staticTexts of that is an empty array.
Any ideas how to test for a title in the navigation bar in iOS 11?
You can find the exact type of title by using the recording feature.
As a solution you can try with the below code. Hope it will work.
let app = XCUIApplication()
let pageTitle =
app.navigationBars["Module.ContainerView"].otherElements["page title"]
XCTAssert(pageTitle.exists)
let app = XCUIApplication()
let navTitleIdentifier = "Community"
let navigationTitleElement = app.navigationBars.matching(identifier: navTitleIdentifier).firstMatch
XCTAssert(navigationTitleElement.exists)
I am developing an iOS application with a button to report an issue using SMS/iMessage. I am using MFMessageComposeViewController to present the message composition interface using the following code (Swift 3):
if(MFMessageComposeViewController.canSendText()){
let controller = MFMessageComposeViewController()
controller.messageComposeDelegate = self
controller.body = "Example Message"
controller.recipients = ["2345678901"]
self.present(controller, animated: true, completion: nil)
}
I have also implemented the MFMessageComposeViewControllerDelegate function to dismiss properly. A standard text message / iMessage sends successfully, but the user does not have the option to attach an image. The buttons for camera, iMessage Apps, etc. are there, but they are disabled and cannot be pressed. How can I enable these buttons (camera, specifically) to allow my users to attach images to messages composed with the app?
The Buttons in Question:
EDIT:
Thanks Abdelahad for the suggestion. I've modified his response to allow multiple recipients and to include a message body. I also updated it to remove the deprecated addingPercentEscapes(using: ) method.
Here is a solution using a url to open the Messages app. NOTE: This takes users out of the app.
let recipients = "2345678901,3456789012" //Phone Numbers
let messageBody = "This is a test"
let sms: String = "sms://open?addresses=\(recipients)&body=\(messageBody)"
let smsEncoded = sms.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
let url = URL(string: smsEncoded!)
UIApplication.shared.openURL(url!)
But still I would like a solution that does not take the user out of the app. Is this possible? Why would the MFMessageComposeViewController show the buttons without enabling them?
Don't use MFMessageComposeViewController use UIApplication.shared.openURL(url!) but this will takes the user out of the app
var phoneToCall: String = "sms: +201016588557"
var phoneToCallEncoded = phoneToCall.addingPercentEscapes(using: String.Encoding.ascii)
var url = URL(string: phoneToCallEncoded)
UIApplication.shared.openURL(url!)
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
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
This question already has answers here:
How do I get a reference to the AppDelegate in Swift?
(18 answers)
Closed 8 years ago.
How can I get instance of current UIApplication from View Controller in Swift?
I am getting Use of unresolved identifier 'sharedApplication' error with this code:
let app = sharedApplication as UIApplication
EDIT Swift 4.x
let app = UIApplication.shared.delegate as! AppDelegate
If you're e.g. not in a ViewController, you must:
import UIKit
Perhaps try:
let app = UIApplication.sharedApplication()
EDIT (Swift 3):
It should be noted that in Swift 3, to accomplish this, you will want to access the shared property instead:
let app = UIApplication.shared
You can do it by
let app = UIApplication.sharedApplication()