Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5234] iOS 11: Ti.Media.saveToPhotoGallery is broken and causes app to crash

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2017-10-20T21:54:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterDavid Fox
AssigneeShak Hossain
Created2017-09-26T03:16:54.000+0000
Updated2018-08-14T06:45:46.000+0000

Description

Any call to Ti.Media.saveToPhotoGallery on iOS 11 with any Titanium SDK causes the app to crash with no error or messaging in the console. The permission dialog is never shown. Same code with iOS 10.1 works fine.

Comments

  1. Hans Knöchel 2017-09-26

  2. David Fox 2017-09-26

    Hi Hans, Thanks a bunch for the info, that was the issue and adding that permission fixed it! Glad to see that PR, that will definitely be helpful. I'm not sure if it's in the documentation anywhere but I didn't see anything off hand - it might be helpful to add what you wrote here maybe. Thanks again.
  3. Muhammad Sabir 2018-03-20

    @Hans Knochel Is there any method to check/request that permission like Ti.Media.has***** and Ti.Media.request**** ??? Currently the code for save to gallery is executed before the permissions popup by iOS.
  4. Marian Kucharcik 2018-08-13

    This code works for me(iOS 11.4.1, iPX):
       saveToPhotoGalleryButton.addEventListener("click", function()
       {
       	var image = takenPhotoImageView.toImage(function(e)
       	{
       		if(Ti.Media.hasPhotoGalleryPermissions)
       		{
       			Ti.Media.saveToPhotoGallery(image, 
       			{
       				success:function(e)
       				{
       					alert("Image saved");
       				},
       				error:function(e)
       				{
       					alert("Image not saved: "+e.error);
       				}
       			});
       		}
       		else
       		{
       			Ti.Media.requestPhotoGalleryPermissions();
       		}
       	}, true);
       	
       });
       
    If there is no permissions granted, I request them. in tiapp.xml you have to add this:
       <key>NSPhotoLibraryAddUsageDescription</key>
       <string>App wants to save photos to gallery</string>
       
    Hans or somebody from appc, can you please modify docs and put this info there? Because there is no single word about missing key and permissions... Thanks
  5. Hans Knöchel 2018-08-14

    Thanks for the feedback [~max87]. Note that it is hasPhotoGalleryPermissions() not hasPhotoGalleryPermissions. The latter one will always be true, because the function itself always exists (which is what you are checking).
  6. Marian Kucharcik 2018-08-14

    Yeah, you're right and I'm sorry, it's a typo(I can't edit my previous comment to correct it)
  7. Hans Knöchel 2018-08-14

    PR to update the docs: https://github.com/appcelerator/titanium_mobile/pull/10252

JSON Source