Call Directory Extension CallKit does't recognize numbers with more than 9 digits - ios

I'm working with CallKit and developing an app with a Call Directory Extension. I've followed this tutorial and I'm currently test the capability of identify numbers that the user does't have in his contacts and show an ID from my app, but although is working perfectly with numbers of 1 to 9 digits, for example 123456, when I set numbers with 10 or more digits, iOs doesn't recognize the number. After a day and a half of google it, I've have found no information about that. If anyone can help me I'll appreciate it. Thanks in advance.
The method for set the phone numbers for recognize:
private func addAllIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
// Retrieve phone numbers to identify and their identification labels from data store. For optimal performance and memory usage when there are many phone numbers,
// consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded.
//
// Numbers must be provided in numerically ascending order.
let allPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ 123456789, 1_888_555_5555 ]
let labels = [ "ID test", "Local business" ]
for (phoneNumber, label) in zip(allPhoneNumbers, labels) {
context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
}
}
With this code, when I simulate a call with the number 123456789, iOS shows the tag "ID test" and that's correct, but if I add any digit, for example 0 at the end: 1234567890, iOS does't show anything when I simulate a call. I don't know if I'm missing something.

Well, after a bunch of tests I could made it work. The point was that the phone must contain the full country code and the area code. So for example 00_52_55_4567_8932 877 or +52_55_4567_8932 both will work. But 55_4567_8932 and 4567_8932 will not work. I hope this can help someone else in the future. Thank you all!

Related

Issue returning desired data with Lua

Wondering if I could get some help with this:
function setupRound()
local gameModes = {'mode 1','mode 2','mode 3'} -- Game modes
local maps = {'map1','map2','map3'}
--local newMap = maps[math.random(1,#maps)]
local mapData = {maps[math.random(#maps)],gameModes[math.random(#gameModes)]}
local mapData = mapData
return mapData
end
a = setupRound()
print(a[1],a[2]) --Fix from Egor
What the problem is:
`
When trying to get the info from setupRound() I get table: 0x18b7b20
How I am trying to get mapData:
a = setupRound()
print(a)
Edit:
Output Issues
With the current script I will always the the following output: map3 mode 2.
What is the cause of this?
Efficiency; is this the best way to do it?
While this really isn't a question, I just wanted to know if this method that I am using is truly the most efficient way of doing this.
First of all
this line does nothing useful and can be removed (it does something, just not something you'd want)
local mapData = mapData
Output Issues
The problem is math.random. Write a script that's just print(math.random(1,100)) and run it 100 times. It will print the same number each time. This is because Lua, by default, does not set its random seed on startup. The easiest way is to call math.randomseed(os.time()) at the beginning of your program.
Efficiency; is this the best way to do it?
Depends. For what you seem to want, yes, it's definitely efficient enough. If anything, I'd change it to the following to avoid magic numbers which will make it harder to understand the code in the future.
--- etc.
local mapData = {
map = maps[math.random(#maps)],
mode = gameModes[math.random(#gameModes)]
}
-- etc.
print(a.map, a.mode)
And remember:
Premature optimization is the root of all evil.
— Donald Knuth
You did very good by creating a separate function for generating your modes and maps. This separates code and is modular and neat.
Now, you have your game modes in a table modes = {} (=which is basically a list of strings).
And you have your maps in another table maps = {}.
Each of the table items has a key, that, when omitted, becomes a number counted upwards. In your case, there are 3 items in modes and 3 items in maps, so keys would be 1, 2, 3. The key is used to grab a certain item in that table (=list). E.g. maps[2] would grab the second item in the maps table, whose value is map 2. Same applies to the modes table. Hence your output you asked about.
To get a random game mode, you just call math.random(#mode). math.random can accept up to two parameters. With these you define your range, to pick the random number from. You can also pass a single parameter, then Lua assumes to you want to start at 1. So math.random(3) becomes actually math.random(1, 3). #mode in this case stand for "count all game modes in that table and give me that count" which is 3.
To return your chosen map and game mode from that function we could use another table, just to hold both values. This time however the table would have different keys to access the values inside it; namely "map" and "mode".
Complete example would be:
local function setupRound()
local modes = {"mode 1", "mode 2", "mode 3"} -- different game modes
local maps = {"map 1", "map 2", "map 3"} -- different maps
return {map = maps[math.random(#maps)], mode = modes[math.random(#modes)]}
end
for i = 1, 10 do
local freshRound = setupRound()
print(freshRound.map, freshRound.mode)
end

How do I tell my app to read exactly what the string contains?

Stumbled on an issue I can't seem to figure out. I have an app that spits out a certain amount of points depending what the string is so if someone says "not 1" then my app will show -4 points for number 1. If someone says "its 2" then the app will award 12 points for 2.
So now my issue is, If someone says "its 2" and awards 12 points which is great, exactly what I want. But when someone says "its not 2" it still awards 12 points to 2 because it contains the word "its", when I want it to show -4 points.
|| vote.lowercased().contains("its")
|| vote.lowercased().contains("its not")
I want it to be able to see if it contains exactly "its not" then it will know to -4 points.
If you want to distinguish its and its not you have to check for the longer string first
if vote.lowercased().contains("its not") {
// -4 points
} else if vote.lowercased().contains("its") {
// 12 points
}

Generating a random number under super.ViewDidLoad

I am making a 'Guess The Number' Game for a project at school, I want my application to generate one random number between 1-10 and then let me use it under my button which allows the user to guess the number by entering their guess into a text field. I have managed to do some of this, my random number generator is currently under my 'Guess' Button which means every time they press the button the number will change. My solution is to generate a number under super.viewDidLoad and then use it under the button to do the rest, but I'm not sure how to do this.
If I've understood you correctly you want the number to be generated only once instead of on every press.
So you might want something like this:
var randomNumber: Int
override func viewDidLoad() {
super.viewDidLoad()
//Initialization
generateRandomNumber()
}
func generateRandomNumber() {
randomNumber = Int(arc4random_uniform(9)) + 1
}
randomNumber is an instance-variable, so you can access it in all of your methods, for example to check if the user guessed correctly.
Use the standard library functions for high quality random numbers: arc4random() or arc4random_uniform(), just as in Objective-C.
They are in the Darwin module, so you will need to import Darwin if you haven't imported AppKit, UIKit, or Foundation.

Working with large dictionaries in Swift

I have a large set of data (approximately forty thousand value pairs), that ideally fits into [Int:Double] dictionary, but Xcode tries to reindex the file all the time and it just doesn't work.. the environment hangs, crashes..
What is the current best practice to deal with such issue in Swift for iOS?
class R {
let array:[Int:Double] = [
99502:0.1730,
// 40 thousand lines are here
99503:0.1730
]
}

Variable names at the end

I am going through the new Apple Swift language.
Why should I use variable name at the end ?
var largest = 0
for (kind, numbers) in interestingNumbers {
for number in numbers {
if number > largest {
largest = number
}
}
}
largest
Are you asking why the last line is largest? Paste the code into a playground and you'll see it show the value of largest on the right at that line. It's just so you can see what the value is after the loop.
If you are following the learning book (I see the code sample taken from the iBook) without Xcode; you are missing Xcode's Playground.
Download Xcode 6 Beta, open playground, paste above code, see the magic ;-)
Playground is a tool to see what happens in your code as you type.
Also to understand the philosophy behind Xcode Playground take a look at this video:
Bret Victor - Inventing on Principle http://vimeo.com/36579366

Resources