<commit_before># motion-takeoff [![Build Status](https://travis-ci.org/MohawkApps/motion-takeoff.png)](https://travis-ci.org/MohawkApps/motion-takeoff) [![Code Climate](https://codeclimate.com/github/MohawkApps/motion-takeoff.png)](https://codeclimate.com/github/MohawkApps/motion-takeoff) [![Gem Version](https://badge.fury.io/rb/motion-takeoff.png)](http://badge.fury.io/rb/motion-takeoff)

A RubyMotion specific iOS gem for scheduling stuff. You can use motion-takeoff to display messages at certain launch counts and schedule local notifications. Currently, there are two modules in this gem: `Messages` & `Reminders`.

The `Messages` module will allow you to schedule alerts to users at certain launch counts.

The `Reminders` module is a nice wrapper for `UILocalNotification` to help you set reminders for the user to come back to your app at specified periods of time. It supports all the options of `UILocalNotification` and does some fancy interpretation of dates for you if needed.

More modules are planned for the future. This gem is in its infancy. Please help me make it better!

## Installation

Add this line to your application's Gemfile:

    gem 'motion-takeoff'

And run: `bundle`

## Usage: Messages Module

Open your app delegate and in your `applicationDidBecomeActive:` method do something like this:

```ruby
def applicationDidBecomeActive(application)
  messages = Takeoff::Messages.new
  messages.schedule launch:1, title:"Welcome to #{App.name}!", message:"Thanks for checking it out!"
  messages.schedule launch:3, title:"Quick Tip:", message:"This is the 3rd time you've launched this application!"
  messages.schedule launch:500, title:"Quick Tip:", message:"This is the 500th time you've launched this application!"
  messages.takeoff
end
```

This will display an alert to the user on the 1st, 3rd, and 500th launches of the app.

### Asking for confirmation

You can use the Messages module to ask a user to do something. Just pass a `Proc` object to the `:action` option. You can send an array of strings using `:buttons` but it will default to `["Cancel", "OK"]`. When the user presses the "OK" button, the `Proc` will run.

```ruby
def applicationDidBecomeActive(application)
  messages = Takeoff::Messages.new
  messages.schedule(
    launch: 1,
    title: "Welcome to #{App.name}!", 
    message: "So you want to view the settings?"
    action: Proc.new{ App.delegate.viewController.showSettings }
  )
  messages.takeoff
end
```

## Usage: Reminder Module

The reminders module is a nice wrapper on `UILocalNotification` and makes it easy to schedule reminders to come back and use your app!

You should always reset all local notifications when your app becomes active:

```ruby
def applicationDidBecomeActive(application)
  Takeoff::Reminders.reset
end
```

And here's how to set multiple reminders when your app enters the background:

```ruby
def applicationDidEnterBackground(application)
  Takeoff::Reminders.schedule(
    body: "Fires 20 seconds after the user closes your app.",
    fire_date: 20 #seconds
  )

  Takeoff::Reminders.schedule(
    body: "Fires 10 seconds later.",
    fire_date: Time.now + 30 #Time object in the future
  )
end
```

The `Takeoff::Reminders.schedule` method takes a hash of options that are send to the `UILocalNotification`. `body` and `fire_date` are required and will raise an exception if you try to schedule a notification without those two options. Here's all the default options:

```ruby
{
    action: nil,
    launch_image: nil,
    badge_number: 0,
    has_action: true,
    repeat: {
        calendar: nil,
        interval: 0
    },
    time_zone: NSTimeZone.defaultTimeZone,
    sound: UILocalNotificationDefaultSoundName,
    user_info: {}
}
```
<commit_msg>Clarified timing on reminders example.<commit_after># motion-takeoff [![Build Status](https://travis-ci.org/MohawkApps/motion-takeoff.png)](https://travis-ci.org/MohawkApps/motion-takeoff) [![Code Climate](https://codeclimate.com/github/MohawkApps/motion-takeoff.png)](https://codeclimate.com/github/MohawkApps/motion-takeoff) [![Gem Version](https://badge.fury.io/rb/motion-takeoff.png)](http://badge.fury.io/rb/motion-takeoff)

A RubyMotion specific iOS gem for scheduling stuff. You can use motion-takeoff to display messages at certain launch counts and schedule local notifications. Currently, there are two modules in this gem: `Messages` & `Reminders`.

The `Messages` module will allow you to schedule alerts to users at certain launch counts.

The `Reminders` module is a nice wrapper for `UILocalNotification` to help you set reminders for the user to come back to your app at specified periods of time. It supports all the options of `UILocalNotification` and does some fancy interpretation of dates for you if needed.

More modules are planned for the future. This gem is in its infancy. Please help me make it better!

## Installation

Add this line to your application's Gemfile:

    gem 'motion-takeoff'

And run: `bundle`

## Usage: Messages Module

Open your app delegate and in your `applicationDidBecomeActive:` method do something like this:

```ruby
def applicationDidBecomeActive(application)
  messages = Takeoff::Messages.new
  messages.schedule launch:1, title:"Welcome to #{App.name}!", message:"Thanks for checking it out!"
  messages.schedule launch:3, title:"Quick Tip:", message:"This is the 3rd time you've launched this application!"
  messages.schedule launch:500, title:"Quick Tip:", message:"This is the 500th time you've launched this application!"
  messages.takeoff
end
```

This will display an alert to the user on the 1st, 3rd, and 500th launches of the app.

### Asking for confirmation

You can use the Messages module to ask a user to do something. Just pass a `Proc` object to the `:action` option. You can send an array of strings using `:buttons` but it will default to `["Cancel", "OK"]`. When the user presses the "OK" button, the `Proc` will run.

```ruby
def applicationDidBecomeActive(application)
  messages = Takeoff::Messages.new
  messages.schedule(
    launch: 1,
    title: "Welcome to #{App.name}!", 
    message: "So you want to view the settings?"
    action: Proc.new{ App.delegate.viewController.showSettings }
  )
  messages.takeoff
end
```

## Usage: Reminder Module

The reminders module is a nice wrapper on `UILocalNotification` and makes it easy to schedule reminders to come back and use your app!

You should always reset all local notifications when your app becomes active:

```ruby
def applicationDidBecomeActive(application)
  Takeoff::Reminders.reset
end
```

And here's how to set multiple reminders when your app enters the background:

```ruby
def applicationDidEnterBackground(application)
  Takeoff::Reminders.schedule(
    body: "Fires 20 seconds after the user closes your app.",
    fire_date: 20 #seconds
  )

  Takeoff::Reminders.schedule(
    body: "Fires 10 seconds after the first notification.",
    fire_date: Time.now + 30 #Time object in the future
  )
end
```

The `Takeoff::Reminders.schedule` method takes a hash of options that are send to the `UILocalNotification`. `body` and `fire_date` are required and will raise an exception if you try to schedule a notification without those two options. Here's all the default options:

```ruby
{
    action: nil,
    launch_image: nil,
    badge_number: 0,
    has_action: true,
    repeat: {
        calendar: nil,
        interval: 0
    },
    time_zone: NSTimeZone.defaultTimeZone,
    sound: UILocalNotificationDefaultSoundName,
    user_info: {}
}
```

{'fraction_non_alphanumeric': 0.0928476821192053, 'fraction_numerical': 0.006622516556291391, 'mean_word_length': 4.491636363636363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4832446', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2120, 'n_words': 877}