I'm creating a jailbreak tweak that includes calling from the lockscreen. I am currently using [[%c(SKTelephonyController) sharedInstance] dialNumber:number] to call a number.
Everything is working fine and the call goes through until you try to make a call when there is an open application. For example, if you leave an application open and lock the phone without closing the application, SpringBoard will crash when you try making the call. If there is no open application, the call works fine and there is no crash.
Is there a way to suspend the application programmatically?
I've already looked into [[%c(UIApplication) sharedApplication] _killThermallyActiveApplication];, but the selector is unrecognized, although it is found in the private headers. I've also tried [application disableContextHostingForRequester:#"LaunchSuspend"], which also isn't working.
I'm trying to deactivate the application before making the phone call, but after 2 days of searching through headers, I am unable to do so.
Any help is appreciated.
Finally figured it out! I'll put the code below for those who need it.
[[%c(UIApplication) sharedApplication] quitTopApplication:nil];
Related
I can make user to call from my app. I want to get the length of the call in my app, Once the call is ended
No,You can't get that officially.As once you initiate telprompt:// it would leave your application & once the call has been ended there is no delegate to be called later and you are outside your app.You can't access any call related information in non-jailbroken phone.
Well below link will surely help.
https://iosstuff.wordpress.com/2011/08/19/accessing-iphone-call-history/
But for sure, for sure Apple will reject the app.
Encountered a very weird problem, using simple AFNetworking downloading operation, even tried with simple NSURLConnection operation, connection fails if you keep your app running, and lock screen and then unlock. Works absolutely fine in background though.
Any one encountered similar problem with NSURLConnection want to share some solution?
Thanks.
It looks like an iOS bug. Weird, but lock screen action affects NSURLSession somehow, so that it stops working and returns NSURLErrorNetworkConnectionLost. So in my app I gave up using shared session. I either use a new session object for every request or (if I need to maintain one session constantly) recreate it every time the screen gets unlocked. And it works. For users of AFNetworking or any other third party library working on top of NSURLSession the situation is harder, of course. You'll need to correct the code of the library, which is definitely not a good thing, but I think there's no other choice
Very helpful Andrey Chernukha,
In my case, figured out that you don't necessary need to recreate new session every time.
I ended up using array to save running NSURLSessionDataTasks and after phone is unlocked resume them.
Steps:
I created array NSMutableArray *dataTasksToResume
In - (void)applicationWillResignActive:(UIApplication *)application I saved all tasks to dataTasksToResume array
Cancel all running NSURLSessionDataTasks
In - (void)applicationDidBecomeActive:(UIApplication *)application get all tasks from array and resuming them (re-creating them)
Enjoy!
Hope it helps.
I am using [[UIApplication sharedApplication] openURL:url] to open social media URLs in an app. However, I can't seem to open more than two to four URLs before my app gets killed (app ended unexpectedly). I also notice that when I call the above mentioned method, my memory usage is jumping significantly (I was hoping this would not be the case).
I tried to open the exact same URLs from mail.app, and I can keep opening the URLs without mail.app being killed. So definitely something is wrong with my app.
Question 1: Any input on how can I avoid increasing memory usage when I call [[UIApplication sharedApplication] openURL:url].
Question 2: Why is mail.app not getting killed, while my app is killed?
Many thanks!
Upon researching another question on stack overflow and following suggestion to remove NSLog (not many of them in my app), things seem to work just fine and my app is not getting killed. I am logging this for any future reference for other readers. If you're getting a message that your app is killed due to MEMORY PRESSURE, try removing NSLog from the app and see if that helps. It helped me! Here is the reference to the other thread: link
I have a application running in background and I need to know if device is sleeping in order to start a sincronisation process, but I didn't find information about this.
Does anyone know if it is posible and how do it?
Thanks.
You cannot know if the device is asleep because you have no control over the OS.
You can, otherwise, use the App Delegate method:
- (void)applicationWillResignActive:(UIApplication *)application
{
//your code goes here
}
if you want to wait till your app goes to background
I believe you can't do this using public API. The only thing which you can check whether your application is active or in background (using AppDelegate callbacks). And as Luke pointed out in comments, checking whether device "falls asleep" isn't iOS best design practice.
There are some private API's to do what you want, you can look at following questions:
Is there a way to check if the iOS device is locked/unlocked?
Detect screen on/off from iOS service
However, you should be aware that your app won't be accepted in AppStore in such case.
How programmatically restart an iPhone app in iOS?
I find this way http://writeitstudios.com/david/?p=54
But may be something simple.
The only way I know to do this is not ideal, but it works.
First, your app has to opt out of background execution (multitasking) The app has to quit when exited, not run as a background task. This is done with the plist key UIApplicationExitsOnSuspend.
Second, your app needs to register a custom URL scheme that can be used to launch the app.
Third, you need a web page hosted somewhere that when loaded will redirect to your app's custom URL scheme.
Forth, the user needs an active Internet connection.
To exit and restart, call UIApplication openURL on your hosted redirecting web page. Your app will exit and safari will launch and load your page. The page will redirect Safari to your custom URL scheme, prompting Safari to internally call openURL, causing iOS to launch your app.
my post that you linked to is referring to a Cocoa Application, not the iOS. On the iOS, you can quit an application (but Apple doesn't like this) by using exit(0); but I don't recommend that. You cannot restart iPhone apps though.
Unless you're developing for jailbroken devices, Apple won't even allow you to programatically terminate your app. So restarting the device is out of the question.
Your AppDelegate instance has a method
(void)applicationDidBecomeActive:(UIApplication *)application
{
}
In here, you can put logic to figure out if the app should restart, or continue doing whatever it was doing. For example you can have a BOOL variable appMustRestart that is false at first but gets triggered as true whenever something happens in your app that you'd like the next time to be a fresh relaunch.
if (appMustRestart)
{
[self resetVars]; // call a method that resets all your vars to initial settings
// INSERT CODE HERE TO TRANSFER FOCUS TO INITIAL VIEWCONTROLLER
}