Unable to download and view images from parse in iOS - objective-c

As of yesterday I was able to view images fine but now I can't view from url and get error as
NSErrorFailingURLKey=http://files.parsetfss.com
Some images are working fine while others are getting issues.
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:objStampData.stampImage.url] placeholderImage:[UIImage imageNamed:#"PlaceHolder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
if(!error)
{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
}
else
{
NSLog(#"Error %#",error);
}
}];

Two possible reasons:
Name of the image in parse. There I have problem when the name contains somestrange symbols like ".","&" and etc. Try with simple name and different image format.
Check if you allow
access to parse from the plist file check here

Related

when i use SDWebimage to load image,i want to know how the image is loaded,but the Cell is nonfluency

I want to achieve when image is not loaded, the imageView load default image. But when the image is loaded,the imageView load the url-image. Now the problem is that the Sington (SDImageCache) should cause nonfluency. When I shield the Sington (SDImageCache), it's ok.
BOOL isInCache = ([[SDImageCache sharedImageCache]
imageFromCacheForKey:imgUrlStr] != nil);
if (isInCache) {
[self.imgView sd_setImageWithURL:[NSURL URLWithString:imgUrlStr]
placeholderImage:[UIImage imageNamed:#"defaultImg"]
options:SDWebImageRetryFailed];
} else {
self.imgView.image = [UIImage imageNamed:#"defaultImg"];
}
I am using below code in my application.
[IMAGE_VIEW_OBJECT_NAME sd_setImageWithURL:IMAGE_URL placeholderImage:PLACEHOLDER_IMAGE completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if(error)
{
_imgUserPic.image = PLACEHOLDER_IMAGE;
}
else
{
_imgUserPic.image = image;
}
}];
Its help me to show default image when the image is not available on the main URL.
Hope it will work for you.

SDWebImage's sd_setImageWithURL crashes the application when trying to show 100 of images in view

i am showing around 100 of the urls in my one screen asyncronusly in my button image with the SDWebImage.
i am facing issues with the memory load when i tried to show all the images from the url.
i have one UIScrollView and In that i have one UIImageView which has all the 100 Uibutton Added Dynamaically.
Now my requirement is when user Zoomed int he UIScrollView at certain Level i need to show image in UIbutton and when i start to show the Image from the server to that button with the following code its crashes witht he memory warning.
[btn sd_setImageWithURL:[NSURL URLWithString:busOwner.WhiteLargeLogoURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:placeHolderImage]];
can any one please let me know that how can i resolve this memory issues and can also show the images at same time to all the 100 buttons?
i have also tried to put uiiamgeView instead of uiButton and also i have tried to use
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
// Perform non main thread operation
for (BusinessOwnerEntity *busOwner in arrBusOwner) {
NSURL *url = [NSURL URLWithString:busOwner.WhiteLargeLogoURL];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
NSLog(#"REcieved File %ld",(long)receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
}];
}
dispatch_sync(dispatch_get_main_queue(), ^{
// perform main thread operation
});
});
to download images before but its crashes here too..
Use SDWebImage callbacks to load your images in queue, not all at the same time.
It will reduce your memory consumption and avoid iOS to kill your app.
[manager downloadImageWithURL:url options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
NSLog(#"REcieved File %ld",(long)receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if ("are they less than 10 images loading?"){
[self startNewImageLoading];
}
}];

Save Video into Custom Album iOS

How to save video with my custom album .
I found one link but it don't work Custom file manager
It gives the url value is null.
[VideoAlbumManager addVideoWithAssetURL:outputFileUrl toAlbumWithName:#"Video Maker"];//outputfileurl is my video url from document directory
Give any suggestion for this..
-(void)SaveToalbum{
NSString *finalFileName=[NSString stringWithFormat:#"Documents/video.mov"];
NSString *videoOutputPath = [NSHomeDirectory()
stringByAppendingPathComponent:finalFileName];
NSString* webStringURL = [videoOutputPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url =[NSURL URLWithString:webStringURL];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:url])
{
NSURL *clipURl = url;
[library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error)
{
}];
}
}
You can try with it. It will be helpful for you. Just go through "http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/" link and download the sample project.
Drag-drop two file "ALAssetsLibrary+CustomPhotoAlbum.h" and "ALAssetsLibrary+CustomPhotoAlbum.m" into your project and add "AssetsLibrary.framework". Now you are ready for coding.Just go on your ViewController.h Class and import the <AssetsLibrary/AssetsLibrary.h> and "ALAssetsLibrary+CustomPhotoAlbum.h" file.
Create a object for ALAssetsLibrary and write a block for saving the video file in custom album,just like this,
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(#"Big error: %#", [error description])
}
}];
You can use this link to save the video..
GitHub Link
Import this two files into your project.
ALAssetsLibrary+CustomPhotoAlbum.h
ALAssetsLibrary+CustomPhotoAlbum.m
Then in your save IBAction method write this lines..
if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputFilePath)){
NSURL *muyrl=[NSURL fileURLWithPath:outputFilePath];
[library saveVideo:muyrl toAlbum:albumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
Where.. outputfilepath is your videopath and if you have url then save it with URL name.
library is ALAssetLibrary that define in .h file
albumName is your Album name what do you want..I hope this will help you.

load image fastly from url

I have used SDWebimages classes for loading the image from url to image view. But it is still taking time to load.
NSString *filePath1 = [NSString stringWithFormat:#"%#",pathimage1];
[cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
Can anyone tell me what I am doing wrong? Or the best way to load the image from url.
Try this :
NSString *filePath1 = [NSString stringWithFormat:#"%#",pathimage1];
[cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
success:^(UIImage *image, BOOL cached)
{
dispatch_async(dispatch_get_main_queue(), ^{
cell.image1.image = image;
});
NSLog(#"success Block");
}
failure:^(NSError *error)
{
NSLog(#"failure Block");
}];
Loading images from the network may take a long time to load for several reasons, two of the most obvious being
Slow connection to the internet on the device (Wifi / 3G / 2G).
Overloaded server.
To speed things up if you have control over the server and the images that are stored on it you could always load a smaller version (low quality preview/thumbnail) initially, followed by loading a larger / full-size version when needed:
typedef enum {
MyImageSizeSmall,
MyImageSizeMedium,
MyImageSizeLarge
} MyImageSize;
-(void)requestAndLoadImageWithSize:(MyImageSize)imageSize intoImageView:(UIImageView *)imageView
{
NSString *imagePath
switch (imageSize)
{
case MyImageSizeSmall:
imagePath = #"http://path.to/small_image.png";
break;
case MyImageSizeMedium:
imagePath = #"http://path.to/medium_image.png";
break;
case MyImageSizeLarge:
imagePath = #"http://path.to/large_image.png";
break;
}
[imageView setImageWithURL:[NSURL URLWithString:imagePath]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
}

PSYouTubeExtractor Error while Extraction

I am trying to use the PSYouTubeExtractor in my Project, it is supposed to help with displaying YouTube videos inline by either downloading the mp4 or displaying it in a web view.
Here is how I implemented it so far:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[PSYouTubeExtractor extractorForYouTubeURL:[deskUrls objectAtIndex:indexPath.row] success:^(NSURL *URL) {
NSLog(#"Finished extracting: %#", URL);
// show the movie!
} failure:^(NSError *error) {
NSLog(#"Failed to query mp4: %#", error);
}];
}
deskUrl is: this link for example and while this is extracting an error occurs:
[PSYouTubeExtractor doRetry_] [Line 105] Trying to load page...
2012-09-30 17:50:40.054 Tube[3378:907] -[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x21027eb0
Well, I do not understand why, because this is just how it should be done. On the github page of the developer here, this is just the same code.
Anyone has an idea how to fix this?
It expects a NSURL instance but you obviously are providing an NSString instance.
Convert your string into a URL using the following call;
NSURL *youTubeURL = [NSURL URLWithString:[deskUrls objectAtIndex:indexPath.row]];
Then you may use the extractor factory/singleton as already done in your example;
[PSYouTubeExtractor extractorForYouTubeURL:youTubeURL success:^(NSURL *URL) {
NSLog(#"Finished extracting: %#", URL);
// show the movie!
} failure:^(NSError *error) {
NSLog(#"Failed to query mp4: %#", error);
}];