AFNetworking stop downloading images with same url - iphone

In my app I download images and insert them into a table view. In my case there could be several same images with identical URLs. To reduce the server overloa, I'd like to download each image only once. Is there built-in support for this? Or what is the best way to achieve my goal?

Create a NSMutableDictionary and as you download an image and place it in the table view, add the URL as the key in the dictionary and the table view row as the value. Before you download an image, check to make sure that the dictionary doesn't already contain the URL (if ([[dictionary allKeys] containsObject:url]). If it doesn't, download the image. If it does, then grab the row number and make the empty row's image the same as the image of the row in the dictionary.
http://example.com/image => 1

Related

Parse and Viewing Files on WebView

I have some files between the extensions of pdf and doc on parse database
I have a tableview which populates from parse query so when i click on them i want to display the file for that row in a new webview. I'm on final stage now but i could not find a way to get file from parse and view it on webview via Swift.
No issue on code so far my tableview populates and cells are making segue to the new empty webview, of course without file. By the way i'm not sure webview can view the doc files so if it can't please advice me the best way to do it.
Thank you
You'll need to retrieve the URL for the file object, and tell the web view to load that URL. Lets assume you have a Place object that has a PFFile related to it via an attribute called brochure. You can get your PFFile object that describes the file (doesn't contain the actual file) with a call like:
let placeBrochure = myPlace["brochure"] as PFFile
Then, you'll need to extract the url from that PFFile
let brochureURL = NSURL(string: placeBrochure.url)! // Probably shouldn't force unwrap
and load it into your webview
let request = NSURLRequest(URL: brochureURL)
webview.loadRequest(request)
For your specific case, you'll need to extract the equivalent of the myPlace object from some sort of array that represents the data that's used to populate your tableview, and this will probably need to happen in didSelectRow.
In terms of support for Microsoft Word .doc format files, it looks like UIWebView should be able to handle them: https://developer.apple.com/library/ios/qa/qa1630/_index.html

ANDROID : Loading Image From link stored in mysql db in imageview?

I want to load image in card view with other data like title and desc.
I am uaing php to get result as json response which is working and also i am able to set data to textview and pass from one activity to other !
Only problem i am facing is in setting image in image view.
i can add image manually by making listview obj and storing link in ArrayList obj
Like obj.add(R.drawable.feature1.jpg)
How to do it dynamically from the json response i am getting ?
Sorry if i sound confusing as i am new to android and just want to make a image gallery where first i will display list of albums and after clicking one of albums all images from that albums are loaded and displayed.
{"products":[{"mid":"1","title":"Demo Video 1","link":"https:\/\/m.youtube.com\/watch?v=PCwjNfSM-U","mediaCreatedOn":"2015-08-30 18:59:18","mediaUpdatedOn":"0000-00-00 00:00:00"},{"mid":"2","title":"Demo Video 1","link":"https:\/\/www.youtube.com\/","mediaCreatedOn":"2015-08-30 18:59:18","mediaUpdatedOn":"0000-00-00 00:00:00"}],"success":1}
The above is the output from server side where only the youtube link is replaced by server img location.
Thank you for reading, have a nice day ahead :)
1:You can store image to database Example:mysite.com/img/34324234342.png (phpMysql)
2:And you can get image from php rest service (Only image link)
3:For load image from link , you can use picasso library (android)
4:If you want image with text, you can use custom listview
Example xml for restful service.
<myimage>
<title>abc</title>
<ipath>mysite.com/img/34324234342.png</ipath>
</myimage>

copy paste text and image both to clipboard in iphone app

I am working on an app where I want to copy some text and image and allow user to paste it anywhere. I know it is done using UIPasteboard and I have implemented copying of image but now I want to copy image and text both and then let user paste it. There can be several images and text messages which can come in any order. It is like a paragraph being written with text and images. Is this possible? Can someone suggest me how can I achieve it?
Regards
Pankaj
You can put anything you wish in the pasteboard, including multiple entries like of type UIPasteboardTypeListString and another of type UIPasteboardTypeListImage, and even another of type #"My Made-Up Type". Think of it as a shared mutable dictionary.
It's up to the receiving application to understand what to do with them.

How to handle correctly converting images to thumbnails

I'm building out an admin area for an ecommerce site where the user can create a new product and upload multiple images to be used for the product. I have a table that lists all of the products, each row shows the first image returned from the database. I can scale down a large image to 100px x 100px but the user is still downloading a big image, not a true thumbnail.
I see two ways of doing this:
1. I can make the user choose which img will be the thumbnail so that the regular img is upload and also a smaller version of the file.
2.I can create thumbnails for every img that is uploaded and append to the filename of the thumbnail img so that I can return the first image that ends with a certain string.
Is there a more elegant way to do this or am I on the right track?
Create a cache directory, then create a script called something like image.php. Link your images like this
<img src="image.php?path=images/img.png&width=100&height=100">
Then in image.php, it should first check in the cache directory if the file exists.
Call the file "img.png&width=100&height=100" and save it in the cache directory. That way you can easily check if it exists, but there is enough entropy for someone to change it to width=101 and height = 101 so that the image will be regenerated.
Each time you create the thumbnail, just store it in the cache directory. If it exists, do a header() call and an echo file_get_contents() and then die().

saving text from uitextview to plist

for my application i am able to read the description of a place selected from the table row and display it in the uitextview. but what i needed to do next is able to save content edited by user in the uitextview to plist. need some guide because i had been searching for it but in vain..thanks
You don't need to use a plist to store a string, you can use -[NSString writeToFile:atomically:encoding:error:] method, and just create a single file.
If you're dead set on creating a plist, you can use the NSPropertyListSerialization class to read and write plists.