Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Added guards in Rich push notification extension handler class (#51)
Browse files Browse the repository at this point in the history
* Updated the version to 3.2.3

Added guards in Rich push notification extension handler class

* Added guard in Rich push notification extension handler class

Added guard in Rich push notification extension handler class

* Added guards in Rich push notification extension handler class

Added guards in Rich push notification extension handler class
  • Loading branch information
AnanthaKrish committed May 22, 2017
1 parent 1e9faf2 commit 9c130b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion BMSPush.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

s.name = 'BMSPush'

s.version = '3.2.2'
s.version = '3.2.3'

s.summary = 'Swift client side Push SDK for IBM Bluemix Push notifications services'
s.homepage = 'https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-swift-push'
Expand Down
41 changes: 23 additions & 18 deletions Source/BMSRichPushNotificationOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,30 @@ open class BMSPushRichPushNotificationOptions:UNNotificationServiceExtension {
var bestAttemptContent: UNMutableNotificationContent?
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

let urlString = request.content.userInfo["attachment-url"] as? String
if let fileUrl = URL(string: urlString! ) {
// Download the attachment
URLSession.shared.downloadTask(with: fileUrl) { (location, response, error) in
if let location = location {
// Move temporary file to remove .tmp extension
let tmpDirectory = NSTemporaryDirectory()
let tmpFile = "file://".appending(tmpDirectory).appending(fileUrl.lastPathComponent)
let tmpUrl = URL(string: tmpFile)!
try! FileManager.default.moveItem(at: location, to: tmpUrl)

// Add the attachment to the notification content
if let attachment = try? UNNotificationAttachment(identifier: "video", url: tmpUrl, options:nil) {
bestAttemptContent?.attachments = [attachment]
if let urlString = request.content.userInfo["attachment-url"] as? String, urlString != "" {

if let fileUrl = URL(string: urlString ) {
// Download the attachment
URLSession.shared.downloadTask(with: fileUrl) { (location, response, error) in
if let location = location {
// Move temporary file to remove .tmp extension
let tmpDirectory = NSTemporaryDirectory()
let tmpFile = "file://".appending(tmpDirectory).appending(fileUrl.lastPathComponent)
let tmpUrl = URL(string: tmpFile)!
try! FileManager.default.moveItem(at: location, to: tmpUrl)

// Add the attachment to the notification content
if let attachment = try? UNNotificationAttachment(identifier: "video", url: tmpUrl, options:nil) {
bestAttemptContent?.attachments = [attachment]
}
}
}
// Serve the notification content
contentHandler(bestAttemptContent!)
}.resume()
// Serve the notification content
contentHandler(bestAttemptContent!)
}.resume()
}

}else{
contentHandler(bestAttemptContent!)
}
}
}
Expand Down

0 comments on commit 9c130b8

Please sign in to comment.