You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
iOS delegate implementation causes TypeError: Attempted to assign to readonly property. #70
Ok found that the consistent thing between these two files is that they both have delegates. Commenting out the delegates in the files results in it working.
I then moved the delegates out to their own files, but now the error is back. Any ideas on how to get this working?
Delegate code:
import { SpotAssetContainer, SpotAssetDownloadTask, SpotAssetDownloadTaskStatus } from "../models/asset-manager.models"
export class AVAssetDownloadDelegateImpl extends NSObject implements AVAssetDownloadDelegate {
wrapper;
public static ObjCProtocols = [AVAssetDownloadDelegate] // define our native protocols
static new(): AVAssetDownloadDelegateImpl {
return <AVAssetDownloadDelegateImpl>super.new() // calls new() on the NSObject
}
URLSessionAssetDownloadTaskDidFinishDownloadingToURL(session: NSURLSession, assetDownloadTask: AVAssetDownloadTask, location: NSURL): void {
console.log("downloadComplete");
let _assetDownloadTask: SpotAssetDownloadTask = this.wrapper.assetDownloadTasks.find(a => a.assetId === assetDownloadTask.taskDescription);
if (_assetDownloadTask) {
console.log("Asset download complete: " + _assetDownloadTask.assetId);
_assetDownloadTask.status = SpotAssetDownloadTaskStatus.completed;
this.wrapper.assetsDownloading -= 1;
_assetDownloadTask.downloadFinishTime = Date.now();
this.wrapper.calculateFileDownloadSpeed(location.relativePath, _assetDownloadTask);
}
}
URLSessionAssetDownloadTaskDidLoadTimeRangeTotalTimeRangesLoadedTimeRangeExpectedToLoad?(session: NSURLSession, assetDownloadTask: AVAssetDownloadTask, timeRange: CMTimeRange, loadedTimeRanges: NSArray<NSValue>, timeRangeExpectedToLoad: CMTimeRange): void {
let _asset: SpotAssetContainer = this.wrapper.assets.find(a => a.asset.id === assetDownloadTask.taskDescription);
if (_asset) {
let loadedSeconds = CMTimeGetSeconds(CMTimeRangeGetEnd(timeRange));
console.log("loadedSeconds " + loadedSeconds);
if (loadedSeconds >= 10) {
console.log("stopping download now that it is over 10 seconds");
assetDownloadTask.cancel();
}
}
}
}
Bundle delegate code:
/* 633 */
/* exports provided: AVAssetDownloadDelegateImpl */
/* exports used: AVAssetDownloadDelegateImpl */
/*!************************************************!*\
!*** ./delegates/avasset-download-delegate.ts ***!
\************************************************/
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__models_asset_manager_models__ = __webpack_require__(/*! ../models/asset-manager.models */ 169);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return AVAssetDownloadDelegateImpl; });
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var AVAssetDownloadDelegateImpl = (function (_super) {
__extends(AVAssetDownloadDelegateImpl, _super);
function AVAssetDownloadDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
AVAssetDownloadDelegateImpl.new = function () {
return _super.new.call(this); // calls new() on the NSObject
};
AVAssetDownloadDelegateImpl.prototype.URLSessionAssetDownloadTaskDidFinishDownloadingToURL = function (session, assetDownloadTask, location) {
console.log("downloadComplete");
var _assetDownloadTask = this.wrapper.assetDownloadTasks.find(function (a) { return a.assetId === assetDownloadTask.taskDescription; });
if (_assetDownloadTask) {
console.log("Asset download complete: " + _assetDownloadTask.assetId);
_assetDownloadTask.status = __WEBPACK_IMPORTED_MODULE_0__models_asset_manager_models__["b" /* SpotAssetDownloadTaskStatus */].completed;
this.wrapper.assetsDownloading -= 1;
_assetDownloadTask.downloadFinishTime = Date.now();
this.wrapper.calculateFileDownloadSpeed(location.relativePath, _assetDownloadTask);
}
};
AVAssetDownloadDelegateImpl.prototype.URLSessionAssetDownloadTaskDidLoadTimeRangeTotalTimeRangesLoadedTimeRangeExpectedToLoad = function (session, assetDownloadTask, timeRange, loadedTimeRanges, timeRangeExpectedToLoad) {
var _asset = this.wrapper.assets.find(function (a) { return a.asset.id === assetDownloadTask.taskDescription; });
if (_asset) {
var loadedSeconds = CMTimeGetSeconds(CMTimeRangeGetEnd(timeRange));
console.log("loadedSeconds " + loadedSeconds);
if (loadedSeconds >= 10) {
console.log("stopping download now that it is over 10 seconds");
assetDownloadTask.cancel();
}
}
};
return AVAssetDownloadDelegateImpl;
}(NSObject));
AVAssetDownloadDelegateImpl.ObjCProtocols = [AVAssetDownloadDelegate]; // define our native protocols
//# sourceMappingURL=avasset-download-delegate.js.map
/***/ }),
changed the title [-]TypeError: Attempted to assign to readonly property.[/-][+]iOS delegate implementation causes TypeError: Attempted to assign to readonly property.[/+]on Feb 9, 2017
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
Add a "noEmitHelpers": true to your tsconfig.json and your tsconfig.aot.json file.
Reacted by bnussey, Jon Zgoda, nabeel.a, Rezon Jovian, Manoj and Eddy Verbruggen
I am seeing the exact same issue that @bnussey was seeing with the UIApplicationDelegate. I added the "noEmitHelpers": true that @NathanaelA suggested but I am still getting a segmentation fault on app launch but for a different reason.
@danielgek One of my teammates figured it out. We did not use the "noEmitHelpers": true as that caused more problems for us. These links talked about the issue: #8 and http://fluentreports.com/blog/?p=342.
In the second link at the end of the post, there is info on the crashing on startup. We used the eliminateExtends method.
/**********************************************************************************
* (c) 2016, Master Technology
* Licensed under the MIT license or contact me for a Support or Commercial License
*
* I do contract work in most languages, so let me solve your problems!
*
* Any questions please feel free to email me
* Version 1.0.2 Nathan@master-technology.com
*********************************************************************************/
"use strict";
function eliminateExtends(pre) {
var i = pre.indexOf('var __extends = ');
if (i === -1) {
return pre;
}
var x = pre.indexOf('};',i);
return pre.substring(0,i) + pre.substring(x+2);
}
module.exports = eliminateExtends;
We then updated our webpack.config.js by adding a resolveLoader:
The issue reappeared by itself after we migrated to Webpack 4 / nativescript-dev-webpack 0.15.1
For some strange reason, the .js file that implements the eliminate-extends was automatically deleted from the file system after the webpack.config.js was updated. Not sure if this is by design, but maybe the webpack config update script does this.
After manual recreation of the .js file and adjustment of the webpack.config.js it works again.
IMHO the root issue (iOS delegate implementation causes TypeError) is still a bug.
@lambourn can you please elaborate on how you implement @slmolloy 's solution? i've created the eliminateExtends.js file on my app root folder, then added resolve(__dirname, "webpack-loader") to my webpack config file (do I need to install something to make it work?) and finally added this to the .ts rule:
In my case, the webpack.config.js is based on the default config for NativeScript-Angular projects. The elimiate-extends.js is stored in a ./lib folder in the root of the project.
Activity
bnussey commentedon Feb 9, 2017
Ok so if I comment out the code that resulted in the above code from
bundle.jsI get the same error from another bit of my project code..bnussey commentedon Feb 9, 2017
Ok found that the consistent thing between these two files is that they both have delegates. Commenting out the delegates in the files results in it working.
I then moved the delegates out to their own files, but now the error is back. Any ideas on how to get this working?
Delegate code:
Bundle delegate code:
[-]TypeError: Attempted to assign to readonly property.[/-][+]iOS delegate implementation causes TypeError: Attempted to assign to readonly property.[/+]hdeshev commentedon Feb 9, 2017
@bnussey could you post a sample project on GitHub, so I can reproduce the error?
bnussey commentedon Feb 9, 2017
Hey @hdeshev all you need to do is add a delegate like I have above and bundle and then try and run. I used this as a reference - https://docs.nativescript.org/runtimes/ios/how-to/ObjC-Subclassing.html#typescript-delegate-example
bnussey commentedon Feb 9, 2017
I have two different delegates and they both cause the error
bnussey commentedon Feb 10, 2017
If you'd like to replicate this on your side, use the following code:
NathanaelA commentedon Feb 10, 2017
This is caused by the emitting of the helpers.
Add a
"noEmitHelpers": trueto your tsconfig.json and your tsconfig.aot.json file.bnussey commentedon Feb 10, 2017
This has fixed it, thank you @NathanaelA
slmolloy commentedon Aug 29, 2017
I am seeing the exact same issue that @bnussey was seeing with the
UIApplicationDelegate. I added the"noEmitHelpers": truethat @NathanaelA suggested but I am still getting a segmentation fault on app launch but for a different reason.The code in the
bundle.jsis:bnussey commentedon Aug 29, 2017
Hi @slmolloy did you do it in your
tsconfig.aot.jsonor just yourtsconfig.json?slmolloy commentedon Aug 29, 2017
My
tsconfig.aot.jsonextendstsconfig.json. I tried in each one independently as well as both. Each attempt resulted in the same error.danielgek commentedon Sep 1, 2017
@slmolloy any luck on this ? having the same issue and i'm getting crazy with tsconfigs
slmolloy commentedon Sep 3, 2017
@danielgek One of my teammates figured it out. We did not use the
"noEmitHelpers": trueas that caused more problems for us. These links talked about the issue: #8 and http://fluentreports.com/blog/?p=342.In the second link at the end of the post, there is info on the crashing on startup. We used the
eliminateExtendsmethod.We then updated our
webpack.config.jsby adding aresolveLoader:And added
eliminate-extendsto the.tsrule:lambourn commentedon Aug 15, 2018
Note to future readers:
we had the same issue a while back and @slmolloy 's comment above did fix the issue.
The issue reappeared by itself after we migrated to Webpack 4 / nativescript-dev-webpack 0.15.1
For some strange reason, the .js file that implements the eliminate-extends was automatically deleted from the file system after the webpack.config.js was updated. Not sure if this is by design, but maybe the webpack config update script does this.
After manual recreation of the .js file and adjustment of the webpack.config.js it works again.
IMHO the root issue (iOS delegate implementation causes TypeError) is still a bug.
miguelopezv commentedon Sep 12, 2018
@lambourn can you please elaborate on how you implement @slmolloy 's solution? i've created the
eliminateExtends.jsfile on my app root folder, then addedresolve(__dirname, "webpack-loader")to my webpack config file (do I need to install something to make it work?) and finally added this to the .ts rule:but al iget is that it can't resolve the file:
ERROR in Entry module not found: Error: Can't resolve 'eliminateExtends' in '/Volumes/Users/.../app'lambourn commentedon Sep 17, 2018
@miguelopezv sure.
In my case, the
webpack.config.jsis based on the default config for NativeScript-Angular projects. Theelimiate-extends.jsis stored in a./libfolder in the root of the project.In the
webpack.config.jsI addedto ensure it gets found.
Then in the
module.rulesit is added to the test for.tsfiles:lambourn commentedon Mar 13, 2019
fyi - this issue still exists with {N} 5.2 and nativescript-dev-webpack 0.20.2