Saving images locally in windows phone 8.1 universal app - windows-runtime

I want to download and save(cache) images locally in windows phone 8.1 universal app. so that if Phone is offline I can show users images(avatars) in ListView.
What is the best way of saving images to local storage(should I use local storage or I use sqlite as i am using sqlite to store user's other information)?
How can I save (download) images to local store?
Thanks!

There's a great extension by Q42 in their Q42.WinRT framework called ImageExtensions.cs
You use it on normal Image objects in XAML, but instead of setting the Source of the Image, you set the ImageExtensions.CacheUri.
<Image q42controls:ImageExtensions.CacheUri="https://www.google.com/favicon.ico" />
q42controls is just a namespace added on top of the XAML page
xmlns:q42controls="using:Q42.WinRT.Controls"
When the image is loaded, it's automatically cached!

Related

Apple File system Permission to read from Photo Library

I have a UIWebView inside my ios application , which loads responsive website into my webview, developed in asp.net . Website has a button to choose video from device Photo Library and another button to upload video.
In till ios version 10.2 it is uploading files successfully to server.
Apple introduce new version ios 10.3 with new file system APFS before it was HFS+ File System.
In ios 10.3 it doesnot allow my application to read video file and 0kb size is uploaded to server. This is because my app doesnot have read permission for that file.
How can I allow file system permission to read file from my app.Is there is anything that can be added to my info.plist
Do anyone stuck with this kind of issue.
Thanks
The problem is related to a bug in UIWebView which makes all file input to have the multiple attribute set automatically.
The only solution for iOS 10.3 is to use WKWebView instead, which does not add the multiple attribute automatically.
It's mostly old iOS apps that use UIWebView which I guess is the reason why there are not many bug reports on the web related to this problem.

Expire time for locally cached images on Windows Phone 8.1

I am extending a previously asked question about caching images locally in windows phone 8.1 app
I am using ImageExtension from the Q42.WinRT framework as suggested in the accepted answer to cache images on the device, but I still have an additional requirement to set an expire time on the cached image, mainly to avoid using storage for images that won't be used anymore.
My current code is:
...
xmlns:q42Controls="using:Q42.WinRT.Controls"
...
<!-- Event Image
Source set to default image
Extension for using image cache-->
<Image Stretch="UniformToFill"
HorizontalAlignment="Center"
Source="/Assets/default_image.png"
q42Controls:ImageExtensions.CacheUri="{Binding Image.Url}"/>
Is there any way to indicate an expire time for the images being cached by the framework?
There was definitely no functionality to delete old images so I implemented the change and made a pull request to integrate it in the Q42.WinRT library.
Version 1.3.0.42 now available on Nuget has the change available.
On app initialization (App.xaml.cs in my case) I added the following line:
await WebDataCache.Clear(TimeSpan.FromDays(1));
This deletes all the files which haven't modified for the given time span.

How to execute a background task only for once in windows phone 8.1 universal app

In my application after first login/registration I need to download data from server this will take some time. And user can quit the application while data is loading. So I need to download the data in background process. I know I can use backgorund application/Class and register this class in windows phone application but this is only for one time. Is there any other way to do so without creating backgourd task for this?
Maybe this will help,
You're looking for BackgroundDownloader and DownloadOperation in the Windows.Networking.BackgroundTransfer namespace.
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
MSDN Windows.Networking.BackgroundTransfer
Background Transfer Sample Project (Windows Universal)

WP8 toast notification with custom sound

I'm currenly writing an app where I need to use custom sound for toast notifications (which is sent from cloud). MSDN states that the audio clip must be stored in the app's installation directory or local storage folder. So how is this done?
I tried the CopyToIsolatedStorage() code sample from How to play background audio for Windows Phone. It fetches the audio clip correctly but when the toast should be shown the device won't play any audio or even show the toast which indicates that it can't find the audio clip correctly. In the app, I have a method which shows contents of the push notification when the app is in foreground. From there I can see that the toast notification is sent and received correctly with toast.mp3 sound tag. So the problem must be in the app but I can't figure out what I did wrong.
Tl;dr version:
I want to change toast notification sound, my device is running WP8 with Update 3 and I have a 5 sec long mp3. I can't figure out how and where I should put the audio clip.
I dont think you need to copy the sound to isolated storage, just put it in your main project and set it as content. Then in your Push just reference it.
<wp:Sound>toast.mp3</wp:Sound>
Or if it is in the Assets folder in your project do
<wp:Sound>Assets/toast.mp3</wp:Sound>
Note: This only works for Windows Phone 8 Update 3 and later, works fine for all Windows Phone 8.1.
So the problem was that I blindly assumed one can reference to the audio clip with just <wp:Sound>toast.mp3</wp:Sound> or new Uri("toast.mp3", UriKind.RelativeOrAbsolute), as in the MSDN tutorial, when the file is copied to the root of the isolated storage but this isn't the case. You'll have to include the directory where the clip is in your project to the path, in my case Audio\. Thaks goes to WiredPrairie for pointing this out.
So to wrap things up:
Copy the audio clip which you want to use to the isolated storage with CopyToIsolatedStorage() from How to play background audio for Windows Phone and follow the instructions in Using custom sounds in toasts on Windows Phone 8 Update 3 . And remember to include the directory structure to the path of the clip or put the clip in the root of your project.

How to store user settings in windows rt app

Coming from a mobile background (Android/iOS) both OS's have something that you can hold application preferences (SharedPreferences in android and NSUserDefaults in iOS) like boolean's, int's, strings's ect. which are just key/value pairs that the user can set for polling intervals or turning off something in the app.
What is the equivalent to that in Windows RT?
Windows.Storage.ApplicationData.Current.LocalSettings is a container where you can programmatically add/set key-value-pairs. Are you looking for that?
http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localsettings.ASPx