ProMotion-push 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddf74b4ca93f8c62d6e52e0b075302b83da7b98b
4
- data.tar.gz: 888f61229b99e186a060846a411e5b638dc65023
3
+ metadata.gz: 5ff3b591979913a0c05081d23ea7e5b98fa35e15
4
+ data.tar.gz: 7f585fc3277e542157e61bd299153fff52232bf1
5
5
  SHA512:
6
- metadata.gz: a724ff35734feec0d4fd661d22a0d78864fabd58d104db644ef24a452b378e0215d5a8afe7631cab188a37185dba6b1bff7075ee38be7d55e16ef2d2fd1ef021
7
- data.tar.gz: 85f5b8f4424efe80f2ee2356f87f929e441c5a7d59cf584d1206265f4dcfad43ca72724d476186bfa15eb4a573be3bcb7f7e9e2c5a7489eadbf98de8a7405020
6
+ metadata.gz: 4fdd9d1f049db7b0259cabc1ec1d4df219b4bf4d5cfa0f23481ecc7a47acd256f717671f237ffc533cc9486b21197f88192dbdbc98c4c1798548d8435efe245c
7
+ data.tar.gz: 786ebf2514cf8fd1900c7831cda37d4d774893a1d3d3bbfdf074bfbdeac279a72c44c8736c856418b2b40005008ea5e45300825caf8fa1fc9842eb9dd515c060
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ProMotion-push
2
2
 
3
3
  ProMotion-push is push notification support, extracted from the
4
- popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion).
4
+ popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion) and is maintained by [Infinite Red](http://infinite.red), a web and mobile development company based in Portland, OR and San Francisco, CA.
5
5
 
6
6
  ## Installation
7
7
 
@@ -104,6 +104,28 @@ def on_push_notification(notification, launched)
104
104
  end
105
105
  ```
106
106
 
107
+ ProMotion-push automatically adds support for handling push notifications while your app is in the background. If your push notification payload includes `content-available: 1` then you may have an opportunity to pre-fetch data. The return value of the `on_push_notification` method should one of the following that best matches the result: `:new_data`, `:no_data`, `:failed`. The default is `:no_data`, so you don't need to return anything if you did not fetch any data. For example:
108
+
109
+ ```ruby
110
+ # Payload:
111
+ # {
112
+ # "aps": {
113
+ # "content-available": 1,
114
+ # "alert": "My test notification",
115
+ # "badge": 3,
116
+ # "sound": "default"
117
+ # },
118
+ # "type": "new_messages"
119
+ # }
120
+
121
+ def on_push_notification(notification, launched)
122
+ if notification.type == "new_messages"
123
+ MessagesScreen.load_data
124
+ return :new_data
125
+ end
126
+ end
127
+ ```
128
+
107
129
  #### registered_push_notifications
108
130
 
109
131
  Returns the currently registered notifications as an array of symbols.
@@ -114,6 +136,54 @@ def some_method
114
136
  end
115
137
  ```
116
138
 
139
+ ### Actionable Notifications
140
+ As of IOS 8, notifications can include action buttons in the lock screen, notification banners and notification center. This is called the "Minimal" context and supports 2 actions. The "Default" context supports up to 4 Actions and applies when alerts are opened as popups.
141
+
142
+ To use these features with ProMotion-push you need to:
143
+
144
+ Define each action you plan to include in a notification for either context.
145
+ ```ruby
146
+ approve_action = UIMutableUserNotificationAction.new.tap do | action |
147
+ action.identifier = "APPROVE_ACTION"
148
+ action.title = "Approve"
149
+ action.activationMode = UIUserNotificationActivationModeBackground
150
+ action.authenticationRequired = false
151
+ end
152
+ ```
153
+
154
+ Register your actions by calling `register_push_notification_category` from your AppDelegate code prior to `register_for_push_notifications`, for each category of action you intend to use. Note that you must include a separate array for the actions to show in the minimal context.
155
+ ```ruby
156
+ def on_load(app, options)
157
+ register_push_notification_category 'APPROVAL_ACTIONS', [approve_action, deny_action, self_destruct_action], minimal: [approve_action]
158
+ register_push_notification_category 'SECOND_CATEGORY_NAME', # ...
159
+ # ...
160
+ register_for_push_notifications :badge, :sound, :alert, :newsstand # or :all
161
+ # ...
162
+ end
163
+ ```
164
+
165
+ Include one of the categories you just defined in your push payload
166
+ ```json
167
+ {
168
+ "aps" : {
169
+ "alert" : "Do you approve?",
170
+ "category" : "APPROVAL_ACTIONS"
171
+ }
172
+ }
173
+ ```
174
+
175
+ Implement `on_push_notification_action` in your AppDelegate to handle the selected action
176
+ ```ruby
177
+ def on_push_notification_action(action, notification)
178
+ # handle the action
179
+ case action
180
+ when 'APPROVE_ACTION'
181
+ # approve
182
+ when 'DENY_ACTION'
183
+ # deny
184
+ end
185
+ end
186
+ ```
117
187
 
118
188
  ### ProMotion::PushNotification
119
189
 
@@ -8,4 +8,6 @@ Motion::Project::App.setup do |app|
8
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
9
9
  app.files << File.join(lib_dir_path, "ProMotion/push_notification.rb")
10
10
  app.files << File.join(lib_dir_path, "ProMotion/delegate_notifications.rb")
11
+ app.info_plist['UIBackgroundModes'] ||= []
12
+ app.info_plist['UIBackgroundModes'] << "remote-notification"
11
13
  end
@@ -81,18 +81,23 @@ module ProMotion
81
81
 
82
82
  # CocoaTouch
83
83
 
84
- def application(application, didRegisterForRemoteNotificationsWithDeviceToken:device_token)
84
+ def application(application, didRegisterForRemoteNotificationsWithDeviceToken: device_token)
85
85
  on_push_registration(device_token, nil) if respond_to?(:on_push_registration)
86
86
  end
87
87
 
88
- def application(application, didFailToRegisterForRemoteNotificationsWithError:error)
88
+ def application(application, didFailToRegisterForRemoteNotificationsWithError: error)
89
89
  on_push_registration(nil, error) if respond_to?(:on_push_registration)
90
90
  end
91
91
 
92
- def application(application, didReceiveRemoteNotification:notification)
92
+ def application(application, didReceiveRemoteNotification: notification)
93
93
  received_push_notification(notification, application.applicationState != UIApplicationStateActive)
94
94
  end
95
95
 
96
+ def application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: callback)
97
+ result = received_push_notification(notification, application.applicationState != UIApplicationStateActive)
98
+ callback.call(background_fetch_result(result))
99
+ end
100
+
96
101
  def application(application, handleActionWithIdentifier: action_identifier, forRemoteNotification: notification, completionHandler: callback)
