Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ response.body # => ""
connection.close
```

#### Voice Over IP (voip) notifications

If you are building an iOS VoIP App, you can deliver Pushkit voip notifications by overriding `custom_headers` attribute for `apns-push-type`

```ruby
require 'apnotic'

# create a persistent connection
connection = Apnotic::Connection.new(cert_path: 'apns_certificate.pem',
cert_pass: 'pass')

# create a notification for a specific device token
token = '6c267f26b173cd9595ae2f6702b1ab560371a60e7c8a9e27419bd0fa4a42e58f'

notification = Apnotic::Notification.new(token)
notification.custom_headers = {
'apns-push-type' => 'voip'
}

# send (this is a blocking call)
response = connection.push(notification)

# read the response
response.ok? # => true
response.status # => '200'
response.headers # => {":status"=>"200", "apns-id"=>"6f2cd350-bfad-4af0-a8bc-0d501e9e1799"}
response.body # => ""

# close the connection
connection.close
```

#### Token-based authentication
Token-based authentication is supported. There are several advantages with token-based auth:

Expand Down
4 changes: 3 additions & 1 deletion lib/apnotic/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
module Apnotic

class Notification < AbstractNotification
attr_accessor :alert, :badge, :sound, :content_available, :category, :custom_payload, :url_args, :mutable_content, :thread_id
attr_accessor :alert, :badge, :sound, :content_available, :category,
:custom_payload, :url_args, :mutable_content, :thread_id,
:custom_headers

def background_notification?
aps.count == 1 && aps.key?('content-available') && aps['content-available'] == 1
Expand Down
1 change: 1 addition & 0 deletions lib/apnotic/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def build_headers_for(notification)
h.merge!('apns-topic' => notification.topic) if notification.topic
h.merge!('apns-collapse-id' => notification.apns_collapse_id) if notification.apns_collapse_id
h.merge!('authorization' => notification.authorization_header) if notification.authorization_header
h.merge! notification.custom_headers if notification.custom_headers
h
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/apnotic/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,24 @@ def build_headers
}
) }
end

context 'when it''s a voip notification' do
before do
notification.custom_headers = {
'apns-push-type' => 'voip'
}
end

it do
is_expected.to eq(
'apns-id' => 'apns-id',
'apns-expiration' => '1461491082',
'apns-priority' => '10',
'apns-push-type' => 'voip',
'apns-topic' => 'com.example.myapp',
'apns-collapse-id' => 'collapse-id'
)
end
end
end
end