How create a custom event handler for ctcall center? iphone - iphone

I am working on an application in which i have a requirement of detect call log info.
Means when ever a call coming and going and then after attending call that will disconnect. So i have detect and send a notification when call disconnect.
For this requirement i have done so much r&d and get some results but when i go through Apple's doc for core telephony framework then there is class "CTCallCenter". This class provide a event handler which will invoke app whenever a call state change.
Now problem is that when i go through document of that class then i get som texts which is shown below
To handle such call events, define a handler block in your application and assign it to this property. You must implement the handler block to support being invoked from any context.
link of apple doc for core telephony framework
In above text write down that u have to create a event handler and assign to property then it will handle call events.
So problem is that how I create a custom event handler and how make a property and assign to my custom event handler?
Thanks in advance...

Take a look at CoreTelephonyDemo. You will find your answer in there.
The event handler is a block. You can also look at Blocks Programming Topics

Related

When we use delegate and Call back in iOS?

I'm very new on iOS application development so please explain me about delegate and call back. When we use use call back and delegate?
Call backs are used to allow an API or service to provide information to your code when certain events occur (e.g. when a task has completed). This is useful in asynchronous programming, e.g. when you want your current thread to get on with something else, or to allow the user to continue using the UI. (i.e. a call back is a function or lambda you have written, which is passed as a parameter to another method)
A delegate is the 'signature' (the 'type definition' of a method, including parameters) that a method (such as a call back) must provide in order for it to be useable as callback or event handler.
Edit Just to be complete, Delegation is also a design pattern, whereby the responsibility of control or action is delegated from one object to another.
Big piece about delegates here on the dev centre:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html
There is a tutorial app using callback/delegate
http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/

What's Android Equivalent of iOS's Post Notification and Delegate function?

I find the Post notification and delegate function are very useful in iOS. Once I finish a task I can notify another piece of code to do something. I am sending out notices for others to do the work.
Post Notification is when you sending notice right away, whereas delegate sometime down the line it will send a notice.
In Android I know there's event Listener, but that's only passive listening. What about me actively sending notices? Does Android have that equivalent?
Handler which can be fired right away or with postDelay() you can fire them later
You could either use a Handler to get notified from a running Thread or the AsyncTask which does run some code and after it's finished it notifies the UI Thread.
You are probably looking for a way to thread your application? Where there are other "worker" threads that do long computations (or do buffered IO stuff). The way you would do this is by creating an AsyncTask. Within an AsyncTask, there is a "doInBackground" method that seems to be what "delegate" is in your question. "onPostExecute" will handle whatever's returned in "doInBackground". More in the AsyncTask documentation.
Another option is to simply use a Handler and use postDelay() for later executions:

asynchronous request objective c

hi i am developing a sms App for my client. so far i have put down this plan in place.
1)The app keeps polling the server with an asynchronous request so that it does not interfere with the user interface.
2) for sending sms i am currently using synchronous request , depending on the reply from server i have do various things. i am showing the spinning circle and make the user wait until i get the response from server.
my client has problem with point 2.
The client says as soon as the send sms button is clicked it has to go back to the homescreen and should be able to navigate to any screen and do all other things that the app offers. i could have used async request , but i am not sure how to handle the responses from the server when i am on different view controller other than the one request is called from.
Can somebody help me on this.
Thank You.
The classic way of handling the response of an asynchronous action is either using delegation or notifications. Do not use a singleton. This breaks modularity and decoupling of different view controllers.
Roadmap of how to handle asynchronous actions
Register for the response of the asynchronous actions. This can be setting the delegate of the requesting object e.g. NSURLConnection to the view controller, which is typically self in this context. The othe possibility is that you register for the notification which is fired by the requesting object if things have happend e.g. when a download is finished or an error occurred.
Implement the delegate methods or the notifications to update your model and/or your user interface. Be aware that updating the UI has to happen on your main thread.
Start the asynchronous action. What happens in the background is that a separate thread is spawned or an operation is dispatched using GCD. These are implementation details and do not bother you.
Wait for the answer, which will result in one of your implemented methods to be executed which you then use to update what has changed.
Difference between notifications and delegates
The two differences between delegates and notifications is that delegate is a one-to-one connection between the delegate and the delegating object. Notifications are posted application wide and can be observed by as many objects as needed creating a one-to-many connection. Think about this as a broadcast. The second main difference is that delegation can be used to transfer information back from the delegate to the delegating object. Meaning that the delegating object asks the delegate for certain information. Typical example would be the data source of an UITableView. Notifications however are a one way street. The information flows from the posting object to the observing objects. This makes sense because think about the situation where you would have more than one observer and each would give feedback to the posting objects. Which one would be the right one?
In your case you would have to look up the delegate methods of the asynchronous HTTP request object and implement them accordingly.
Maybe you can try ASIHTTpRequest , It has Sync an Async request
If you using Async request , you can do anything after you press a button to do a request .
Check this
The solution depends on the response processing.... if you are just showing user that the sms sending is failed/successful than you can do it in any general utility class that shows alert.. but for this you have to create the singletone instance of your connection class so delegate(class itself) don't die when the response comes back.......
For this we need to keep track of currentViewController ....... we can do this by creating a reference ........ id currentViewController in appDelegate(with setter/getters).......... so it could be accessible in everywhere application........
its referred object should be changed each time when user changes the viewController.... that will help us to know on which viewController user is currently working.
than when the singeltone class of connection finished its response loading we can use this currentViewController with your desired viewController.
I am not sure how you are using different view controller....... pushing it/ presenting it or adding its view.....

When should the ViewModels call Services and Isolatedstorage

I'm using the MVVM-Light toolkit and storing my ViewModelLocator in App.Resources. I noticed that my ViewModelLocator class gets created before the Application_Launching event gets fired, and according to this Link from Microsoft you shouldn't make any Network calls or access Isolated Storage until after the Application_Loading event has fired and the application is loaded.
So my problem is that my ViewModelLocator creates my ViewModels in its constructor and the ViewModels in turn are making Service calls and accessing IsolatedStorage. So how are you suppose to do this properly? And how do I wait for the app to be "Loaded" when there is no Application_Loaded event?
My understanding is if the load calls are asynchronous, it meets your requirments.
Otherwise, you can always implement your own flag system/ delayed delegate calls after load event completes.

What is NSNotification?

Can anybody explain the importance of NSNotificationCenter?
Where to use them?
What is the difference between NSNotificationCenter vs. AppDelegate?
Apple has provided an Observer Pattern in the Cocoa library called the NSNotificationCenter.
The basic idea is that a listener registers with a broadcaster using some predefined protocol. At some later point, the broadcaster is told to notify all of its listeners, where it calls some function on each of its listeners and passes certain arguments along. This allows for asynchronous message passing between two different objects that don't have to know about one-another, they just have to know about the broadcaster.
You can find more details about it here: http://numbergrinder.com/node/32
The Application Delegate is an object which receives notifications when the UIApplication object reaches certain states. In many respects, it is a specialized one-to-one Observer pattern.
You can read more about it here: What is the AppDelegate for and how do I know when to use it?
If you come from an Actionscript background then NSNotification is like adding listeners to objects I guess.
NSNotification is like notifying the other class about the changes that will happen if some action takes place in another class.