Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Milind Keni committed Jan 8, 2025
2 parents 297229a + 948b8fa commit 0b69a9b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/WEContentExtension/Common/WEConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct WEConstants{
static let WENOTIFICATIONGROUP = "WEGNotificationGroup"
static let WEBENGAGE = "webengage"
static let WEX_APP_GROUP = "WEX_APP_GROUP"
static let WEX_CONTENT_EXTENSION_VERSION = "1.1.2"
static let WEX_CONTENT_EXTENSION_VERSION = "1.1.3"
static let WEX_CONTENT_EXTENSION_VERSION_STRING = "WEContentExtension_version"
static let WHITECOLOR = "#FFFFFF"
}
31 changes: 31 additions & 0 deletions Sources/WEContentExtension/Layouts/Carousel/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ extension WEXCarouselPushNotificationViewController{
}
}

func downloadRemaining(forPositions positions: [Int]) {
for i in positions {
DispatchQueue.global(qos: .userInitiated).async {
if let carouselItem = self.carouselItems[i] as? [String: Any],
let imageURL = carouselItem[WEConstants.IMAGE] as? String,
let imageUrl = URL(string: imageURL) {

// Asynchronously download the image
if let imageData = try? Data(contentsOf: imageUrl),
let image = UIImage(data: imageData) {
DispatchQueue.main.async {
self.images[i] = image
self.wasLoaded[i] = true
}
} else {
DispatchQueue.main.async {
self.images[i] = self.getErrorImage()!
self.wasLoaded[i] = false
}
}
} else {
DispatchQueue.main.async {
self.images[i] = self.getErrorImage()!
self.wasLoaded[i] = false
}
}
}
}
}


func getActivityDictionaryForCurrentNotification() -> [String: Any]? {
if let viewController = self.viewController {
return viewController.getActivityDictionaryForCurrentNotification() as? [String : Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class WEXCarouselPushNotificationViewController: WEXRichPushLayout {
firstImageAdded = true
}
}

var listOfPositionsToDownload: [Int] = []
for i in (firstImageAdded ? 1 : 0)..<items.count {
wasLoaded.append(false)

if i < downloadedCount {
if i <= downloadedCount {
if #available(iOS 10.0, *) {
if let attachmentValue = notification.request.content.attachments.first(where: { $0.identifier == "\(i)" }) {
if attachmentValue.url.startAccessingSecurityScopedResource() {
if let imageData = try? Data(contentsOf: attachmentValue.url), let image = UIImage.animatedImageWithAnimatedGIF(data: imageData) {
if let imageData = try? Data(contentsOf: attachmentValue.url), let image = loadImageFromData(data: imageData) {
images.append(image)
wasLoaded[i] = true
if i == 0 {
Expand All @@ -99,21 +99,26 @@ class WEXCarouselPushNotificationViewController: WEXRichPushLayout {
attachmentValue.url.stopAccessingSecurityScopedResource()
} else {
images.append(getErrorImage()!)
listOfPositionsToDownload.append(i)
wasLoaded[i] = true
}
}
}else{
images.append(getErrorImage()!)
}
} else {
print("Expected to be running iOS version 10 or above")
}
} else {
images.append(getLoadingImage()!)
listOfPositionsToDownload.append(i)
}
}
initialiseCarouselForNotification(notification)


if downloadedCount < items.count {
downloadRemaining(from: downloadedCount)
if listOfPositionsToDownload.count > 0 {
downloadRemaining(forPositions: listOfPositionsToDownload)
}
}
}
Expand Down Expand Up @@ -319,5 +324,38 @@ class WEXCarouselPushNotificationViewController: WEXRichPushLayout {
let x = currentViewX + Float(frameLocation.rawValue) * interViewMargins + Float(frameLocation.rawValue) * viewWidth
return CGRect(x: CGFloat(x), y: CGFloat(currentViewY), width: CGFloat(viewWidth), height: CGFloat(viewHeight))
}


func checkImageType(data: Data) -> String? {
let gifMagicNumbers: [UInt8] = [0x47, 0x49, 0x46] // "GIF" in ASCII
let jpgMagicNumbers: [UInt8] = [0xFF, 0xD8, 0xFF] // JPEG header
let pngMagicNumbers: [UInt8] = [0x89, 0x50, 0x4E, 0x47] // PNG header

if data.starts(with: gifMagicNumbers) {
return "GIF"
} else if data.starts(with: jpgMagicNumbers) {
return "JPEG"
} else if data.starts(with: pngMagicNumbers) {
return "PNG"
}
return nil // Unknown or unsupported format
}

func loadImageFromData(data: Data) -> UIImage? {
guard let type = checkImageType(data: data) else {
print("Unsupported or unknown image type")
return nil
}

switch type {
case "GIF":
return UIImage.animatedImageWithAnimatedGIF(data: data)
case "JPEG", "PNG":
return UIImage(data: data)
default:
return nil
}
}


}
2 changes: 1 addition & 1 deletion WEContentExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'WEContentExtension'
s.version = '1.1.2'
s.version = '1.1.3'
s.summary = 'Extension Target SDK for adding WebEngage Rich Push Notifications support'

s.description = <<-DESC
Expand Down

0 comments on commit 0b69a9b

Please sign in to comment.