Emoji view in iOS chat application using Swift - ios

I am working on chat application, Where I need to show Emoji view on button selection. So I can select and send emoji within the text message. This functionality is already inside Messenger application. I know there is button already in keyboard but I want to add button outside keyboard. Please let me know if there is any resource available to get it done quickly.

This way you can array of Emoji.
let emojiRanges = [
0x1F601...0x1F64F, // emoticons
0x1F30D...0x1F567, // Other additional symbols
0x1F680...0x1F6C0, // Transport and map symbols
0x1F681...0x1F6C5 //Additional transport and map symbols
]
var emojis: [String] = []
for range in emojiRanges {
for i in range {
let c = String(describing: UnicodeScalar(i)!)
emojis.append(c)
}
}

Related

iOS test automation for complex view, UIAccessabilityContainer?

I am building UI automation tests for an app with a complex view hierarchy.
In my situation, I would like to use automation to tap on a UITextField subclass. That textfield is contained within a collectionView, which is itself contained within another collection view.
That textview has a known accessibility label+identifier, but I can't find any way to access this view via the normal XCTest api. For example, the following does not locate the element:
let app = XCUIApplication()
let textField = app.textFields["FOO"]
let textField2 = app.secureTextFields["FOO"]
let textField3 = app.otherElements["FOO"]
As another way to get a reference to the textfield, I tried setting up as a UIAccessabilityContainer, but I'm not sure I'm using it correctly.
//inside the textfield
//should return false if using UIAccessibilityContainer?
self.isAccessibilityElement = false
let e = UIAccessibilityElement(accessibilityContainer: self)
e.accessibilityIdentifier = placeholder
e.accessibilityLabel = placeholder
e.accessibilityTraits = .allowsDirectInteraction
//append this element to the window's list of elements
var eles = window?.accessibilityElements ?? []
eles.append(e)
window?.accessibilityElements = eles
Doing this seems to break all of my existing automation code using the "normal" api. What is the correct way to go about this?

Printing random string from an array on textview

I can't seem to get my array printed onto my textview. I have an array and have set my textview (texthold) to the randomIndex of the array.. Anything you guys see I'm doing wrong?
This is my button that when clicked is supposed to get a random string from the devices array and print it into the textview field. I am getting no errors just nothing displays onto the textview when the button is clicked
#IBAction func Generate(_ sender: Any) {
let devices = ["Apple Watch", "iPhone", "iPad", "Mac", "Apple TV"]
// Generate a random index
let randomIndex = Int(arc4random_uniform(UInt32(devices.count)))
// Get a random item
let randomItem = devices[randomIndex]
texthold.text = devices[randomIndex]
}
This code works in my program. Check your layout using "Debug view hierarchy tool", maybe it will help.
And:
texthold.text = randomItem
Name methods with lowercase (Generate -> generate)
Check if your button touch calls this method
Check if your UI items have connected outlets.
There may be problem with changing text from background thread, but if you really have this method connected from storyboard/xib as method for outlet's action - this situation impossible.
And check that your code is being called on .touchUpInside action of your button (second screenshot in storyboard)!

iOS UITests - How to distinguish two different XCUIElement?

While iOS UITesting, how can I distinguish between two different XCUIElement?
For example I have two different UIButton with same label string "Button". How to check they are different? Do XCUIElement provides ID or any distinct property?
Add an accessibilityIdentifier to each button in your app's code and access each button by its identifier in your tests to tell them apart. Accessibility identifiers are not user-facing, even to Accessibility users, so this will not affect your user experience.
// app code
buttonA.accessibilityIdentifier = "buttonA"
buttonB.accessibilityIdentifier = "buttonB"
// test code
let app = XCUIApplication()
let buttonA = app.buttons["buttonA"]
let buttonB = app.buttons["buttonB"]

How to Send Text in an UIInputViewController

so I've got the following code to insert text:
func insert(text: String) {
(textDocumentProxy as UIKeyInput).insertText(text)
}
But how do I actually get it to send to the chat window?
If you are looking to access all the text entered in the UIInputViewController, the following code may help:
var totalText = "" // complete text entered
if let before: String = self.textDocumentProxy.documentContextBeforeInput {
totalText += before
}
if let after: String = self.textDocumentProxy.documentContextAfterInput {
totalText += after
}
Now that you have complete text entered, you can send it to chat window. There are some limitations here which I can share if this is what you're looking for. Please let me know
Edit
To send text to whatsapp, you need to press send button which is outside the custom keyboard extension. If you want to enter text into the UITextView of whatsapp, it is pretty straightforward to do so. But, the custom keyboard extension can't control the send button of whatsapp

iOS 8 Custom Keyboard

I am trying to build a custom keyboard, it's like a emoji keyboard, but the keyboard's data is from a json file. After parse this json file and get the data, how to make the custom keyboard use it and show in the keyboard view, like the emoji keyboard that built in? Right now, I follow App Extension Keyboard: Custom Keyboard guide, and there only small bits of information here. Is there any tutorial or guide about how to create a custom emoji keyboard online? The current codes I am trying are below:
class KeyboardViewController: UIInputViewController {
override func viewDidLoad() {
super.viewDidLoad()
var error: NSError?
let yanFile = NSBundle.mainBundle().pathForResource("yan", ofType: "json")
let yanData = NSData(contentsOfFile: yanFile) as NSData
let yanDict = NSJSONSerialization.JSONObjectWithData(yanData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
println("dict: \(yanDict)") //print nothing in console
// Perform custom UI setup here
self.nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton
self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal)
}
}
The json like below:
{
"list":
[
{
"tag": "laugh",
"yan":
[
"o(*≧▽≦)ツ┏━┓",
"(/≥▽≤/)",
"ヾ(o◕∀◕)ノ"
]
},
{
"tag": "wanna",
"yan":
[
"✪ω✪",
"╰(*°▽°*)╯",
"≖‿≖✧",
">ㅂ<",
"ˋ▽ˊ",
"✪ε✪",
"✪υ✪",
"ヾ (o ° ω ° O ) ノ゙",
"(。◕ˇ∀ˇ◕)",
"(¯﹃¯)"
]
}
]
}
You can build a xib file by clicking new file -> view
1) inside the xib file create a uiview 320x216 and you can drag'n'drop whatever controls you want into it
2) then you can load the nib like this into your keyboard's inputView:
// Perform custom UI setup here
UIView *layout = [[[NSBundle mainBundle] loadNibNamed:#"keyboardXib" owner:self options:nil] objectAtIndex:0];
[self.inputView addSubview:layout];
3) i think it's amazing if you build a JSON to keyboard api
you send a JSON of the keyboard map to your app
and the app knows how to arrange the keys on the inputView accordingly
let us know if you build this project!
EDIT:
4) Most of what you need to do is parse the JSON and display the content you want from the JSON uibuttons, and also decide what text they are inserting into the text field
check out this question: How to parse a JSON file in swift?
Good luck!
First of all you need to create your UI for keyboard in your KeyboardViewController. It's up to you how you customize it, add buttons, views, gestures etc.. (By the way height of view is limited, to standard keyboard height size, so don't try to make it higher it won't draw) Template that is generated it's just sample to show how you can put a single button in it. After you setup your UI make sure you have Next Keyboard Button it's required.
Regarding Emoji, it's not real images, they are just unicode characters that later replaced with images by system. So you can't pass images, the only input that you can provide is NSString [self.textDocumentProxy insertText:#"hello "]; // Inserts the string "hello " at the insertion point
More details can be found here https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html.

Resources