Skip to content

Commit

Permalink
fix(ios): implement Ti.Blob binary toString natively
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Jan 13, 2021
1 parent a66bf79 commit ce900a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions common/Resources/ti.internal/extensions/ti/ti.blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@
/* globals OS_IOS, OS_VERSION_MAJOR */
const buffer = Ti.createBuffer({ value: '' });
const blob = buffer.toBlob();

if (OS_IOS) {
blob.constructor.prototype.toString = function () {
const value = this.text;
return (value === undefined) ? '[object TiBlob]' : value;
};

if (OS_VERSION_MAJOR < 11) {
// This is hack to fix TIMOB-27707. Remove it after minimum target set iOS 11+
setTimeout(function () {}, Infinity);
}
}

const BlobPrototype = Object.getPrototypeOf(blob);
// Web Blob has an arrayBuffer() method that returns a Promise
// https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
blob.constructor.prototype.arrayBuffer = function () {
BlobPrototype.arrayBuffer = function () {
return new Promise((resolve, reject) => {
let buf;
try {
Expand All @@ -33,3 +21,17 @@ blob.constructor.prototype.arrayBuffer = function () {
resolve(buf);
});
};

if (OS_IOS) {
if (OS_VERSION_MAJOR < 13) {
BlobPrototype.toString = function () {
const value = this.text;
return (value === undefined) ? '[object TiBlob]' : value;
};
}

if (OS_VERSION_MAJOR < 11) {
// This is hack to fix TIMOB-27707. Remove it after minimum target set iOS 11+
setTimeout(function () {}, Infinity);
}
}
2 changes: 1 addition & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ - (NSString *)toString
if (t != nil) {
return t;
}
return [super toString];
return @"[object TiBlob]";
}

static void jsArrayBufferFreeDeallocator(void *data, void *ctx)
Expand Down

0 comments on commit ce900a7

Please sign in to comment.