unable to get simple program logic
i m making an iphone app in which when same person calls you and u dont pick the phone then the a sound will be played when same user calls u more than 4 times ,now wh开发者_StackOverflow社区en a call is incoming i am storing its callid in a string or whatever but my problem is i cant find logic to check that the same user has called four times or more??
Use an NSDictionary (a form of hash database). If the current callers name isn't there as the key, add it, and set the value to be count of 1. If the callers name exists as a key in the dictionary, increment the count value by 1. After that, read the count value and do whatever you want depending on the comparison against 4.
But getting the callers name may require some sort of non-stock OS on an iPhone.
Hm.
Loop through an array of received calls.
Instead of storing the callerId in a string, store it in an array called receievedCalls.
During each incoming call, loop through the array (foreach loop?), looking for the callerId of the current caller.
foreach (receivedCalls as $key => $value) {
if ($value == $callerId) {
count++;
}
if (count >= 4) {
(play sound)
}
}
Probably flawed logic but meh. Again, I haven't worked with iPhone apps before so I don't know what kind of language it uses.
No API for that, Sorry.
精彩评论