Proper appDelegate method for Flurry startsession? - iphone

Flurry docs recommend placing the startSession call in applicationDidFinishLaunching:.
Two problems with this...
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[FlurryAnalytics startSession:#"AWESOMEAPIKEY"];
// ...
}
1) Isn't application:didFinishLaunchingWithOptions: the new approved launch point?
2) This is only called once on launch, but don't we want session info every time a user opens or switches back to the app? Or does Flurry handle all that on their own by listening to some event or NSNotification?
Wouldn't a better place to put the startSession call be in applicationDidBecomeActive: or applicationWillEnterForeground:, like so?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// ... Flurry AppCircle setup
[FlurryAnalytics startSession:#"AWESOMEAPIKEY"];
// ... your setup
}

for your case 1)
correct place to put [FlurryAnalytics startSession:#"SOMESESSIONKEY"]; is
application:didFinishLaunchingWithOptions:
you can place it there without worries. I have done this by myself and the app is working awesome at appstore and providing the stats perfectly.
for case 2), your secession will be automatically resumed when app returns to foreground so you dont have to do any special handling here.

I was real curious about this too. I looked at my inherited code for my app and didn't see any flurry activity in didbecomeactive, foreground, etc. I only saw the startsession in didfinishlaunchingwithoptions. I saw the below on the flurry site re: startsession, but i still don't get how it works, just behind the scenes stuff the flurry library does? #samfisher, can you elaborate?
"This method serves as the entry point to Flurry Analytics collection. It must be called in the scope of applicationDidFinishLaunching. The session will continue for the period the app is in the foreground until your app is backgrounded for the time specified in setSessionContinueSeconds:. If the app is resumed in that period the session will continue, otherwise a new session will begin."
FlurryApi.h shows the default as 10 for setSessionContinueSeconds so I guess Flurry handles it, I'm just looking for more confirmation.
http://support.flurry.com/sdkdocs/iOS/interface_flurry_analytics.html#a78b0b92085b38875d51f1ca0d699849a

Related

Doing something even if application is closed in iphone

I am developing iphone application where i want to develop feature of taking backup of files inside the application on to the server for every hour even if the application is completely closed.
I have tried to use NSLocalNotification but it is not calling method
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
in appdelegate. The notifier showing alert box with the buttons cancel and view , If I click in view it opens the application but not calling the method. Even if user say cancel then also it should call this method.
So it is not calling web service to take backup of files. Can any one please direct me to link which does the same.
Thanking You,
Rohit Jankar
You really can't do what you want. Since iOS does not allow application to run in the background unless it's is a VOIP client, AudioPlayer or track the user location.
The problem with the solution with UILocalNotification is that iOS handles the notification. When the user clicks cancel your app does not get informed about this. You can only handle the view button clicks.
The-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification is only called if you app is run or is restored from background running.
If you app gets start by the system when you user click view on the Local notification you will need to check if there is a notification in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method:
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
//handle the notification.
}
I am developing iphone application where i want to develop feature of
taking backup of files inside the application on to the server for
every hour even if the application is completely closed.
If you're talking about backing up files to your own server every few hours, there's really no way to do that. On the other hand, there should also be no need to do it when the app isn't running -- if the app isn't running, it can't modify data in its files and there shouldn't be any need to back up. Instead, just make sure that you back up your data periodically when the app is running.
If you just want to make sure that the app's data is backed up somewhere, consider using iCloud. Once you've set up your app to use iCloud, your data will be backed up whenever you update it.

Animation on iPhone app closing, like the shutter on camera app

I'd like my app to do an animation just before close, exactly like the official Camera app from Apple, that "closes the shutter" before closing itself. Is is possible or is this a private and undocumented API?
Thank you in advance!
There is no official way for your app to delay its closing after the user taps the home button. Apple wants users to be able to quit out of apps quickly and at anytime. However, you do get notified when your app is closing, and you do get a chance to run some code. I can't tell you for sure of any UI stuff would work, but the spot to try it is in your UIApplicationDelegate (AppDelegate) class. The methods you're interested in are:
- (void)applicationWillResignActive:(UIApplication *)application {
// Try some UI stuff here
}
Or:
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
I'm assuming the UI will change as the app window is animating away. Let us know if it works!

iPhone Application Themes

I tried using a multi-value settings bundle to change the view. I would do the if statements in the applicationdidfinishloading in the application delegate. Apparently the method isn't called every time the app is loaded, and it would not work correctly.
If anyone has done this, or has any suggestions, links to tutorials. I would really appreciate it. I'm just trying to load views (nibs) based on user preference.
I think you can put your code in
- (void)applicationDidBecomeActive:(UIApplication *)application
or
- (void)applicationWillEnterForeground:(UIApplication *)application
methods also because from iOS 4.0 due to multitasking your app is just in the background state so it wont call applicationdidfinishloading method when the user presses the icon of your app again.

Using the applicationWillTerminate method doesn't seem to be working

I am wanting to save some app state data for when the user is quitting the app. I am thinking that I should be using the applicationWillTerminate method inside of my appDelegate, but when I try and do anything there, it's not doing anything:
- (void) applicationWillTerminate:(UIApplication *)application {
NSLog(#"test");
}
When I run my app, and do some stuff, and hit the home button to quit the app, nothing comes over the console...
Do I have to implement the applicationWillTerminate method in the appDelegate? The user of my app will most likely be in a Reader view when they leave, is there anyway to implement the app will close method there?
see this link iPhone simulator and applicationWillTerminate() for older iOS versions;
but remember the Home button does not necessarily terminate the application is ios4... you should use applicationDidEnterBackground but would suggest both places applicationWillTerminate and applicationDidEnterBackground
Adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES will make you application quit when you hit the home button, even on iOS4
In iOS 4, the applicationWillTerminate: method is only called if you opt out of the background execution model. In the standard iOS 4 application lifecycle, applications are suspended (not terminated) when the home button is pressed. Your application delegate will receive an applicationWillResignActive: message followed by an applicationDidEnterBackground: message. The applicationDidEnterBackground: method is a good place to save user data.

How to react to applicationWillResignActive from anywhere?

What's the code to subscribe to an event like applicationWillResignActive in any place in your iphone application?
[UPDATE]
Let me rephrase my question. I don't want to respond to this in my application delegate, but rather listen to this event from another class. Is that possible or I need to pass the event from the application delegate to the concerning class?
Looks like you are looking for this code.
- (void) applicationWillResign {
NSLog(#"About to lose focus");
}
- (void) myMethod {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationWillResign)
name:UIApplicationWillResignActiveNotification
object:NULL];
}
Take a look at the documentation for the method you're talking about:
applicationWillResignActive:
Tells the delegate that the application will become inactive. This method is optional.
- (void)applicationWillResignActive:(UIApplication *)application
[...]
Discussion
[...]
Just before it becomes inactive, the application also posts a UIApplicationWillResignActiveNotification.
Implement the method below in your application delegate:
-(void)applicationWillResignActive:(UIApplication *)application
This allows you to react when the application becomes inactive - when this is the case, it is executing but not dispatching incoming events. This happens, for example, when an overlay window pops up or when the device is locked.
Just before it becomes inactive, the application also posts a UIApplicationWillResignActiveNotification.
Your topic and question are asking slightly different things.
Your application will receive applicationWillResignActive, along with applicationWillTerminate, automatically. No subscription is necessary, just implement the function in your app.
As to how to respond, this is down to the application. While you can choose to do nothing the recommended behavior is that you cease or slow any non-critical functionality. E.g. if you were a game you would stop updating the display and/or pause the game.