Skip to content

Commit

Permalink
[Fix] base 64 mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgchgli0718 committed Jan 14, 2024
1 parent 918495d commit 8c6c34e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ ZNSTextAttachment enables NSTextAttachment to download images from remote URLs,
```
File > Swift Packages > Add Package Dependency
Add https://github.com/ZhgChgLi/ZNSTextAttachment.git
Select "Up to Next Major" with "1.1.8"
Select "Up to Next Major" with "1.1.9"
```
or
```swift
...
dependencies: [
.package(url: "https://github.com/ZhgChgLi/ZNSTextAttachment.git", from: "1.1.8"),
.package(url: "https://github.com/ZhgChgLi/ZNSTextAttachment.git", from: "1.1.9"),
]
...
.target(
Expand All @@ -35,7 +35,7 @@ platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
pod 'ZNSTextAttachment', '~> 1.1.8'
pod 'ZNSTextAttachment', '~> 1.1.9'
end
```

Expand Down
6 changes: 3 additions & 3 deletions Sources/ZNSTextAttachment/ZNSTextAttachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public class ZNSTextAttachment: NSTextAttachment {
let firstMatch = regex.firstMatch(in: imageURL.absoluteString, options: [], range: NSRange(location: 0, length: imageURL.absoluteString.count)),
firstMatch.range(at: 1).location != NSNotFound,
firstMatch.range(at: 2).location != NSNotFound,
let mimeTypeRange = Range(firstMatch.range(at: 1), in: imageURL.absoluteString),
let typeRange = Range(firstMatch.range(at: 1), in: imageURL.absoluteString),
let base64StringRange = Range(firstMatch.range(at: 2), in: imageURL.absoluteString),
let base64Data = Data(base64Encoded: String(imageURL.absoluteString[base64StringRange]), options: .ignoreUnknownCharacters) {

let mimeType = String(imageURL.absoluteString[mimeTypeRange])
self.dataDownloaded(base64Data, mimeType: mimeType)
let type = String(imageURL.absoluteString[typeRange])
self.dataDownloaded(base64Data, mimeType: "image/"+type)

} else {
let urlSessionDataTask = URLSession.shared.dataTask(with: imageURL) { (data, response, error) in
Expand Down
2 changes: 1 addition & 1 deletion scripts/ZNSTextAttachment.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ZNSTextAttachment"
s.version = "1.1.8"
s.version = "1.1.9"
s.summary = "ZNSTextAttachment enables NSTextAttachment to download images from remote URLs."
s.homepage = "https://github.com/ZhgChgLi/ZNSTextAttachment"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down

0 comments on commit 8c6c34e

Please sign in to comment.