Skip to content

Instantly share code, notes, and snippets.

@MarkVillacampa
Created February 26, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkVillacampa/12033317b604a950937a to your computer and use it in GitHub Desktop.
Save MarkVillacampa/12033317b604a950937a to your computer and use it in GitHub Desktop.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:options)
if options && options[UIApplicationLaunchOptionsRemoteNotificationKey]
# The application was completely closed and the user launched it by tapping on a notification
else
# The application was completely closed and the user launched it by tapping on the app's icon
end
end
def application(application, didReceiveRemoteNotification:notification)
if application.applicationState != UIApplicationStateActive
# The application received a notification while it was inactive.
# The app can be inactive because it was in the background and is in the process of being foregrounded,
# or because the user opened the notification center, or the control center, or is in a call over our
# application.
# To check if the application is inactive because it is in the process of being foregorunded,
# we store the time of the last call to "applicationWillEnterForeground" and check if it was
# less than 1 second ago.
return if @last_foregrounding.nil? || NSDate.date.timeIntervalSinceDate(@last_foregrounding) > 1
Router.handle_notification(notification)
end
end
def applicationWillEnterForeground(application)
@last_foregrounding = NSDate.date
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment