Not Recognizing Function name in AfNetworking - ios

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url=[NSURL URLWithString:share.profilePicUrl];
[_imageview setImageWithURLRequest:[NSURLRequest requestWithURL:url] placeholderImage:
[UIImage imageNamed:#""] success:^(NSURLRequest *request,NSHTTPURLResponse *response,UIImage *image)
{
dispatch_async(dispatch_get_main_queue(), ^{
_imageview.image = image;
});
} failure:^(NSURLRequest *request,NSHTTPURLResponse *response,NSError *error){
}];
});
UIImageView setImageWithURLRequest:placeholderImage:success:failure:]:
unrecognized selector sent to instance 0xb1b71f0
2013-12-12 23:41:00.826 Application[6749:1403] * Terminating app due
to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIImageView
setImageWithURLRequest:placeholderImage:success:failure:]:
unrecognized selector sent to instance 0xb1b71f0'

Ensure that AFNetworking+UIImageView.m (or more likely, all AFNetworking implementation files) has been added to your target.
Click on AFNetworking+UIImageView.m, and select your target under "Target Membership" in the right window.
See Adding files to separate targets in Xcode 4

Related

how to use loadItemForTypeIdentifier to load an image

I have the following function which loads an image using the new PHPickerViewController:
- (void) picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results
{
PHPickerResult *result = [results firstObject];
if (result)
{
[result.itemProvider loadObjectOfClass:[UIImage class] completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error)
{
dispatch_async(dispatch_get_main_queue(),
^{
if (!error)
{
[self pickerControllerDidFinishPickingWithImage:(UIImage *)object];
}
else
{
[self pickerControllerDidFinishWithError];
}
});
}];
}
}
I want to avoid using loadObjectOfClass because I don't want the image to load asynchronously. So I opted to use loadItemForTypeIdentifier instead and did the following:
[result.itemProvider loadItemForTypeIdentifier:#"public.image" options:nil completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error)
{
dispatch_async(dispatch_get_main_queue(),
^{
if (!error)
{
[self pickerControllerDidFinishPickingWithImage:(UIImage *)object];
}
else
{
[self pickerControllerDidFinishWithError];
}
});
}];
However, when I run this code I am getting:
ncaught exception 'NSInvalidArgumentException', reason: '-[NSURL
imageOrientation]: unrecognized selector sent to instance
0x600001ce5920' terminating with uncaught exception of type
NSException
I am not that great with blocks and this is my first time using a UTI so I'm wondering, what am I doing wrong here? Is it even possible to accomplish what I'm trying to accomplish, i.e. pull a UIImage out using loadItemForTypeIdentifier? Am I getting the syntax wrong?

iOS - AFNetworking 2 Dispatch_once

I've just updated Afnetworking 1 to 2.1 and app started to crash. there was no problem at AF 1.0. How can i solve this problem?
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[API initWithBaseURL:]: unrecognized selector sent to instance 0xa3e6810'
API.m
+ (API*)sharedInstance {
static API *sharedInstace = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstace = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAPIHost]];
sharedInstace.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
});
return sharedInstace;
}

download image make and update table view after downloading

