Howto react to local notification in the currently running view - ios

I have a web app, that is running partly in background mode (at least for the time, iOS does allow that).
When an event occurs inside it, I ifre a local notification.
When the user clicks on it, the app comes back to the foreground, but I want to call some javascript function inside the web app.
How do I call a function inside my view controller from the app delegate's
application:didReceiveLocalNotification method?

Assuming myViewController as the rootViewController you can use:
AppDelegate *delegate = (AppDelegate *) application.delegate;
[delegate.window.rootViewController launchJavascriptMethod];

Related

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

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.

IOS: Is it possible preserve the State of UIViewController in Background

Am developing an IOS app. Where i need to make some images upload to server. Am using NSURLSession and uploadTaskWithRequest to do this. Every thing is working fine in normal way. My requirement user wants to store some post with more than 10 images in app using database SQLLite. And later show all the stored posts in UITableView with button for each UITableViewCell. When user tap on each button it should start uploading each POST to server. So I thought i should persist my UIViewController in AppDelegate so the process of uploading should not be killed when user go to another view controllers.
My Problem: When user close the app the process is in which UIViewController POST uploading is Stoping. So i would like to know how to keep my UIViewController live even in app go close or go into background.
Is there any better way to fulfill my requirement.
Here are some better ways!
Use a singleton. In my apps, I'll usually create a class called "DataHandler" that handles all of the NSURLSession/CoreData/etc stuff so all I have to do is
[DataHandler uploadImages:images];
and when I need the information back I'll call
self.tableData = [DataHandler lastUploadedImages];
This way I don't have to worry if my view controller is still alive.
Have the AppDelegate do the NSURLSession stuff. You already know the AppDelegate is persisted so why not just have that guy do it! Here is an example:
UIApplication *sharedApplication = [UIApplication sharedApplication];
AppDelegate *appDelegate = [sharedApplication delegate];
// this is the method you would add to your AppDelegate. Make sure to
// import your AppDelegate's header file so your ViewController can
// call the method.
[appDelegate uploadImages:images];

How to disable iPhone 'app not active' flashing banner

My app checks the GPS while my app is not the active app and I use AVAudioplayer too in background.
It works fine and stays in the background doing its thing, but ios7 displays this red top banner with my app name flashing on it when it is not the active app.
How can I disable this banner, it is annoying to use other apps that are squished down 1 line?
I know this can be done as I have other GPS based background apps that don't display this flashing banner.
EDIT - So we found the answer quickly but the solution evades me:
If I stop OpenEars pocketsphinxController from listening with a button that calls this method while the program is active, the banner disappears when the app loses focus:
-(void) mystopListening{
NSLog(#"Tried to stop listening");
[pocketsphinxController stopListening];
}
BUT if I call the same method from my app delegate with (I had to import my view controller.h file in my app delegate.h and add -(void) nystopListening; in my view controller.h to make the below execute properly):
- (void)applicationWillResignActive:(UIApplication *)application{
myViewController * vc = [[myViewController alloc]init];
[vc mystopListening];
}
The banner persists! It is a little like ios7 has decided I am a recording culprit before I even have a chance to turn it off. OR, am I even turning it off?
How do I do this effectively and in what event?
EDIT - So it turns out I am not really turning pocketsphinxController off when 'mystopListening' is called from the app delegate. I know this because it DOES log the 'Tried to stop listening' when called from app delegate but the pocketsphinxController does not respond with its 'pocketsphinxDidStopListening' method. PocketsphinxController does call its 'pocketsphinxDidStopListening' method when I call 'mystopListening' from a button while the app is active.
Why won't the pocketsphinxController respond when called from from the app delegate, I must be doing it wrong?
Thanks,Carmen
Turns out I was not really calling the original pockectsphinxcontroller instance from my app delegate.
As a workaround to the problem I did this:
My app always has a timer running, so in my app delegate where I get notice of when app goes to inactive and comes back active, I just set global flags so my timer can know app active status. Then my timer just uses pockecsphinxcontroller methods to stop and start listening and voila, the banner is no more while app not active.

Delaying openURL when app launched via remote push through didFinishLaunchingWithOptions

Here's my app scenario: When user swipes a notification I will launch some other app via URL.
So it basically launches some other app when notification arrives.
Currently to handle swiping notification scenario, when
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)
method is invoked, within this method, I call processNotification: method, which contains:
...
[[UIApplication sharedApplication] openURL:url];
...
If push received while app is active, url is opened perfectly fine.
If push received by swiping or clicking on notification, url is opened in the background but the currently viewed app is my application. For example if my url is tel:123-456-7890, iOS starts the call (you can hear the sound) but active app is not Phone.app, it is my app.
That seemed pretty strange to me. However if I wait for UI to load, and call processNotification: after that, it brings up Phone.app window correctly. (bug in platform? because call happens but my UI is on the top.)
I need a method to delay execution of this processNotification: call, (maybe through an operation queue) until a view controller is loaded. Otherwise, my app stays on top and the URL is opened in the background.
I was facing the same issue, I moved the openURL into main_queue and it seems to be working fine. I did not have to even make that change in didBecomeActive
dispatch_async(dispatch_get_main_queue(), ^(void){
[[UIApplication sharedApplication] openURL:url];
});
You should delay your handling of the push notification (i.e. calling openURL:) until applicationDidBecomeActive:. Keep the parameters you need from application:didFinishLaunchingWithOptions: but only call your handling code in applicationDidBecomeActive:.
I think the problem here is that SpringBoard is unable to cope with one app transition being called while another is in progress. An iOS bug of course. You should open a bug report at https://bugreport.apple.com

iPhone UILocalNotification load specific view

I have my local notification working, but when I click View to come back to the app, in the app delegate I am trying to load a specific view, but it wont take. Is this possible or not? It always just comes back to the last view viewed.
When you tap "View" on the notification, it takes you back to your application, and your application shows whatever it was showing before (if it was backgrounded) or is launched.
If you need to show a particular UI in response to the notification, consider implementing the <UIApplicationDelegate> method -[<UIApplicationDelegate> application:didReceiveLocalNotification:]. In that method you can inspect the notification and transition to the appropriate interface.

Resources