Skip to content

Instantly share code, notes, and snippets.

@Bashta
Created February 23, 2016 09:54
Show Gist options
  • Save Bashta/68e7873d333edad297f3 to your computer and use it in GitHub Desktop.
Save Bashta/68e7873d333edad297f3 to your computer and use it in GitHub Desktop.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
Parse.setApplicationId("asd",
clientKey: "asdasd")
let completionBlock: () -> Void = {
// do something when it successfully starts the session
}
let errorBlock: (NSError!) -> Void = {error in
// check the error
print(error)
}
RevMobAds.startSessionWithAppID("5658c286572018d36f3fee27",
withSuccessHandler: completionBlock, andFailHandler: errorBlock);
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
//Push notifications
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return FBSDKApplicationDelegate.sharedInstance().application(application,
didFinishLaunchingWithOptions: launchOptions)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
if PFInstallation.currentInstallation().badge != 0 {
PFInstallation.currentInstallation().badge = 0
PFInstallation.currentInstallation().saveEventually()
application.applicationIconBadgeNumber = 0
}
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// Store the deviceToken in the current installation and save it to Parse.
let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.saveInBackground()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
DataManager.sharedInstance.handleAppllicationOpeningFromPushNotification(userInfo)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if application.applicationState == .Inactive {
DataManager.sharedInstance.handleAppllicationOpeningFromPushNotification(userInfo)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment