Handle File.write insufficient disk space - appcelerator

I am developing an application for both Android and iOS. In this application, I download images from the remote server which the user can view them. Now, my question is that when we develop native applications, if the storage space is insufficient, then during file write, it will throw an exception.
Now, similarly when we are doing the same in Appcelerator, file.write(blob), if the disk is not sufficient, will the call throw can exception, or do we need to check for the return value to confirm that it has been written properly.

Soumy, you will need to check the return value.
If you looked in the SDK source code you will see that the native exception for both Android/iOS is send as a false value, through the Kroll Proxy.
You can check here for the File.write implementation on JAVA and
here for the File.write implementation on Obj-C

There is the method spaceAvailable inside Ti.Filesyste.File (https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem.File-method-spaceAvailable). You could use that the create a manual check before saving the file if you know how big it is

Related

How can I know what entitlement items should be added for Mac sandbox app?

In Apple's document about App Sandbox, I found something about Temporary Exception, and the value of Global Mach Service Temporary Exception is an array, but I do know what items can this array contains.
Actually, I hope there is place where I can check what entitlement items should be added for a specific function in sandbox app. For example, for a certain function, maybe I should add some com.apple.security.temporary-exception.mach-lookup.global-name and com.apple.security.temporary-exception.files.absolute-path.read-write, but the problem is what they are.
For now, when the function is unable to work in sandbox, I can find error message in system log, but still do not know what entitlements are needed.
documentation of sandbox is pretty inconsistent. what it suggests is to just use whatever you want to do, run the app and check console to see which functions fail. https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/DesigningYourSandbox/DesigningYourSandbox.html#//apple_ref/doc/uid/TP40011183-CH4-SW1
EDIT: if you're using temporary exceptions you'll need to add them in iTunes connect and explain each one in detail.

Microsoft Edge browser how to read Clipboard data

I am unable to read clipboard data in Microsoft Edge browser. i am using the below javascript.
if (window.clipboardData && window.clipboardData.getData) { // IE
pastedText = window.clipboardData.getData('Text');
} else if (e.clipboardData && e.clipboardData.getData) { //non-IE
pastedText = e.clipboardData.getData('text/plain');
}
Non of the if/elseif block is executed in Edge. I tried using
e.originalEvent.clipboardData.getData('text/plain');
But I am getting 'Access is denied.' error.
Let me know, if anybody know how to fix this issue.
Edge does not currently support the clipboard api, but it is under consideration and likely to be added in near future.
I do not have edge, but it seems that you are not authorized to access the clipboard data. Is this on a website or are you calling this from within a JavaScript script executed locally?
Make sure the website is in the trusted sites.
See https://w3c.github.io/clipboard-apis/#clipboard-event-interfaces, or more precisely:
12.1 Privacy concerns
Untrusted scripts should not get uncontrolled access to a user's clipboard data. This specification assumes that granting access to the current clipboard data when a user explicitly initiates a paste operation from the user agent's trusted chrome is acceptable. However, implementors must proceed carefully, and as a minimum implement the precautions below:
Objects implementing the DataTransfer interface to return clipboard data must not be available outside the ClipboardEvent event handler.
If a script stores a reference to an object implementing the DataTransfer interface to use from outside the ClipboardEvent event handler, all methods must be no-ops when called outside the expected context.
Implementations must not let scripts create synthetic clipboard events to get access to real clipboard data except if configured to do so.
Implementations should not let scripts call document.execCommand('paste') unless the user has explicitly allowed it.
Implementations may choose to further limit the functionality provided by the DataTransfer interface. For example, an implementation may allow the user to disable this API, or configure which web sites should be granted access to it.

Modify webpage on Share Extension iOS8

I try to run js pre/post processor to modify webpage after finish share extension, but finalize method failed to run.
In Apple document it said that both Share extensions and Action extensions can benefit from this js processor, but my finalize method not get called. Only run method get called. Anyone know how to make this work ?
Accessing a Webpage
In Share extensions (on both platforms) and Action extensions (iOS
only), you can give users access to web content by asking Safari to
run a JavaScript file and return the results to the extension ...
https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html
Here is sample project: https://app.box.com/s/9ild73l9gbmfazrmjerk
In your code you have a typo in function type, should be "finalize" instead of "finalizea".

Getting a notification when a local file is accessed in windows

I'd like to get notified when a specific file get accessed (AFAIK, most generally for a Userland code - by CreateFile() / NtCreateFile())
I already know about FileSystemWatcher which should do the same within the .NET environment, But I'm working in plain C + WinAPI.
As for the type of notification , raising a specified Event would be perfect, but sending a callback to be called , will also work.
See FindFirstChangeNotification function in WinAPI and related links.
Alternatively, when functionality of that function is not enough, you can use a filesystem filter driver (write yours or use our CallbackFilter product).

Refresh resources in Windows Phone 7 app isolated storage

I have a Windows Phone app that relies on an XML data file that comes packaged with the app. When the app is ran the first time on a phone, I load the file into isolated storage. Once the file is loaded into isolated storage, the app uses the isolated storage version of data. In the next version of my app (the Marketplace update), the XML file will have more elements, how do I update the data file once per app update (new version on the Marketplace)?
I thought I could change the file name in the isolated storage, but that would leave trash behind. I could also check for exceptions when I load the XML file, but are there any other, more elegant ways? I do not want to check for the old file in the isolated storage every time my app runs.
The ideal scenario would be to put a piece of code that would be executed once when the new version of the app is loaded onto the phone, is there a way to do that?
To my knowledge there isn't an "out of the box" event that will run a single time at the first run of an app after it was installed/updated.
You'd have to flag the run your self, like you are already stating (save the current version, compare version at each run of the app to see if app was updated!)
I think I now understand what you want.
Add the XML file as a resource.
Use GetResourceStream to get the content of the XML.
Note that the name for the resource would be something like /DllName;component/Folder/ResourceName
Here is what I did:
In the constructor method of my DataLayer class, I added the following code:
private bool AppIsOld
{
get
{
string storedVersion = GetStoredAppVersion(); //stored previously "seen" version
string currentVersion = GetCurrentlyRunningAppVersion();
return !(storedVersion == currentVersion);
}
}
private string GetCurrentlyRunningAppVersion()
{
var asm = Assembly.GetExecutingAssembly();
var parts = asm.FullName.Split(',');
return parts[1].Split('=')[1].ToString();
}
And then I run the following check:
if (AppIsOld)
RefreshResources(); //do whatever to refresh resources
The code for GetCurrentlyRunningAppVersion() function is taken from here.
This solution is not what I had in mind because it runs every time the class constructor is called while I wanted something that would run once upon version update.

Resources