Is there a way to know when an iOS device locks/unlocks? - iphone

I need to be able to perform some actions when the user unlocks the screen (namely they need to log-in again). I checked the UIApplicationDelegate protocol thinking it was a logical place for such an interface, but didn't see anything that seemed to do this. Is this even possible?
Edit:
applicationDidBecomeActive: and applicationDidEnterBackground: look like they may get triggered for unlocking and locking, but the documentation doesn't mention it specifically.

You can use applicationDidBecomeActive and applicationWillResignActive this will tell you any time the app is slept, this includes locking the phone, and things like phone calls.
applicationDidBecomeActive:
This method is called to let your application know that it moved from the inactive to active state. This can occur because your application was launched by the user or the system. Applications can also return to the active state if the user chooses to ignore an interruption (such as an incoming phone call or SMS message) that sent the application temporarily to the inactive state.
applicationWillResignActive:
This method is called to let your application know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. An application in the inactive state continues to run but does not dispatch incoming events to responders.

Related

Swift - Can I use PushKit but don't make a call?

As the title, I just want to receive a VoIP message, then do something.
But it seems to be necessary to do reportNewIncomingCall in didReceiveIncomingPushWith, and it will make the caller scene shows up.
Can I cancel the call before it shows up ?
Can I cancel the call before it shows up?
No.
Generally, any computation from a push notification should inform the user for security purposes. As pushkit wakes up the main app for computation compared to the normal push which wakes only notification extension, it does have more restrictions, for example, callkit UI must be shown to the user.
By default, for any push notification regardless of VOIP or other, it must present a notification to the user. From apple doc, to suppress showing notifications when using pushkit you must have com.apple.developer.user notifications.filtering capabilities.
As a result, hiding notifications and showing callkit with the above-mentioned capability will require extra permission from apple.
However, one way can be a silent push, but that is limited to two or three per hour.

iOS: Receive media in background

I am developing SIP and VoIP based iOS application and requirement is that the application should be continuously running even in background also.I am using pjsip lib.
I know that to run the iOS application in bacground,we need this
Set UIBackgroundModes key in Info.plist with voip value
Created a handler that I passed to setKeepAliveTimeout:handler: for
keeping the connection alive
But I just want that if my application is running in background can I receive UDP packets over (RTP/RTCP),while I am keeping UDP port always open.
I have already gone through the posts:
iPhone VOIP in background
VoIP socket on iOS - no notifications received
But,I have not getting clear idea that can we get UDP packet continuously even the app is in background or foreground.
So that if there is any data is coming to iOS client app , the app should be able to notify the user.
Please give suggestions.
In order to run VoIP app at the background and register on a server one should use TCP on iOS. When something happens you can fire local notification.
I think you can set local notifications when the app is running in background and indicate the user of an incoming call through the notification. When the user enters the application you can show the incoming call.
In the below link, check
Background Execution and Multitasking and also Scheduling the Delivery of Local Notifications
IE since you have set the UIBackgroundModes key in Your Info.plist, your app will support long running tasks. So in the applicationDidEnterBackground method add a method which creates a UILocalNotification when there's a call. UILocalNotifications notifies the user with an alert message and a tone of your choice. So once the user is notified and user enters the app, the app will come to foreground where you can add the method for him to receive the call.
In the alert body of the LocalNotification you can send the caller's information to the user.
EDIT : Check out the answer of Paul Richter in this link, where he says
VOIP mode gives you the ability to have code running to notify you of a call coming in
but you're not going to be able to record audio from the background. If you look at how
Voip apps work, when a call comes in a Local Notification is sent informing the user
that a call is coming in. The User then must accept the call which will bring the
application to the foreground at which point from the audio side of things you can
activate your session and proceed with the phone call.
Although not completely related to the library you are using, he has given a decent explaination of the process.
Hope this helps.

Call from within a app and retain the app state

In my application, I have a requirement of displaying some information on a page including the phone number. I need to allow user to make phone call from this page and also want to retain the state of the application once call is over i.e. once user is done with the call, he should land back to the original page where he left. How to achieve this?
iOS4 features multitasking.
You don't need to do anything. User taps somwhere, makes a call, ends it and applicationDidBecomeActive: in your AppDelegate is called. And your app returns exactly to the place where user left it.
From UIApplicationDelegate's Protocol Reference:
This method is called to let your application know that it moved from
the inactive to active state. This can occur because your application
was launched by the user or the system. Applications can also return
to the active state if the user chooses to ignore an interruption
(such as an incoming phone call or SMS message) that sent the
application temporarily to the inactive state.

iOS: deliver NSLocalNotification or Push Notification only when user is idle

I want to send a notification to the user of my iOS application, preferably using NSLocalNotificaiton.
However, if the user is on a call I don't want them to recieve the notification until after the call (I don't want to interrupt their call). Is there any way to schedule the notification to occur after the call has ended?
A notification will no more interrupt a call than a calendar or SMS alert does—the alert view will appear on their screen, and if the ringer isn't silenced then the alert sound will play, but the user won't get disconnected or anything in the process. The only way you have of detecting that the user may have finished a call is the -applicationDidBecomeActive: method on your app delegate, but if your app's going to be in the foreground (which is the only point at which it'll receive that message) then you don't need to bother with a UILocalNotification. In short: no, you can't schedule things around the user's phone activity, but nor should you worry about your notifications interrupting them mid-call.

iPhoneOS, using applicationWillResignActive

I want to use this function applicationWillResignActive perform some tasks.
before the application shuts down due to incoming call, message or user close it manually.
Can i send an email message/in app sms using this function ? Will those tasks would be performed or the application would immediately quit due to the above mentioned interrupts.
Thank you all.
Taimur
Before sending email or sms on iOS you have to display standard UI to user (either MFMailComposeViewController or MFMessageComposeViewController), but you can't present any new UI when application is going to resign active state, so the answer is no - those tasks cannot be performed