iOS equivalent to Android registerActivityLifecycleCallbacks - ios

I developed an Android app where I used the application.registerActivityLifecycleCallbacks (http://developer.android.com/reference/android/app/Application.html) to know when each Activity is started and stopped and record it for analytics purposes. I am now developing the iOS version and I cannot find an equivalent to this method to monitor the UIViewControllers or UIView displayed by the app.
Anybody has an idea ? I am a beginner on iOS so I may not be taking the right approach, feel free to suggest other ideas.
Edit
After the first answer I felt I should be more precise.
I am actually developing a SDK for other developers to include in their apps so I want the impact of the SDK on their code to be as small as possible.
I first thought about doing a BaseActivity/BaseUIViewController that developers would have to extend in all the Activity/UIViewController but it felt heavy and since both language don't allow multiple inheritance this would greatly impact their code. This is why the registerActivityLifecycleCallbacks method is great in Android because they only have to give me an Application or Activity object.
Is there a solution for iOS or I will have to create a BaseController ?
Thank you in advance.

I've not run into anything that specific as the application.registerActivityLifecycleCallbacks in iOS, but you could always implement your own using the methods that exist within the AppDelegate and each class.
From the AppDelegate, you are provided the methods to determine the state of the overall application such as determining when the application finished loading, when it enters the background, and so forth. Details on these states can be found in the UIApplicationDelegate Protocol Reference page.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog("Application did finish launching with options: %#", launchOptions);
return YES;
}
For each view controller, you can add your implementation to the individual view controller lifecycle methods within each file. Methods such as viewDidLoad, viewWillAppear, viewDidAppear, and viewDidLayoutSubviews are available.
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"View %# did load", self);
}

Related

Detect when iOS breadcrumbs are used to return to app

I can't find information about how to detect when the iOS breadcrumbs are used to return to the app. I am looking to call a function on the controller when the view is active again specifically when this breadcrumb is used (Our use case being when location has been enabled externally).
I have tried using viewDidAppear but this isn't called. Is it possible? I find it unusual that this isn't called.
To be clear the breadcrumbs I am talking about are
I think you can use this method on Appdelegate
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
then send a notification to your viewcontroller you want to handler.

Flurry ads integration using SDK 6.0 creates performance issue app crashes

Hi I am using latest flurry SDK 6.0 in app. I need to show ads almost every where in my app. App is UINavigationControllerBased contains more viewControllers. I am using code given in flurry documentation.
I am using below code in each and every ViewController but some times I move fast just like push and pop before add received,so in that case callbacks are continuously receiving but that viewcontroller is not available in stack at that time app crash or recieve memory. I tried to set adDelegate to nil in viewWillDisappear but flurry documentation says don't set it as nil.
Anyone has any ideas regarading this?
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(self.adBanner == nil){
self.adBanner = [[FlurryAdBanner alloc] initWithSpace:#"Flurry Banner"] ;
self.adBanner.adDelegate = self;
[self.adBanner fetchAndDisplayAdInView:self.view viewControllerForPresentation:self];
}
}
Perhaps you should split the code in two?
Fetch the Ad using fetchAdForFrame. This prevents Flurry from using the view you passed.
Then inside the delegate, use displayAdInView. Only call this if you know the view is visible. So in viewWillAppear set a flag to say visible, in viewWillDisappear set a flag to say not visible. This should let you cut off the rendering part.
Seems odd an API like this would have no cancelFetchAd method!

Use Kamcord on non Cocos2d app

I am implementing according to kamcord tutorial :
https://github.com/kamcord/kamcord-ios-sdk/wiki/Getting-Started#wiki-kamcord-initialization
My app is a simple ios app not using the cocos2d game engine.
and for some reason I cannot see it working.
Here is the code implemented in app delegate :
_view_controller = [[ViewController alloc]init];
// Override point for customization after application launch.
// that will present the Kamcord UI.
[Kamcord setDeveloperKey:#"key"
developerSecret:#"secret"
appName:#"appName"
parentViewController:_view_controller];
and I call this methods from the viewController:
- (IBAction)stopRecording:(id)sender {
[Kamcord stopRecording];
NSLog(#"Stop");
}
- (IBAction)startRecording:(id)sender {
[Kamcord startRecording];
NSLog(#"Start");
}
-(IBAction)showUpKamcord{
[Kamcord showViewInViewController:self];
NSLog(#"kamcord");
}
First I start recording, then stop and after that I am showing the view,
any ideas?
Kamcord only works with OpenGL views. It does not record UIKit, so that won't work if that's what you're looking for.
I know this is an older question, but for those that stumble upon it looking for a solution to record your non-Open GL based screens, there is a project called ASScreenRecorder https://github.com/alskipp/ASScreenRecorder that allows you to record your UIKit based app screens and it's extremely simple to get working.

Changing rootViewController in applicaitonWillEnterForeground

Long story short, I'm trying to change my iOS app's rootViewController on applicationWillEnterForeground:, like so:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
MyViewController *controller = [[MyViewController alloc] init];
self.window.rootViewController = controller;
}
However, when iOS performs the "zoom in" animation that is performed when an app is moved from the background to the foreground, it still shows the previous rootViewController's view. Then, as soon as the animation is complete, the app blasts the new rootViewController's view onto the screen.
One way to solve this is to simply move that code to - (void)applicationDidEnterBackground:, but the problem with this solution is that, in my app, there is no way to tell if a new rootViewController will be assigned until - (void)applicationWillEnterForeground:(UIApplication *)application (it is based on time passed since leaving the app).
How can I force the app to redraw before iOS performs the animation taking the app from the background to the foreground?
I believe this is not possible. The screen that iOS shows of your app when it comes into the foreground is actually a screenshot the system took when the app went into the background. There is no way to manipulate or replace that image at the time the app comes back into the foreground.
This behavior is partly documented in the Moving to the Background section of the iOS Application Programming Guide:
Apps can use their applicationDidEnterBackground: method to prepare for moving to the background state. When moving to the background, all apps should do the following:
Prepare to have their picture taken. When the applicationDidEnterBackground: method returns, the system takes a picture of your app’s user interface and uses the resulting image for transition animations. If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns.
Apple does not explicitly document that you cannot modify or replace this screenshot at a later time but neither do they say the opposite anywhere I know of.

Best approach for implementing a pincode for application launch & didEnterForground

I have constructed a pincode view controller that I would like to implement in my app to secure it from unwanted fingers.
I have been looking into how best to implement it so it appears only when the app is first launched & when it returns to the foreground after being in the background.
The appDelegate.m has didFinishLoading & applicationWillEnterForeground but I have been unable to create my view controller here because the window has not yet been loaded.
I would add it to the viewDidLoad method of my view controller but I'm using a TabBarController so would need to do this for all tasks & then the pin would be required whenever the user switches between them.
Does anyone have any suggestions/ code examples/ best practices of how I can achieve this?
Many thanks, James
Try using your AppDelegate's - (void)applicationDidBecomeActive:(UIApplication *)application. I believe you have a window at this point. Anyway even if there is no window yet, there are easy workarounds for that.

Resources