MSMessage message.senderParticipantIdentifier.uuidString not converting to name - ios

I'm in the final stages of an iMessage extension and have one last lingering issue that I thought was a problem with the simulator but now I have the app working on test devices it's not resolved itself.
When I create a message caption the following code works to change the partipipantIdentifer into their name:
layout.caption = "$\(conversation.localParticipantIdentifier.uuidString)"
However when viewing the message at the recipient's end this code:
self.titleLabel.text = "$\(self.message!.senderParticipantIdentifier.uuidString) sent:"
doesn't display the senders name it just displays their UUID string. What am I missing to convert the sender UUID to their name? Does anyone know if this is this possible or not?
Thanks

The "$(participantIdentifier)" syntax only works within MSMessageLayout. When setting the UILabel.text you can only get the uuid.

Related

iOS Notification Content Extension - How to pass data to app?

I wrote a custom Notification Content Extension for my Push Notifications like this:
The thing is, whenever the user is on a certain item in the carousel, I want the GO TO APP button to send a String to the app when it's opening, and from there, handle that string to move the user to the correct ViewController.
I already have the handling part inside the app, I just need to know how to pass that String from the Notification Content Extension to the container app.
Thanks! :)
Enable app groups in capabilities and use suite userDefaults to write the key and read it in the app
NSUserDefaults*defaults= [[NSUserDefaults alloc] initWithSuiteName:#"group.com.company.appName"];
// Write in extension
[defaults setObject:#"anyThing" forKey:#"sharedContent"];
// Read in app
[defaults objectForKey:#"sharedContent"];
If your app is configured for Universal Links or you have defined a Custom URL Scheme for your app, you can also open your app's URL (e.g. with data in query parameters) by calling
extensionContext?.open(url)
in your NotificationViewController.
iOS 13, Swift 5.
Based on the answer by Sh_Khan, here is some Swift Syntax. Obviously I have added App Group as a capability to the target of the main app + the target of the extension, naming the group as "group.ch.Blah" for this example.
Setting your app group, saving a string in our case, needed to set the type as Any cause strings not a type that is available in groups.
let localK = getPrivateKey64() as Any
let defaults = UserDefaults.init(suiteName: "group.ch.Blah")
defaults?.set(localK, forKey: "privateK")
Setting your app group, and reading the string back, needed to recast it back to string.
let defaults = UserDefaults.init(suiteName: "group.ch.Blah")
let localK = defaults?.object(forKey: "privateK") as? String
Worked perfectly with a notification service extension.

Localized Strings are always in English in UITests (Snapshot)

I'm pretty new to Fastlane and love the idea of Snapshot, but I got a little problem.
When I'm trying to create a new set of screenshots I'm facing the problem that the UITests don't use the correct localized Strings to fetch the UI elements.
My current state is based on this Stack entries: XCode 7 UITests with localized UI
The localization method:
func localizedString(_ key: String) -> String {
let uiTestBundle = Bundle(for: MyUITests.self)
return NSLocalizedString(key, bundle: uiTestBundle, comment: "")
}
Trying to perform a tap that way:
app.navigationBars[localizedString("key_1")].buttons[localizedString("key_2")].tap()
The error I get is the following:
No matches found for "Rolling stone" NavigationBar
Rolling stone is the Base/English Localization of the key, but there should be a German one. So for any reason the UITest always picks the English Localization.
Does anybody have an idea how to troubleshoot this? I checked the SnapshotHelper and it passes a "de-DE" as the language, so that's not the point.
But I just can't find the Bug :(
Localization
This link here should be sufficient enough to solve your problem. You simple pick the correct language option during the test tab under edit scheme option.

iOS UITest error when try to select picker element

I'm trying to select an element of picker, the picker has Accessibility = picker_station, why can I do ? is something wrong ? or I need to use other code.
let app = XCUIApplication()
app.pickers["picker_station"].pickerWheels.element.adjust(toPickerWheelValue: "Aberdeen")
xcode error is:
Testing Failure - Internal error: unable to find current value '1 of 152' in possible values
Thanks
You are using it correctly, but the adjust(toPickerWheelValue:) method is buggy, as discussed here: https://forums.developer.apple.com/thread/16104
I agree with Oletha this seems to remain an unfixed bug in the framework.
We could fix the issue at least temporarily by calling
pickerWheel.swipeDown()
before calling
pickerWheel.adjust(toPickerWheelValue: "Value")
Otherwise we received the same crash.
After you displayed picker wheel on screen, you can update the value by:
app.pickerWheels.element.adjustToPickerWheelValue("Updated row value")

How can I open a pdf link when click a button on Swift?

I am trying to open a pdf from my Swift application but I cannot make it to work.
I know that there are a lot of questions related with this and in most of them they use this code:
UIApplication.shared.openURL(URL(string: "http://www.url.com" + id)!)
But I am getting the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
so I thought that the error was because the id was nil so I made two prints to see what was retrieved: one for url and one for id. Both of them are correct and if I copy the url on the browser navigation bar it works perfectly (I cannot provide the real url because it is of a client).
I have this function wrapped inside an #IBAction to detect when a button is clicked so I looked if the connection had been broken. It is also correct.
So I cannot understand why this error is happening. I spent some hours but cannot figure out what is causing this error.
Am I missing something? Should I codify the url in some way?
P.S: I am using Xcode8 and Swift3.
UPDATE: If I set www.google.es it is working perfectly. Can it be a problem using variables inside of the url?
Thanks in advance!
Finally, after some hours searching about the problem and following the recommendation of #rmaddy (Thanks!) I have split my function in three parts and I could see that the URL was returning nil value.
It was strange because I could copy the string into my browser navigation bar and it worked well so I thought that it could be something about encoding. One time I have encoded it I noticed that the id of the pdf was retrieved with a \r at the final of the id. Like this:
id004.pdf\r
The solution that I have done is the following:
var string = "http://www.url.com" + id
var index1 = string.index(string.endIndex, offsetBy: -1)
var substring1 = string.substring(to: index1)
let encodedString = substring1.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
UIApplication.shared.openURL(NSURL(string: encodedString!) as! URL)
Encoded string is necessary because if not the link no longer work.

Unable to get UIAutomation iOS UILabel value

I am trying to get the value "HELLO" of the UILabel shown in the iPad simulator.
I have enabled accessibility and have set the label as "Label Access".
But when I call target.logElementTree(), both the name and value are set to "LabelAccess" and as far as the apple docs say, the value field should contain the string that is set (in this case "Hello").
Does anybody know a fix for this?
PS: I am using the latest iOS SDK and Xcode.
Apple Stack Exchange
I think you encountered a UIAutomation bug that exists since forever.
Easiest way to get around this bug is to set the accessibilityValue to your text in code.
Something like this.
NSString *valueString = [NSString stringWithFormat:#"%d", value];
self.label.text = valueString;
self.label.accessibilityValue = valueString;
Helps those people that use Voice Over too ;-)
thanks for the workaround. Doesn't look like this bug has been fixed.
Came across this while writing Appium test for the iOS app. The element found by the driver somehow only contains accessibilityLabel and accessibilityIdentifier but not the actual text that's shown on the screen.
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value=<accessibilityLabel> name=<accessibilityIdentifier> label=<accessibilityLabel> .../>
Has someone found if this issue has been logged with apple?
EDIT: Refer to this answer and the comment underneath. https://stackoverflow.com/a/11411803/4725937
Basically need to use [accessibilityValue]: https://developer.apple.com/documentation/uikit/uiaccessibilityelement/1619583-accessibilityvalue for accessible components for the display text to show up as XCUIElementTypeStaticText.value in the page source.
For eg:
someUILabel.accessibiityLabel = "This is used for voice-over"
someUILabel.accessibilityValue = "This is displayed text"

Resources