Skip to content

Commit

Permalink
Stop stripping out the "default" sound from APNS objects, because sen…
Browse files Browse the repository at this point in the history
…ding that

is Apple's recommended way of requesting the default notification sound. If
you omit it, then no sound at all is played.
  • Loading branch information
brunchboy committed Sep 25, 2012
1 parent 30efe2d commit c0cfa27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/herolabs/apns/message.clj
Expand Up @@ -4,11 +4,7 @@
(defn with-badge [message number] (assoc-in message [:aps :badge ] number)) (defn with-badge [message number] (assoc-in message [:aps :badge ] number))


(defn with-sound [message sound] (defn with-sound [message sound]
(cond (assoc-in message [:aps :sound ] (name sound))
(= :default sound) (update-in message [:aps ] #(dissoc % :sound ))
(= "default" sound) (update-in message [:aps ] #(dissoc % :sound ))
:else (assoc-in message [:aps :sound ] sound)
)
) )


(defn with-standard-alert [message body] (defn with-standard-alert [message body]
Expand Down Expand Up @@ -44,4 +40,5 @@
(if key (if key
(assoc-in message [:aps :alert :body ] body) (assoc-in message [:aps :alert :body ] body)
message) message)
) )

6 changes: 3 additions & 3 deletions test/herolabs_test/apns/message.clj
Expand Up @@ -7,9 +7,9 @@


(facts "about message assembly" (facts "about message assembly"
(with-badge {} 1) => (just {:aps {:badge 1}}) (with-badge {} 1) => (just {:aps {:badge 1}})
(with-sound {} :default) => (just {:aps nil}) (with-sound {} :default) => (just {:aps {:sound "default"}})
(with-sound {} "default") => (just {:aps nil}) (with-sound {} "default") => (just {:aps {:sound "default"}})
(with-sound {} :chimes) => (just {:aps {:sound :chimes}}) (with-sound {} :chimes) => (just {:aps {:sound "chimes"}})
(with-standard-alert {} "Hello world") => (just {:aps {:alert "Hello world"}}) (with-standard-alert {} "Hello world") => (just {:aps {:alert "Hello world"}})
(with-action-loc-key {} "TEST") => (just {:aps {:alert {:action-loc-key "TEST"}}}) (with-action-loc-key {} "TEST") => (just {:aps {:alert {:action-loc-key "TEST"}}})
(with-loc-key {} "TEST") => (just {:aps {:alert {:loc-key "TEST"}}}) (with-loc-key {} "TEST") => (just {:aps {:alert {:loc-key "TEST"}}})
Expand Down

0 comments on commit c0cfa27

Please sign in to comment.