Class: Parse::Push
- Inherits:
-
Object
- Object
- Parse::Push
- Includes:
- Client::Connectable
- Defined in:
- lib/parse/model/push.rb
Overview
This class represents the API to send push notification to devices that are
available in the Installation table. Push notifications are implemented
through the Parse::Push class. To send push notifications through the
REST API, you must enable REST push enabled? option in the Push
Notification Settings section of the Settings page in your Parse
application. Push notifications targeting uses the Installation Parse
class to determine which devices receive the notification. You can provide
any query constraint, similar to using Parse::Query, in order to target
the specific set of devices you want given the columns you have configured
in your Installation class. The Parse::Push class supports many other
options not listed here.
Defined Under Namespace
Classes: AudienceNotFound, BroadcastNotAllowed
Constant Summary collapse
- SUPPORTED_PUSH_DEVICE_TYPES =
Device types that support push notifications. These are the device types that Parse Server has push adapters for.
%w[ios android osx tvos watchos web expo].freeze
- UNSUPPORTED_PUSH_DEVICE_TYPES =
Device types that are known but may not have push support configured. These will generate warnings when targeted.
%w[win other unknown unsupported].freeze
Class Attribute Summary collapse
-
.allow_broadcast ⇒ Object
Returns the value of attribute allow_broadcast.
Instance Attribute Summary collapse
- #alert ⇒ String (also: #message)
- #badge ⇒ Integer
-
#category ⇒ String
The notification category for action buttons (iOS).
-
#channels ⇒ Array
An array of strings for subscribed channels.
-
#content_available ⇒ Boolean
Whether this is a silent push (iOS content-available).
-
#data ⇒ Hash
Specific payload data.
- #expiration_interval ⇒ Integer
- #expiration_time ⇒ Parse::Date
-
#image_url ⇒ String
URL for an image attachment (requires mutable-content).
-
#localized_alerts ⇒ Hash
Language-specific alert messages (e.g., => "Hello", "fr" => "Bonjour").
-
#localized_titles ⇒ Hash
Language-specific titles (e.g., => "Welcome", "fr" => "Bienvenue").
-
#mutable_content ⇒ Boolean
Whether this notification can be modified by a service extension (iOS).
- #push_time ⇒ Parse::Date
-
#query ⇒ Object
Sending a push notification is done by performing a query against the Installation collection with a Parse::Query.
-
#sound ⇒ String
The name of the sound file.
- #title ⇒ String
Class Method Summary collapse
-
.channels ⇒ Array<String>
List all available channels from the Installation collection.
-
.send(payload) ⇒ Object
Send a push notification using a push notification hash.
-
.to_channel(channel) ⇒ Parse::Push
Create a new Push targeting a specific channel.
-
.to_channels(*channels) ⇒ Parse::Push
Create a new Push targeting multiple channels.
-
.to_installation(installation) ⇒ Parse::Push
Create a new Push targeting a specific installation.
-
.to_installation_id(installation_id) ⇒ Parse::Push
Create a new Push targeting an installation by its objectId.
-
.to_installations(*installations) ⇒ Parse::Push
Create a new Push targeting multiple installations.
-
.to_user(user) ⇒ Parse::Push
Create a new Push targeting a specific user.
-
.to_user_id(user_id) ⇒ Parse::Push
Create a new Push targeting a user by their objectId.
-
.to_users(*users) ⇒ Parse::Push
Create a new Push targeting multiple users.
Instance Method Summary collapse
-
#as_json(*args) ⇒ Hash
A JSON encoded hash.
-
#broadcast! ⇒ self
Opt this specific push in to broadcasting to every Installation.
-
#broadcast_allowed? ⇒ Boolean
True when broadcasting is allowed for this push, either via the class-level Push.allow_broadcast flag or the per-instance #broadcast! opt-in.
-
#clear_badge ⇒ self
Clear the badge (set to 0).
-
#content_available? ⇒ Boolean
Check if this push has content-available set (silent push).
-
#expires_at(time) ⇒ self
Set the expiration time for this push notification.
-
#expires_in(seconds) ⇒ self
Set the expiration interval for this push notification.
-
#increment_badge(amount = 1) ⇒ self
Increment the badge count instead of setting an absolute value.
-
#initialize(constraints = {}) ⇒ Push
constructor
Initialize a new push notification request.
-
#mutable! ⇒ self
Enable mutable-content for iOS notification service extension.
-
#mutable_content? ⇒ Boolean
Check if this push has mutable-content set (rich notifications).
-
#payload ⇒ Hash
This method takes all the parameters of the instance and creates a proper hash structure, required by Parse, in order to process the push notification.
-
#schedule(time) ⇒ self
Schedule the push notification for a future time.
-
#send(message = nil) ⇒ Object
helper method to send a message.
-
#send! ⇒ Parse::Response
Send the push notification, raising an error on failure.
-
#silent! ⇒ self
Mark this as a silent push notification (iOS content-available).
-
#to_audience(audience_name, cache: true) ⇒ self
Target a saved audience by name.
-
#to_audience_id(audience_id) ⇒ self
Target a saved audience by its object ID.
-
#to_channel(channel) ⇒ self
Target a specific channel for this push notification.
-
#to_channels(*channels) ⇒ self
Target multiple channels for this push notification.
-
#to_installation(installation) ⇒ self
Target a specific installation (or multiple installations) by object or objectId.
-
#to_installation_id(installation_id) ⇒ self
Target a specific installation by its objectId.
-
#to_installations(*installations) ⇒ self
Target multiple installations.
-
#to_json(*args) ⇒ String
A JSON encoded string.
-
#to_query {|Parse::Query| ... } ⇒ self
Configure the push query using a block.
-
#to_user(user) ⇒ self
Target installations belonging to a specific user (or multiple users).
-
#to_user_id(user_id) ⇒ self
Target installations belonging to a user by their objectId.
-
#to_users(*users) ⇒ self
Target installations belonging to multiple users.
-
#where(constraints = nil) ⇒ Hash, Parse::Query
Apply a set of constraints.
-
#where=(where_clauses) ⇒ Parse::Query
Set a hash of conditions for this push query.
-
#with_alert(message) ⇒ self
Set the alert message for this push notification.
-
#with_badge(count) ⇒ self
Set the badge number for this push notification.
-
#with_body(body) ⇒ self
Alias for #with_alert - sets the body text of the notification.
-
#with_category(category_name) ⇒ self
Set the notification category for action buttons (iOS).
-
#with_data(hash) ⇒ self
Set custom data payload for this push notification.
-
#with_image(url) ⇒ self
Add an image attachment to the push notification.
-
#with_localized_alert(lang, message) ⇒ self
Add a localized alert message for a specific language.
-
#with_localized_alerts(translations) ⇒ self
Set multiple localized alerts at once.
-
#with_localized_title(lang, title) ⇒ self
Add a localized title for a specific language.
-
#with_localized_titles(translations) ⇒ self
Set multiple localized titles at once.
-
#with_sound(sound_name) ⇒ self
Set the sound file for this push notification.
-
#with_title(title) ⇒ self
Set the title for this push notification (appears above the alert).
Methods included from Client::Connectable
Constructor Details
#initialize(constraints = {}) ⇒ Push
Initialize a new push notification request.
248 249 250 |
# File 'lib/parse/model/push.rb', line 248 def initialize(constraints = {}) self.where constraints end |
Class Attribute Details
.allow_broadcast ⇒ Object
Returns the value of attribute allow_broadcast.
99 100 101 |
# File 'lib/parse/model/push.rb', line 99 def allow_broadcast @allow_broadcast end |
Instance Attribute Details
#alert ⇒ String Also known as: message
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#badge ⇒ Integer
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#category ⇒ String
Returns the notification category for action buttons (iOS).
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#channels ⇒ Array
Returns an array of strings for subscribed channels.
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#content_available ⇒ Boolean
Returns whether this is a silent push (iOS content-available).
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#data ⇒ Hash
Returns specific payload data.
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#expiration_interval ⇒ Integer
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#image_url ⇒ String
Returns URL for an image attachment (requires mutable-content).
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#localized_alerts ⇒ Hash
Returns language-specific alert messages (e.g., => "Hello", "fr" => "Bonjour").
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#localized_titles ⇒ Hash
Returns language-specific titles (e.g., => "Welcome", "fr" => "Bienvenue").
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#mutable_content ⇒ Boolean
Returns whether this notification can be modified by a service extension (iOS).
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
#query ⇒ Object
Sending a push notification is done by performing a query against the Installation collection with a Parse::Query. This query contains the constraints that will be sent to Parse with the push payload. @return [Parse::Query] the query containing Installation constraints.
|
|
# File 'lib/parse/model/push.rb', line 112
|
#sound ⇒ String
Returns the name of the sound file.
148 |
# File 'lib/parse/model/push.rb', line 148 attr_writer :query |
Class Method Details
.channels ⇒ Array<String>
List all available channels from the Installation collection. This is a convenience method that delegates to Installation.all_channels.
188 189 190 |
# File 'lib/parse/model/push.rb', line 188 def self.channels Parse::Installation.all_channels end |
.send(payload) ⇒ Object
Send a push notification using a push notification hash
160 161 162 |
# File 'lib/parse/model/push.rb', line 160 def self.send(payload) client.push payload.as_json end |
.to_channel(channel) ⇒ Parse::Push
Create a new Push targeting a specific channel.
169 170 171 |
# File 'lib/parse/model/push.rb', line 169 def self.to_channel(channel) new.to_channel(channel) end |
.to_channels(*channels) ⇒ Parse::Push
Create a new Push targeting multiple channels.
178 179 180 |
# File 'lib/parse/model/push.rb', line 178 def self.to_channels(*channels) new.to_channels(*channels) end |
.to_installation(installation) ⇒ Parse::Push
Create a new Push targeting a specific installation.
224 225 226 |
# File 'lib/parse/model/push.rb', line 224 def self.to_installation(installation) new.to_installation(installation) end |
.to_installation_id(installation_id) ⇒ Parse::Push
Create a new Push targeting an installation by its objectId.
233 234 235 |
# File 'lib/parse/model/push.rb', line 233 def self.to_installation_id(installation_id) new.to_installation_id(installation_id) end |
.to_installations(*installations) ⇒ Parse::Push
Create a new Push targeting multiple installations.
242 243 244 |
# File 'lib/parse/model/push.rb', line 242 def self.to_installations(*installations) new.to_installations(*installations) end |
.to_user(user) ⇒ Parse::Push
Create a new Push targeting a specific user.
197 198 199 |
# File 'lib/parse/model/push.rb', line 197 def self.to_user(user) new.to_user(user) end |
.to_user_id(user_id) ⇒ Parse::Push
Create a new Push targeting a user by their objectId.
206 207 208 |
# File 'lib/parse/model/push.rb', line 206 def self.to_user_id(user_id) new.to_user_id(user_id) end |
.to_users(*users) ⇒ Parse::Push
Create a new Push targeting multiple users.
215 216 217 |
# File 'lib/parse/model/push.rb', line 215 def self.to_users(*users) new.to_users(*users) end |
Instance Method Details
#as_json(*args) ⇒ Hash
Returns a JSON encoded hash.
297 298 299 |
# File 'lib/parse/model/push.rb', line 297 def as_json(*args) payload.as_json end |
#broadcast! ⇒ self
Opt this specific push in to broadcasting to every Installation. Use when you legitimately want a global push and have not set the process-wide allow_broadcast. The explicit call site is the audit trail.
391 392 393 394 |
# File 'lib/parse/model/push.rb', line 391 def broadcast! @broadcast_allowed = true self end |
#broadcast_allowed? ⇒ Boolean
Returns true when broadcasting is allowed for this push, either via the class-level allow_broadcast flag or the per-instance #broadcast! opt-in.
399 400 401 |
# File 'lib/parse/model/push.rb', line 399 def broadcast_allowed? @broadcast_allowed == true || self.class.allow_broadcast == true end |
#clear_badge ⇒ self
Clear the badge (set to 0).
702 703 704 705 |
# File 'lib/parse/model/push.rb', line 702 def clear_badge self.badge = 0 self end |
#content_available? ⇒ Boolean
Check if this push has content-available set (silent push).
278 279 280 |
# File 'lib/parse/model/push.rb', line 278 def content_available? @content_available == true end |
#expires_at(time) ⇒ self
Set the expiration time for this push notification. The push will not be delivered after this time.
535 536 537 538 |
# File 'lib/parse/model/push.rb', line 535 def expires_at(time) self.expiration_time = time self end |
#expires_in(seconds) ⇒ self
Set the expiration interval for this push notification. The push will expire after this many seconds from now.
547 548 549 550 |
# File 'lib/parse/model/push.rb', line 547 def expires_in(seconds) self.expiration_interval = seconds.to_i self end |
#increment_badge(amount = 1) ⇒ self
Increment the badge count instead of setting an absolute value. This is useful when you want to add to the existing badge rather than replace it.
689 690 691 692 693 694 695 696 |
# File 'lib/parse/model/push.rb', line 689 def increment_badge(amount = 1) if amount == 1 self.badge = "Increment" else self.badge = { "__op" => "Increment", "amount" => amount.to_i } end self end |
#mutable! ⇒ self
Enable mutable-content for iOS notification service extension. This allows the notification to be modified by a service extension before display.
597 598 599 600 |
# File 'lib/parse/model/push.rb', line 597 def mutable! @mutable_content = true self end |
#mutable_content? ⇒ Boolean
Check if this push has mutable-content set (rich notifications).
284 285 286 |
# File 'lib/parse/model/push.rb', line 284 def mutable_content? @mutable_content == true end |
#payload ⇒ Hash
This method takes all the parameters of the instance and creates a proper hash structure, required by Parse, in order to process the push notification.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/parse/model/push.rb', line 309 def payload msg = { data: { alert: alert, badge: badge || "Increment", }, } msg[:data][:sound] = sound if sound.present? msg[:data][:title] = title if title.present? msg[:data][:"content-available"] = 1 if content_available? msg[:data][:"mutable-content"] = 1 if mutable_content? msg[:data][:category] = @category if @category.present? msg[:data][:image] = @image_url if @image_url.present? # Add localized alerts (e.g., "alert-en", "alert-fr") if @localized_alerts.is_a?(Hash) @localized_alerts.each do |lang, text| msg[:data][:"alert-#{lang}"] = text end end # Add localized titles (e.g., "title-en", "title-fr") if @localized_titles.is_a?(Hash) @localized_titles.each do |lang, text| msg[:data][:"title-#{lang}"] = text end end msg[:data].merge! @data if @data.is_a?(Hash) if @expiration_time.present? msg[:expiration_time] = @expiration_time.respond_to?(:iso8601) ? @expiration_time.iso8601(3) : @expiration_time end if @push_time.present? msg[:push_time] = @push_time.respond_to?(:iso8601) ? @push_time.iso8601(3) : @push_time end if @expiration_interval.is_a?(Numeric) msg[:expiration_interval] = @expiration_interval.to_i end if query.where.present? q = @query.dup if @channels.is_a?(Array) && @channels.empty? == false q.where :channels.in => @channels end unless q.where.empty? compiled = q.compile_rest_where # Constraints that compile to nothing would target every # installation; refuse instead of widening the audience. if compiled.empty? raise ArgumentError, "The push targeting query has constraints but compiles to no `where`, " \ "which would reach every installation. Check the targeting constraints." end msg[:where] = compiled end elsif @channels.is_a?(Array) && @channels.empty? == false msg[:channels] = @channels end msg end |
#schedule(time) ⇒ self
Schedule the push notification for a future time.
524 525 526 527 |
# File 'lib/parse/model/push.rb', line 524 def schedule(time) self.push_time = time self end |
#send(message = nil) ⇒ Object
helper method to send a message
377 378 379 380 381 382 |
# File 'lib/parse/model/push.rb', line 377 def send( = nil) @alert = if .is_a?(String) @data = if .is_a?(Hash) assert_broadcast_allowed! client.push(payload.as_json) end |
#send! ⇒ Parse::Response
Send the push notification, raising an error on failure. This is the bang version that raises Error if the push fails.
611 612 613 614 615 616 617 618 |
# File 'lib/parse/model/push.rb', line 611 def send! assert_broadcast_allowed! response = client.push(payload.as_json) if response.error? raise Parse::Error.new(response.code, response.error) end response end |
#silent! ⇒ self
Mark this as a silent push notification (iOS content-available). Silent pushes wake the app in the background without displaying an alert.
558 559 560 561 |
# File 'lib/parse/model/push.rb', line 558 def silent! @content_available = true self end |
#to_audience(audience_name, cache: true) ⇒ self
The audience must exist in the _Audience collection
Target a saved audience by name. Audiences are pre-defined in the _Audience collection and can be reused. Uses caching by default for better performance.
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/parse/model/push.rb', line 725 def to_audience(audience_name, cache: true) # Use cached audience lookup for better performance audience = Parse::Audience.find_by_name(audience_name, cache: cache) if audience.nil? raise AudienceNotFound, "Audience '#{audience_name}' not found in _Audience collection" end if audience.query_constraint.present? # Merge the audience's query constraints into our query audience.query_constraint.each do |key, value| query.where(key.to_sym => value) end end self end |
#to_audience_id(audience_id) ⇒ self
Target a saved audience by its object ID.
749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/parse/model/push.rb', line 749 def to_audience_id(audience_id) audience = Parse::Audience.find(audience_id) if audience.nil? raise AudienceNotFound, "Audience id '#{audience_id}' not found in _Audience collection" end if audience.query_constraint.present? audience.query_constraint.each do |key, value| query.where(key.to_sym => value) end end self end |
#to_channel(channel) ⇒ self
Target a specific channel for this push notification.
432 433 434 435 |
# File 'lib/parse/model/push.rb', line 432 def to_channel(channel) self.channels = [channel] self end |
#to_channels(*channels) ⇒ self
Target multiple channels for this push notification.
442 443 444 445 |
# File 'lib/parse/model/push.rb', line 442 def to_channels(*channels) self.channels = channels.flatten self end |
#to_installation(installation) ⇒ self
Target a specific installation (or multiple installations) by object or objectId. This directly targets device installation(s).
When given a Parse::Installation object, this method validates:
- The installation has a device_token (raises ArgumentError if missing)
- The device_type is supported for push (warns if unsupported)
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
# File 'lib/parse/model/push.rb', line 883 def to_installation(installation) # Delegate to to_installations if given an array return to_installations(installation) if installation.is_a?(Array) object_id = case installation when Parse::Installation validate_installation_for_push!(installation) installation.id when Hash installation[:objectId] || installation["objectId"] || installation[:id] || installation["id"] when String installation else raise ArgumentError, "Expected Parse::Installation, Hash, String, or Array, got #{installation.class}" end query.where(objectId: object_id) self end |
#to_installation_id(installation_id) ⇒ self
Target a specific installation by its objectId. This is a convenience method equivalent to to_installation with a string ID.
913 914 915 916 |
# File 'lib/parse/model/push.rb', line 913 def to_installation_id(installation_id) query.where(objectId: installation_id) self end |
#to_installations(*installations) ⇒ self
Target multiple installations. This queries the Installation collection for devices matching any of the given installation objectIds.
When given Parse::Installation objects, this method validates each:
- The installation has a device_token (raises ArgumentError if missing)
- The device_type is supported for push (warns if unsupported)
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/parse/model/push.rb', line 934 def to_installations(*installations) object_ids = installations.flatten.map do |installation| case installation when Parse::Installation validate_installation_for_push!(installation) installation.id when Hash installation[:objectId] || installation["objectId"] || installation[:id] || installation["id"] when String installation else raise ArgumentError, "Expected Parse::Installation, Hash, or String, got #{installation.class}" end end query.where(:objectId.in => object_ids) self end |
#to_json(*args) ⇒ String
Returns a JSON encoded string.
302 303 304 |
# File 'lib/parse/model/push.rb', line 302 def to_json(*args) as_json.to_json end |
#to_query {|Parse::Query| ... } ⇒ self
Configure the push query using a block. The block receives the query object for adding constraints.
453 454 455 456 |
# File 'lib/parse/model/push.rb', line 453 def to_query yield query if block_given? self end |
#to_user(user) ⇒ self
Target installations belonging to a specific user (or multiple users). This queries the Installation collection for devices where the user pointer matches the given user(s).
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
# File 'lib/parse/model/push.rb', line 789 def to_user(user) # Delegate to to_users if given an array return to_users(user) if user.is_a?(Array) pointer = case user when Parse::User user.pointer when Hash user when String Parse::Pointer.new(Parse::Model::CLASS_USER, user).to_h else raise ArgumentError, "Expected Parse::User, Hash, String, or Array, got #{user.class}" end query.where(user: pointer) self end |
#to_user_id(user_id) ⇒ self
Target installations belonging to a user by their objectId. This is a convenience method equivalent to to_user with a string ID.
818 819 820 821 822 |
# File 'lib/parse/model/push.rb', line 818 def to_user_id(user_id) pointer = Parse::Pointer.new(Parse::Model::CLASS_USER, user_id).to_h query.where(user: pointer) self end |
#to_users(*users) ⇒ self
Target installations belonging to multiple users. This queries the Installation collection for devices where the user pointer matches any of the given users.
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
# File 'lib/parse/model/push.rb', line 835 def to_users(*users) pointers = users.flatten.map do |user| case user when Parse::User user.pointer when Hash user when String Parse::Pointer.new(Parse::Model::CLASS_USER, user).to_h else raise ArgumentError, "Expected Parse::User, Hash, or String, got #{user.class}" end end query.where(:user.in => pointers) self end |
#where(constraints = nil) ⇒ Hash, Parse::Query
Apply a set of constraints.
266 267 268 269 270 |
# File 'lib/parse/model/push.rb', line 266 def where(constraints = nil) return query.compile_where unless constraints.is_a?(Hash) query.where constraints query end |
#where=(where_clauses) ⇒ Parse::Query
Set a hash of conditions for this push query.
258 259 260 |
# File 'lib/parse/model/push.rb', line 258 def where=(where_clauses) query.where where_clauses end |
#with_alert(message) ⇒ self
Set the alert message for this push notification.
463 464 465 466 |
# File 'lib/parse/model/push.rb', line 463 def with_alert() self.alert = self end |
#with_badge(count) ⇒ self
Set the badge number for this push notification.
492 493 494 495 |
# File 'lib/parse/model/push.rb', line 492 def with_badge(count) self.badge = count self end |
#with_body(body) ⇒ self
Alias for #with_alert - sets the body text of the notification.
472 473 474 |
# File 'lib/parse/model/push.rb', line 472 def with_body(body) with_alert(body) end |
#with_category(category_name) ⇒ self
Set the notification category for action buttons (iOS). Categories must be registered in the app's notification settings.
587 588 589 590 |
# File 'lib/parse/model/push.rb', line 587 def with_category(category_name) @category = category_name self end |
#with_data(hash) ⇒ self
Set custom data payload for this push notification.
512 513 514 515 516 |
# File 'lib/parse/model/push.rb', line 512 def with_data(hash) @data ||= {} @data.merge!(hash.symbolize_keys) self end |
#with_image(url) ⇒ self
Add an image attachment to the push notification. This automatically enables mutable-content for iOS service extension processing.
574 575 576 577 578 |
# File 'lib/parse/model/push.rb', line 574 def with_image(url) @image_url = url @mutable_content = true self end |
#with_localized_alert(lang, message) ⇒ self
Add a localized alert message for a specific language. Parse Server will automatically send the appropriate message based on device locale.
634 635 636 637 638 |
# File 'lib/parse/model/push.rb', line 634 def with_localized_alert(lang, ) @localized_alerts ||= {} @localized_alerts[lang.to_s] = self end |
#with_localized_alerts(translations) ⇒ self
Set multiple localized alerts at once.
661 662 663 664 665 |
# File 'lib/parse/model/push.rb', line 661 def with_localized_alerts(translations) @localized_alerts ||= {} translations.each { |lang, msg| @localized_alerts[lang.to_s] = msg } self end |
#with_localized_title(lang, title) ⇒ self
Add a localized title for a specific language. Parse Server will automatically send the appropriate title based on device locale.
650 651 652 653 654 |
# File 'lib/parse/model/push.rb', line 650 def with_localized_title(lang, title) @localized_titles ||= {} @localized_titles[lang.to_s] = title self end |
#with_localized_titles(translations) ⇒ self
Set multiple localized titles at once.
672 673 674 675 676 |
# File 'lib/parse/model/push.rb', line 672 def with_localized_titles(translations) @localized_titles ||= {} translations.each { |lang, title| @localized_titles[lang.to_s] = title } self end |
#with_sound(sound_name) ⇒ self
Set the sound file for this push notification.
502 503 504 505 |
# File 'lib/parse/model/push.rb', line 502 def with_sound(sound_name) self.sound = sound_name self end |
#with_title(title) ⇒ self
Set the title for this push notification (appears above the alert).
481 482 483 484 |
# File 'lib/parse/model/push.rb', line 481 def with_title(title) self.title = title self end |