iOS 8 Push Notifications in RubyMotion

iOS 8 changed the way apps register for push notifications. In order for your app to register for push notifications successfully on both iOS 7 and 8 you’ll need to check the version number and register differently.

if !Device.simulator?
  if Device.ios_version.start_with? "8"
    settings = UIUserNotificationSettings.settingsForTypes((UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound |           UIRemoteNotificationTypeAlert), categories:nil)
    UIApplication.sharedApplication.registerUserNotificationSettings(settings)
    UIApplication.sharedApplication.registerForRemoteNotifications
  else
    UIApplication.sharedApplication.registerForRemoteNotificationTypes(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)
  end
end