I am working on an app which is image downloading. Images are of different sizes. I want to download image async and update table view when image downloading. Also need to clear cache on a time interval.
Please suggest me how to implement. I have seen SDwebimagecache but it is crashing on image downloading.
I hope it's can help you. I use SDWebImage with my all (ARC)projects.
using :
add your viewcontroller : #import "UIImageView+WebCache.h"
[yourImageView setImageWithURL:[NSURL URLWithString:#"ImageUrl"]];
you need to add MapKit and ImageIO to the project. if you didn't add
To do that:
Click on the project at the top of the project navigator in Xcode
Select the 'Build Phases' tab.
Open up the 'Link Binary with Libraries' box.
Click the '+'.
Add MapKit and ImageIO frameworks.
I have used the core data and AFNetworking to achieve the same thing, find below my code
UserBasicInfo* userBasicInfo = [[UserBasicInfo findByAttribute:#"userId" withValue:#(chatUser)] objectAtIndex:0];;
if (userBasicInfo.userImage == nil) {
__weak LGMessageBoxCell *weakCell = cell;
[cell.userImage setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:userBasicInfo.imageUrl]]
placeholderImage:[UIImage imageNamed:#"facebook-no-user.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
weakCell.userImage.image = image;
[weakCell setNeedsLayout];
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
UserBasicInfo* userBasicInfo = [[UserBasicInfo findByAttribute:#"userId" withValue:#(chatUser) inContext:localContext] objectAtIndex:0];
userBasicInfo.userImage = UIImagePNGRepresentation(image);
} completion:^(BOOL success, NSError *error) {
NSLog(#"%#",[error localizedDescription]);
}];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
}];
} else {
cell.userImage.image = [UIImage imageWithData:userBasicInfo.userImage];
}

Trying to parse complex JSON from Instagram with AFNetworking. Driving me a bit crazy

Parsing simple JSON with AFNetworking is well documented and seems very straight forward. What I'm trying to do is parse JSON from Instagram, which is many levels deep into an array where I can pull the images and insert into a CollectionView. Right now I'm stuck. My simple code returns everything in a single text block, and not what I need at all. What I'm trying to grab is outlined in Red. If I grab 10 images, I really want those all in an array. At that point I can grab the actually images and display them. Right now I'm stuck.
Find all images that are tagged Snow:
https://api.instagram.com/v1/tags/snow/media/recent?access_token=836379.f59def8.fd07b9ba8ea440188dc56d2763bbf6c2
Code that just return a string of image names, which is not want I want at all.
-(void)viewDidLoad {
NSLog(#">>> Entering %s <<<", __PRETTY_FUNCTION__);
[super viewDidLoad];
NSString *path = #"https://api.instagram.com/v1/tags/snow/media/recent?access_token=836379.f59def8.fd07b9ba8ea440188dc56d2763bbf6c2";
NSLog(#"path %#", path);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:path]];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSString *image = [[[[JSON valueForKey:#"data"]valueForKey:#"images"]valueForKey:#"low_resolution"]valueForKey:#"url"];
NSLog(#"%#", image);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
// NSLog(#"There was a problem: %#", [error localizedDescription]);
}];
[operation start];
//NSDictionary *dict = [imagesArry objectAtIndex:0];
}
This is what I get:
"http://distilleryimage8.s3.amazonaws.com/3bc4787a401f11e384ec22000ab5caf6_6.jpg",
"http://distilleryimage3.s3.amazonaws.com/d32fb366401d11e3ba2d22000ae90e24_6.jpg",
"http://distilleryimage4.s3.amazonaws.com/903d89f6401911e382a322000a1f9709_6.jpg",
"http://distilleryimage6.s3.amazonaws.com/84350bf8401d11e393e722000aaa0a4a_6.jpg",
"http://distilleryimage5.s3.amazonaws.com/45387d48401f11e3b9ed22000a1f8cd8_6.jpg",
"http://distilleryimage2.s3.amazonaws.com/350228c0401f11e3993b22000ae81198_6.jpg",
"http://distilleryimage4.s3.amazonaws.com/6da0b634401e11e3977b22000aeb36ba_6.jpg",
"http://distilleryimage8.s3.amazonaws.com/a0d357722b5c11e3988a22000a1fbac2_6.jpg",
"http://distilleryimage5.s3.amazonaws.com/b2a25ba8400e11e3bfd922000ae90db3_6.jpg",
"http://distilleryimage2.s3.amazonaws.com/1f6c4716401f11e39bdd22000aeb0cb1_6.jpg",
"http://distilleryimage0.s3.amazonaws.com/ca032f722c5711e38c7122000ab5c5fc_6.jpg",
"http://distilleryimage2.s3.amazonaws.com/4ca448be3fde11e3b66b22000aa8003c_6.jpg",
"http://distilleryimage2.s3.amazonaws.com/19fc276c401d11e3b22b22000a1f96e2_6.jpg",
"http://distilleryimage6.s3.amazonaws.com/e36d5a202ddb11e3ac9b22000a1fb864_6.jpg",
"http://distilleryimage3.s3.amazonaws.com/283e1266401f11e3bf9922000a1fbc1c_6.jpg",
"http://distilleryimage4.s3.amazonaws.com/01e0ccc6401f11e3854822000ae90109_6.jpg",
"http://distilleryimage10.s3.amazonaws.com/b43573fa401e11e3942822000a1fbb05_6.jpg",
"http://distilleryimage8.s3.amazonaws.com/f6029e5c401e11e3ab8622000ab5c723_6.jpg",
"http://distilleryimage8.s3.amazonaws.com/6d914dde401e11e38c3f22000ae800af_6.jpg"
)
Just seems like I'm not approaching it right, is it that simple? One line get grab all my Instagram images links? Hmmmm, it does look like they are seperated by ",". Could it be that simple?
NSString *image = [[[[JSON valueForKey:#"data"]valueForKey:#"images"]valueForKey:#"low_resolution"]valueForKey:#"url"];
UPDATE:
Ok, almost. This is a bit strange, seems very straight forward, trying to split the array by "," yet i am sure I'm working on a string:
NSArray *listItems = [image componentsSeparatedByString:#","];
ERROR: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI componentsSeparatedByString:]: unrecognized selector sent to instance 0x8b84710'
Thanks Hot Licks. Just because I say it's a NSTRING means zilch. I am really returning an array.

xcode running well on simulator but when deploy to ios 6 encounter error

2012-10-08 14:48:14.579 sageby[2716:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SBJsonParser errorTrace]: unrecognized selector sent to instance 0x1fda4660'
* First throw call stack:
(0x352412a3 0x34a1397f 0x35244e07 0x35243531 0x3519af68 0x12932f 0x1293a7 0x12cda3 0x12c9b1 0x12c753 0x12aac7 0x12e567 0x12eac3 0x3a26bef5 0x3a1ab9f1 0x3a1ab90d 0x384ba5df 0x384b9ccb 0x384e2133 0x3518774d 0x384e2593 0x3844615d 0x35216683 0x35215ee9 0x35214cb7 0x35187ebd 0x35187d49 0x35ef02eb 0x37dcd301 0xaaaf1 0x39e0cb20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
//MBProgressHUD
MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText=#"Accessing account..";
hud.labelFont=[UIFont fontWithName:#"Arial Rounded MT Bold" size:14];
//URL GETTING
NSString *phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxxx.com/pxxx/Module_MyPxxx/json_xxxx_xxx_info.php"];
NSString *param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
NSString *receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
SBJsonParser *parser=[[SBJsonParser alloc]init];
NSError *error=nil;
self.dic_user_info=[[parser objectWithString:receivedDataAsString error:&error]objectAtIndex:0];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
//URL GETTING
phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxx.com/pxxx/Module_MyPxxx/json_get_xxx_xxx_pxxx.php"];
param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
parser=[[SBJsonParser alloc]init];
error=nil;
self.array_polls=[parser objectWithString:receivedDataAsString error:&error];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
hi i'm the developer of the application.
The problem is that running on Xcode 4.5 is correct but just running on iphone device it wont work..

Resources