Launch iOS App on long press of home button / volume button(s) - ios

If the above scenario is possible then immediately I need to Send SMS/invoke service call after my app is launched.

The above scenario is not possible. It is an OS level functionality. But you can do what ever you want when your app is launched either in the application:didFinishLaunchingWithOptions method in your AppDelegate or the viewDidLoad method of your rootViewController.

Related

Swift Xcode - how to differentiate between going to lock screen and going to home screen?

When the app enters the background or WillResignActive, both functions are called in my SceneDelegate. How am I able to distinguish between when the user exits the app to the HomeScreen versus just locking their phone?
EDIT: I want to perform a different function in each scenario

Perform action when opening app for the second time

When I open the app it fires the events viewDidLoad and viewDidAppear form my View Controller but when I close it and run it again it does not call any of them.
Any idea?
You need to read up on application states. Here is a link I found online outlining the different states:
http://www.techrepublic.com/blog/software-engineer/understand-the-states-and-transitions-of-an-ios-app/
What you really want is to be notified when your app becomes active.
Probably the easiest way is to implement the function applicationDidBecomeActive() in your app delegate. That will be called when your app becomes active as the foreground app either on launch, or when it returns to the foreground as the active app.
Note that if you want that notification sent to some object other than the app delegate you can listen for the UIApplicationDidBecomeActive notification.

applicationWillResignActive called without reason on iOS 10 ( swift 3 )

When I launch my app on iOS 10, I can see that after a short delay, the Appdelegate function -> applicationWillResignActive() is called.
There is no reason for that. The app is still active and in foreground state when it occurs and the app continues to run normally.
Please see above the lifecycle of my app :
--> Click on the app icon
App launch
application --> didFinishLaunchingWithOptions
application --> applicationDidBecomeActive
RootViewController --> viewDidAppear
application --> applicationWillResignActive <-- issue !
application --> applicationDidBecomeActive <-- again ??!!
at this point, the app is still running with no error
This sequence is repeated each time I open the app.
It looks as if something forces my app to quit the foreground state for an ultra short delay.
Usually, applicationDidBecomeActive is called when the app displays an alert ( for example if the app requires an user's permission to access the camera ) or when the user clicks on the home button.
1 - It only occurs when the app starts in landscape mode
2 - It only occurs on iPhones and not on iPads
3 - The problem does NOT occur on an iOS 9 device
Did anyone noticed this problem ?
The problem is, it calls second time after dismissing system services alert (location, push notifications, photos)
So the only way to handle it is to use variable in AppDelegate which increments each time some system alert shows and decrements in applicationDidBecomeActive, so you call your code only if value of this variable is 1.
Another interesting thing is that applicationDidEnterBackground doesn't call when system alert shows, thus we can use this info to decide whether we should call our code in applicationDidBecomeActive or not (but still, it can be less reliable solution)

applicationWillEnterForeground & UIActivityViewController

I have an issue with my obj-c iOS app.
I have a main view in it which is called to appear - when the app is reentering the foreground from the background - via applicationWillEnterForeground.
The thing is that when I use UIActivityViewController to open some content in another app (fx. Messages) this extern app opens on the top of my own and therefore, when I close the extern one, my own is not still in the foreground and applicationWillEnterForeground is not called. This causes a crash in my app.
I am looking for a possible alternative for applicationWillEnterForeground that tells the AppDelegate if the app is "in background" of another app via UIActivityViewController.
Any suggestions?

Determine the app state on pressing home button twice with app running

I would like to know as to what the application state would be on hitting the iphone "Home" button twice with the application running.
The scenario is something like below:
My iOS app is running on the foreground
With the application running hit the home button twice to bring up the multi-tasking taskbar (obviously my app is not listed here because it's not a recently used app and is still running in the foreground)
Now press anywhere outside the taskbar (i.e in the application) and app will be back in focus again
My questions:
What state would be app be on performing above step #2? Would it enter background or still in foreground? What method would get triggered here?
On performing step #3, would the app re-enter foreground from background? Again what method would get triggered here?
Any hints/suggestions would be very helpful.
The application is about to move from active to inactive state, so it's still in-between. You should be able to use -applicationWillResignActive: in your UIApplicationDelegate.
After returning to the application, the application becomes active again thus receives a -applicationDidBecomeActive: on your UIApplicationDelegate.

Resources