tags:

views:

37

answers:

3

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 when 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??

A: 

No API for that, Sorry.

Kendall Helmstetter Gelner
i thought i asked about programming logic not api that how to know that same thing is coming four times or more for eg if i stored call id in array thaen how to find that call had come five times or more
pankaj kainthla
If what you want to do is not possible then your question does not really have an answer. If there was an API for instance, you might well be able to get a count from that instead of storing your own array. But since there is no API your question cannot be answered specifically. If you have a general objective C question about storing arbitrary strings in such a way that you can keep a count of them, you should ask it that way. Also, in the future try not to be quite so short with people that are trying to save you time.
Kendall Helmstetter Gelner
ios 4 had methods which let u get call id and call state(incoming ,connected,disconnected)
pankaj kainthla
+1  A: 

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.

hotpaw2
forget about iphone it can be any language for eg if i m soring random numbers in array then how to know the same number came 4 times or more
pankaj kainthla
+1  A: 

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.

Danae
it can be any language for eg if i m soring random numbers in array then how to know the same number came 4 times
pankaj kainthla
In the code I wrote it would know the number has already called four times, because it stores the the callerId in separate keys of the array. Eg. if someone with callerID 123456 called three times in a row, the array would look like: receivedCalls[0] = 123456; receivedCalls[1] = 123456; receivedCalls[2] = 123456; In the foreach loop it looks at all of these, and when it finds a callerId that is identical to the one that is currently calling, it adds 1 to the variable count. If count becomes greater than or equal to 4, then the sound plays. (count++ means add 1 to count)
Danae
ok ok igot it thanks
pankaj kainthla