Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5081] iOS: 6.1.1 GA / removeEventListener under addEventListener without error?

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2017-07-19T18:50:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterMaxim Khrichtchatyi
AssigneeShak Hossain
Created2017-07-12T17:51:54.000+0000
Updated2017-07-19T18:50:56.000+0000

Description

Titanium SDK 6.1.0 GA – the below code works successfully Titanium SDK 6.1.1 GA – Error
[ERROR] :      message = "Invalid type passed to function";
[ERROR] :      nativeLocation = "-[TiProxy addEventListener:] (TiProxy.m:838)";
[ERROR] :      nativeReason = "expected: Function, was: String";
Help to fix the bug and correct me if I did something wrong.
    var avatar = {
	    RemoteImage: function(a) {
			a = a || {};

			var md5;
			var needsToSave = false;
			var savedFile;

			if (a.image) {
				md5 = Ti.Utils.md5HexDigest(a.image) + '.png';
				savedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, md5);

				if (savedFile.exists()) {
					a.image = savedFile;
				}
				else {
					needsToSave = true;
				}
			}

			if (needsToSave == true) {
				var image = Ti.UI.createImageView(a);

				function saveImage(e) {
					image.removeEventListener('load', saveImage);
					savedFile.write(
						image.toImage(null, true)
					);
				};

				image.addEventListener('load', saveImage);

				function defaultAvatar(e) {
					image.setImage(a.data_user_avatar_default);
					image.removeEventListener('error', defaultAvatar);
				};

				image.addEventListener('error', defaultAvatar);
			}
			else {
				var image = Ti.UI.createImageView(a);
			}

			return image;
		}
	};

        var profileAvatar = avatar.RemoteImage({
		image: 'https://www.gravatar.com/avatar/image.png',
	        data_user_avatar_default: 'https://www.gravatar.com/avatar/md5.png',
		defaultImage: '/img/avatar_preload.png',
		width: 60,
		height: 60
	});

Comments

  1. Sharif AbuDarda 2017-07-14

    Hello, please share a full reproducible test code.

JSON Source