Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-6036

iOS: image placed in the applicationDataDirectory is removed if used as an attachment in a scheduleLocalNotification

    Details

      Description

      I'm trying to attach an image, placed in the Ti.Filesystem.applicationDataDirectory, to a local notification.
      But as soon as I do the Ti.App.iOS.scheduleLocalNotification(), the image is removed from the Ti.Filesystem.applicationDataDirectory

      Example: first click on "Capture screen", and then on "Shedule notification"

      var win = Ti.UI.createWindow({
      	backgroundColor : "yellow",
      	layout : "vertical"
      });
       
      var imageView =  Ti.UI.createImageView({
      	top : 50,
      	width : 200,
      	height : 200,
      	backgroundColor : "white",
      	borderWidth : 5,
      	borderColor : "white"
      });
       
      var captureScreenBtn = Ti.UI.createButton({
      	top : 20,
      	title : "Capture screen",
      	width : Ti.UI.SIZE,
      	height : Ti.UI.SIZE
      });
       
      var notificationBtn = Ti.UI.createButton({
      	top : 20,
      	title : "Schedule notification",
      	width : Ti.UI.SIZE,
      	height : Ti.UI.SIZE
      });
       
      captureScreenBtn.addEventListener("click",function(){
      	var imageBlob = win.toImage(null,true);
      	var imageUrl = Ti.Filesystem.applicationDataDirectory + "image.jpg";
      	var f = Ti.Filesystem.getFile(imageUrl);
      	f.write(imageBlob);
      	imageView.image = imageUrl;
      	imageExists();
      });
       
      notificationBtn.addEventListener("click",function(){
      	Ti.App.iOS.scheduleLocalNotification({
      		date: new Date(new Date().getTime() + 5000),
      		alertBody: "Test notification",
      		badge: 1,
      		userInfo: {id:1},
      		alertLaunchImage : "appicon.png",
      		sound : "default",
      		attachments: [{
      			identifier: "1",
      			url: Ti.Filesystem.applicationDataDirectory + "image.jpg"
      		}],
      		identifier: "1"
      	});
      	setTimeout(function(){
      	    imageView.image = Ti.Filesystem.applicationDataDirectory + "image.jpg"
      	    imageExists();
      	},100)
      	
      });
       
      function imageExists(){
      	var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "image.jpg");
      	alert('"image.jpg" exists? ' + f.exists());
      }
       
      win.addEventListener('open', function() {
        Ti.App.iOS.registerUserNotificationSettings({
          types: [
            Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
          ]
        });
      });
       
      win.add(imageView);
      win.add(captureScreenBtn);
      win.add(notificationBtn);
      win.open();
      

        Attachments

          Activity

            People

            • Assignee:
              shossain Shak Hossain (Inactive)
              Reporter:
              astrovicapps Vittorio Sorbera
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Integration