What is the best way to handle QR code's Information, As QR code can have any information, For now, I want to handle only
1 URL and redirect to safari browser--> its fine
2 vCard and open contact book with contact values, But I'm seeing that VCARDS keys name are not unique(not sure if I'm Having improper QR codes). And also, QR value is a string to how to detect which value is for which key of address book?
e.g:
"BEGIN:VCARD
FN:Ashwin kanjariya
TEL:+999-999-9999
EMAIL:you#we.com
URL:http://www.youandme.com
N:kanjariya;ashwin
ADR:any address
ROLE:software developer
VERSION:3.0
END:VCARD"
So, I'm Not sure for VCARD all keys are universal or not? What is the best way to handle it?
I appreciate your any kind of suggest that can help me to figure out VCARD parsing.
Is CFDataCreate with ABPersonCreatePeopleInSourceWithVCardRepresentation best way to go with?(I have support for below IOS 9 as well)
like
let vCardnsdata = CFDataCreate(nil, UnsafePointer<UInt8>(vCard.bytes), vCard.length)
let addressbookDefaultSrc = ABAddressBookCopyDefaultSource(addressBook)
let vCardPeople = ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource.takeUnretainedValue(), vCardData).takeRetainedValue() as NSArray
VCARD has several versions with slightly different implementations, keys don't have to be unique, a person can have multiple home or work phone numbers for example, but you should be able to tell what is a phone number and just accept as many as your customer believes is reasonable for their use case.
An extensive list of what you may find in VCARD's is here: https://en.wikipedia.org/wiki/VCard
If you want to make sure that all the data is stored, then you may have to implement lists, or in database terms, store items in different tables so that one to many relationships can be maintained for several items.
When designing a system to store information about people, you may also want to observe some of the Falsehoods Programmers Believe About Names
Related
I am developing an iOS application where I am scanning QRCode and showing result to user. I am scanning QRCode by native libraries provided by Apple. I am able to get string/content from QRCode but I am unable to distinguish and parse string/content. I want to get the type of data (distinguish data type) present in QRCode as it may have different types of data, for example url, text, mcard, email data. I also want to parse content i.e. getting fields of data, for example in case of email data, I want to get email, cc, subject and body field. This question How are different content types within QR-Codes distinguished? did not helped because it does not have accepted answer which can help me.
The .stringValue obtained from a AVMetadataObject scan is just that - a "string value." It is up to you to parse the content.
There are a number of predefined data types, such as
a URL, where the string starts with "https://";
an email link, e.g. "mailto:somebody#example.com?subject=Mail%20from%20Our%20Site"
There is also a "VCard" spec, which may be formatted with "field" values:
BEGIN:VCARD
VERSION:3.0
N:Owen;Sean;;;
FN:Sean Owen
TITLE:Software Engineer
EMAIL;TYPE=INTERNET;TYPE=WORK;TYPE=PREF:srowen#google.com
URL;TYPE=Homepage:https://example.com
END:VCARD
for example.
So, you check the start of the string. If it begins with "https://" your app might launch Safari. If it begins with "mailto:" you could launch the mail app. If it begins with "BEGIN:VCARD" then you'd parse the predefined fields and use the data in your app.
There is a good summary of predefined types here (although, it may be a bit out-of-date): https://github.com/zxing/zxing/wiki/Barcode-Contents
Of course, you can create your own types for your own purposes. For example, you can create a QR-Code that contains:
myTypeA:Robert
or:
myTypeB:Driver
then your app would get the string, take one action if it begins with myTypeA: and a different action if it begins with myTypeB:.
My goal is to write a validation class for Rails that is capable of using an OCR recognised text from a business card and is able to detect string snippets and assign them to the correct attributes. I know this cannot be probably 100% perfect but I want to get as close as possible. Here is my approach so far:
I scan business cards via jquery's navigator.mediaDevices
I send the scanned image to a third party API Service, called OCRSpace (a gem is available here: https://github.com/suyesh/ocr_space)
I then get a unformatted array of recognised text snippets back, for example:
result = [['John Doe'], ['+49 160 123456'], ['Mainstr. 45a'], ['12345 Berlin'], ['CEO'], ['johndoe#business-website.de'], ['www.business-website.de']]
I then iterate through the array and do some checks, for example
Using the people library (https://github.com/mericson/people)
to split the name in firstname and lastname (additionally the title
or middlenames) Using the phonelib library
(https://github.com/daddyz/phonelib) to look up a valid phone number
and format it in an international string
Doing a basic regex check on the email address and store it
What I miss now is:
How can I find out what the name-string would possibly be? Right now I let the user choose it (in my example he defines "John Doe" as the name and then the library does the rest). I'm sure I would run into conflicts when using a regex as strings like "Main Street" would then also be recognized as a name?
How do I regex a combination of ZIP-Code and City name? I'm not a regex expert, do you know any good sources that would help? Couldn't find any so far except some regex-checkers in general.
In general: Do you like my approach or is this way too complicated? And do you know some best-practices that look better?
Don't consider this a full answer, but it was too much to make it a comment.
Your way of working seems Ok but I wouldn't use the OCR Service since there are other ways , Tesseract is the best known.
If you do and all the results are comparible presented it seems not too difficult since every piece of info has it's own characteristics.
You can identify the name part because it won't have numbers in it, the rest does, also you can expect to contain it "Mr." or "Mrs." or the such and not "Str.", "street" and so on. You could also use Google Maps to check for correct adresses, there are Ruby gems but have no experience with them.
Your people gem could also help.
You could guess all of this, present the results in you webpage and let the user confirm or adjust.
You could also RegExpr the post-city combination by looking fo a number and string combination in either order but you could also use a gem like ZipCodes to help.
I'm sorry, don't have the time now to test some Regular Expressions now and I don't publish code without testing.
Hope this was some help, success !
I am learning iOS development. Currently, I started my hobby project which is a weather foracast app. I have found a open REST API, I can send request to get weather data for a city.
The REST API needs me to send request with city id instead of city name & it provides me a 20MB json file which contains city objects with fields city_id, city_name, longitude, latitude. I know I should create a City class to have those fields.
My app is supposed to allow user to input the city name, then, my app make request with the corresponding city id. My question is a about the best practice for this:
Since I need all city ids, should I download the 20MB json file & embed it to my app? Does that mean my app size would be larger than 20MB ? Any better practice to handle this?
If I have to put the 20MB json file in my project, what is the best way to parse the content to a list of City programmatically?
If user input one city name, I feel if I scan all the cities in the json file, it is inefficient, what could be the efficient way to find the city id for the city name (without scanning all the 20MB json)?
==== THE OPEN REST API ===
You do not need to include the JSON in your app. In fact, I highly recommend against doing so. This is according to the documentation:
Description:
You can call by city name or city name and country code. API responds with a list of results that match a searching word.
API call:
api.openweathermap.org/data/2.5/weather?q={city name}
api.openweathermap.org/data/2.5/weather?q={city name},{country code}
Parameters:
q city name and country code divided by comma, use ISO 3166 country codes
Examples of API calls:
api.openweathermap.org/data/2.5/weather?q=London
api.openweathermap.org/data/2.5/weather?q=London,uk
Given this information, you can send a request to the API like the example given: api.openweathermap.org/data/2.5/weather?q=London
The response should include the necessary data to make a subsequent call for the weather forecast.
No need to include 20MB of noise in your app bundle.
I'd create an array of City objects and parse the data into each City object (assuming you need all of them. If not, you'll have to find a way to parse out the ones youd on't want.) As long as you're not writing these to storage it shouldn't increase your app size, it may take a bit to download and parse depending on the methods you use, but that's all part of the fun of optimizing.
There are many JSON parsing iOS libraries, I have the most experience using RestKit to make network requests, and that includes a JSON to Objective-C Object parser built right in, it's super easy. Basically, do some research on JSON parser libraries and pick the one that best suits your needs. You shouldn't need to parse it yourself.
I'd create an NSDictionary with the city_name as your keys, and the city_id as your values. Then to retrieve the city_id simply call [dictionary objectForKey:enteredCity] (replacing with your actual variable names, of course)
I believe that they are asking you to bundle and not burden their server with requests for the 20mb file that doesn't seem to change much.
I would make a script that you run on your dev machine that turns this into a sqlite db (or some other serialized format). Don't bundle the JSON and parse at runtime --- turn it into something queryable at runtime.
I'm making a custom keyboard for lawyers, and trying to load law related words in suggestion/prediction bar on top the keyboard based on what user types. Just like in stock keyboard. I have searched around but did not find any concrete answer.
I want to display suggestions of law related terms that I have in a txt file, all words are sorted alphabetically.
DEMO
Here is what I have tried:
UILexicon
let myLexicon = NSMutableDictionary()
self.requestSupplementaryLexiconWithCompletion { (theLexicon: UILexicon!) -> Void in
let lexiconEntries = theLexicon.entries
// Completion handler
for item in lexiconEntries {
self.myLexicon.setObject(item.documentText, forKey: item.userInput)
}
}
This code just gives 23 nil objects.
UITextChecker This is an iOS class that is designed to spot spelling errors, which makes it perfect for knowing if a given word is real or not. This is seems to be mainly for autocorrection, not for suggestion. Correct me if I'm wrong please.
I cannot somehow make sense out of these two classes.
How do I tell custom keyboard, "Hey if user enters "V" show the top 3 words that start from V, then if user enter a, fill the suggestion bar with words that start with "Va" and so on.
EDIT: Looks like someone ran into same problem. Here is a quote how they solved it, I will update with code once I finish figuring this out myself.
However, this was far from the truth - in fact, Apple do not allow access to their dictionary full stop, only offering a UILexicon class instead as stated in their docs:
Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections as users are entering text.
As it turns out, the UILexicon class only really contains contact names along with any shortcuts (like the default On My Way!) defined on the device. So before writing the logic for a keyboard, you first have to implement your own autocorrect library.
We browsed through a few external projects to see if we could include them in the keyboard - most notably Hunspell, which is used by OpenOffice, and Presage, an intelligent predictive text library.
I spent a long time integrating the C++ libraries with the code, but in the end, in order to keep complexity down, we opted to use a combination of UITextChecker (which provides some basic corrections) and our own custom dictionary, containing a few commonly mispelled words.
Link to the Article
Thanks!
You have to implement your own autocorrection system. UILexicon will only give you shortcuts the user has set up, words that they have added to the iOS Dictionary, and names of contacts. It has no awareness of any words that you yourself provide, whether in a txt file or in any other form.
If you want to use the TOMSSuggestionBar, it appears from the sample code that the onus is on you to convert your txt file into a core data model, and indicate to the suggestion bar how it is to interpret the contents of that model. You may also want to implement the data source protocol to get more fine grained control over the suggestions.
Autocorrection and next word prediction are not solved problems; I suggest you do your own research and find the solution that is best suited to your goals.
Is there a query string parameter (or a special path, or subdomain) that can be used with standard localization codes (e.g. es, nl, de, etc) in conjunction with a url like this https://embed.spotify.com/?uri=spotify:track:4bz7uB4edifWKJXSDxwHcs that will localize the content from Spotify?
EDIT:
I am referring specifically to the options menu as pictured below as the rest of the text is just artist and track title.
No. In this case Spotify doesn't offer any localization codes. But there is no reason for it because it just give you general information title/artist/album etc.
You have to tell us more specific what you want.
If you want to grab data from this url use web-api instead.
https://developer.spotify.com/technologies/web-api/
Use Lookup if you have a special title/artist/album etc. but you need spotify url!
https://developer.spotify.com/technologies/web-api/lookup/
If I would interpret your question in another way:
You can look up 'availability' for certain 'territories'
Just for you to know there is a rate limiting 10 requests per ip/second!
Hope I could helpya! If you need something else or want more help tell us or write me a message ;)