Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20072] iOS: Ti.Media.saveToPhotoGallery does not call back for unsupported mime types

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-11-30T02:30:24.000+0000
Affected Version/sRelease 5.1.1
Fix Version/sRelease 5.2.0
ComponentsiOS
Labelsn/a
ReporterFokke Zandbergen
AssigneeHans Knöchel
Created2015-11-28T06:45:46.000+0000
Updated2016-01-15T16:34:34.000+0000

Description

If you pass a File or Blob of unsupported extension/mimeType to Ti.Media.saveToPhotoGallery() neither of the [two callbacks](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-method-saveToPhotoGallery) is called and no error is logged. This is because [the code](https://github.com/appcelerator/titanium_mobile/blob/55f45d09fd30d63e7218954658a35e86335bf29d/iphone/Classes/MediaModule.m#L776-L838) only calls the error callback when it is passed no File or Blob and not when the File or Blob is of unsupported extension/format. *Steps* 1. Create a default project (that has KS_nav_ui.png in Resources). 2. Run with the sample code and confirm it works. 3. Switch the two var file lines. 4. Run again and confirm neither success nor error is called back and no error is showing in logs either.
var win = Ti.UI.createWindow({  
    backgroundColor: '#fff'
});

var btn = Ti.UI.createButton({
	title: 'Click Me'
});

btn.addEventListener('click', function() {
	var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'KS_nav_ui.png');
	// var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'app.js');

	if (!file.exists()) {
		alert('File does not exist');
		return;
	}

	Ti.Media.saveToPhotoGallery(file.read(), {
		success: function(e) {
			alert('Success: ' + JSON.stringify(e));
		},
		error: function(e) {
			alert('Error: ' + JSON.stringify(e));
		}
	});
});

win.add(btn);
win.open();

Comments

  1. Hans Knöchel 2015-11-30

    Added the else-case of the mime check, corrected the miss-spelling in the error messages. PR: https://github.com/appcelerator/titanium_mobile/pull/7510 Demo: See demo code above Screen: http://abload.de/img/simulatorscreenshot29ujsza.png
  2. Chee Kiat Ng 2015-11-30

    CR and FT passed. PR Merged.
  3. Fokke Zandbergen 2015-11-30

    Thanks for the quick fix [~hansknoechel]. I noticed one more _invalid mimeType else_ missing after [line 849](https://github.com/hansemannn/titanium_mobile/blob/3258a9c9634420c3ff3f0ba32d2c8885cc44fa10/iphone/Classes/MediaModule.m#L846-L849).
  4. Eric Wieber 2016-01-15

    Verified fixed, using: MacOS 10.11.2 (15C50) Studio 4.4.0.201511241829 Ti SDK 5.2.0.v20160114021251 Appc NPM 4.2.2 Appc CLI 5.2.0-224 Xcode 7.2 (7C68) Node v0.12.7 Java 1.7.0_80 Error messages now appear for unsupported mime types in saveToPhotoGallery(). Used a modified version of the supplied test case to include more blobs and file types/extensions.

JSON Source