Can I find out how long a user is sat on a UIViewController for?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Set an NSDate in
-viewDidAppear:and call[[NSDate date] timeIntervalSinceDate:yourDate]in-viewDidDisappear:. You’ll get the number of seconds spent in theUIViewController.If don’t want you track time when the application is not active, add the
UIViewControlleras an observer for the UIApplicationDidBecomeActiveNotification & UIApplicationWillResignActiveNotification, calling the-didBecomeActiveand-didResignActivemethods respectively.Update: added code to handle if app becomes inactive