97
102
  received_push_notification_with_action(notification, action_identifier)
98
103
  callback.call
@@ -110,5 +115,18 @@ module ProMotion
110
115
  }[symbol] || UIRemoteNotificationTypeNone
111
116
  end
112
117
 
118
+ def background_fetch_result(result)
119
+ options = {
120
+ new_data: UIBackgroundFetchResultNewData,
121
+ no_data: UIBackgroundFetchResultNoData,
122
+ failed: UIBackgroundFetchResultFailed
123
+ }
124
+ return options[result] if options[result]
125
+
126
+ return result if options.values.include?(result)
127
+
128
+ UIBackgroundFetchResultNoData
129
+ end
130
+
113
131
  end
114
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion-push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  description: Adds push notification support to ProMotion.
70
70
  email:
71
- - jamon@clearsightstudio.com
71
+ - jamon@infinite.red
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -77,7 +77,7 @@ files:
77
77
  - lib/ProMotion-push.rb
78
78
  - lib/ProMotion/delegate_notifications.rb
79
79
  - lib/ProMotion/push_notification.rb
80
- homepage: https://github.com/clearsightstudio/ProMotion-push
80
+ homepage: https://github.com/infinitered/ProMotion-push
81
81
  licenses:
82
82
  - MIT
83
83
  metadata: {}
@@ -97,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.4.5
100
+ rubygems_version: 2.5.1
101
101
  signing_key:
102
102
  specification_version: 4
103
- summary: Adds push notification support to ProMotion. Extracted from ProMotion.
103
+ summary: Adds push notification support to ProMotion.
104
104
  test_files: []