Using FaceBook SDK why do I get 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance - xcode

This code gives this error...why ?
'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithObjectsAndKeys:longitude,#"longitude",latitude,#"latitude",nil];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: info, #"venue", nil];
NSString *graphPath = [NSString stringWithFormat:#"/%#", (ID_OF_EVENT)];
FBRequest *updateEvent = [FBRequest requestWithGraphPath:graphPath parameters:params HTTPMethod:POST];
[updateEvent startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
I am trying to set the venue longitude and latitude, but no matter what I try I keep getting the run time error. What am I missing ? I thought "venue" is a dictionary under the main event and has the valid keys "longitude" and "latitude". Have one my parameters got to be an Array and not a dictionary ?
Actually I suspect these elements are non writable and I probably have to add the address at #"location" to see the details appear.
Regards

Related

Mac ABRecord setValue forProperty error

When I use AddressBook like this :
ABAddressBook *ab = [ABAddressBook addressBook];
ABPerson *person = [[ABPerson alloc]init];
[person setValue:lastName forProperty:kABLastNameProperty];
[ab addRecord:person];
[ab save];
I got error :
`Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-[__NSCFString count]: unrecognized selector sent to instance 0x1001448a0'`
What does setValue:forProperty do
It looks like the problem is in
-[__NSCFString count]
The setValue:forProperty sets value for a property. It looks like the problem might be your lastName object that you are trying to set.

Unable to retrieve data with RestKit because class is not key value coding compliant

I am writing a simple Multiple choice question for iOS.
I want to create an API so that I can retrieve the questions and store the answers of the users. I use django and tastypie for the backend.
I use this function to load the quesion in my app :
- (void)loadQuestion
{
RKObjectMapping* questionMapping = [RKObjectMapping mappingForClass:[Question class]];
[questionMapping addAttributeMappingsFromDictionary:#{
#"question": #"question",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:questionMapping pathPattern:nil keyPath:#"question" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSURL *URL = [NSURL URLWithString:#"http://127.0.0.1:8000/api/v1/question/2/?format=json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSLog(#"request : %#", request);
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:#[responseDescriptor]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(#"Load collection of Articles: %#", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(#"Operation failed with error: %#", error);
}];
[objectRequestOperation start];
}
Here is my question.h :
#import <Foundation/Foundation.h>
#interface Question : NSObject
#property (strong) NSString *question;
#end
And my question.m
#implementation Question
#synthesize question = _question;
#end
The JSON is the following :
{
"chapter": "/api/v1/chapter/2/",
"id": 2, "
pub_date": "2013-04-25T19:23:42.930097",
"question": "Quelle est la capitale de ce pays : Emirats Arabes Unis ?",
"resource_uri": "/api/v1/question/2/"
}
And the tastypie API is :
from tastypie.resources import ModelResource
from tastypie import fields
from .models import Question, Chapter
class ChapterResource(ModelResource):
class Meta:
queryset = Chapter.objects.all()
resource_name = 'chapter'
class QuestionResource(ModelResource):
chapter = fields.ForeignKey(ChapterResource, 'chapter')
class Meta:
queryset = Question.objects.all()
resource_name = 'question'
The error i get is :
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x76b3030> valueForUndefinedKey:]: this class is not key value coding-compliant for the key question.'
I read https://github.com/RestKit/RestKit/wiki/Object-Mapping but did not find what I am doing wrong.
What is wrong with my class ?
Try turning on trace logging to get more details about what's happening with the mapping:
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
That said, I'm not sure it's a problem with the mapping. The exception is thrown while trying to read the question from a string object. RestKit shouldn't be doing that based on your use case. So, you need to add a breakpoint on all exceptions so you can see the full stack trace and work out what's going on: Xcode adding an exception breakpoint.
Looking at your JSON and mapping spec it seems ok.

Ignoring SSL certificate errors with NSURLConnection

I'm using [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)] to pull data from a web service, but the web server has a self-issued certificate, causing this error to appear:
Error displayed using:
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
Is there any way to ignore this error and continue anyway?
Following the instructions in the linked question, I defined a dummy interface for NSURLConnection:
#interface NSURLRequest (DummyInterface)
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
#end
And called the method before creating the request:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
This suppressed the error about the certificate being invalid.
This may be rejected by Apple. Use the proper implementation of NSConnectiondatadelegate:
see a way around it:
Stackoverflow response to similar question

What is the encoding for URL bookmarks stored as NSData?

What is the best way to get the path from the NSData bookmark object, if the bookmark will not resolve?
Normally, you just resolve the bookmark, you get a URL, and off you go. But if the bookmark is to an NFS mount that is not currently present, it won't resolve. So now I have an NSData pointing somewhere that won't resolve, but I don't know where it points.
Here is the code block I have that loads the bookmarks, tries to resolve them, and attempts to decode the NSData if the resolve fails, but I can't figure out the encoding - is this even possible?
NSError* error = [[NSError alloc] init];
NSURL* resolvedURL = [NSURL URLByResolvingBookmarkData:bookmarkData
options:NSURLBookmarkResolutionWithSecurityScope | NSURLBookmarkResolutionWithoutUI
relativeToURL:nil
bookmarkDataIsStale:NULL
error:&error];
if (resolvedURL) {
// do some stuff
...
} else {
NSString* msg = [NSString stringWithFormat:#"Error Resolving Bookmark: %#", error];
NSLog(msg);
// the below certainly doesn't get me a path from the bookmark, any idea what will?
// NSString* path = [[NSString alloc] initWithData:bookmarkData encoding:NSUTF32StringEncoding];
}
I never did figure out the encoding, but I found a workaround.
Originally, I encoded the sandboxed NSURLs into NSData objects, and then stored those as an NSArray in NSDefaults. Therefore, I had no way to determine the path for the NSData, unless it would resolve.
The workaround was to change the design - now I encode the sandboxed NSURL, store it as an object into an NSDictionary with the key being the URL path, and store the NSDictionary in NSDefaults.
With this approach, I can easily retrieve the NSData for any given path, even if it will not resolve.

What does -[NSURL length]: unrecognized selector sent to instance 0x1001c0360 mean

I've been trying to get some example code interfaced with a Cocoa interface(It had been written using Carbon); however, when I attempted to replace
err = ExtAudioFileCreateNew(&inParentDirectory, inFileName, kAudioFileM4AType, inASBD, NULL, &fOutputAudioFile);
with
err = ExtAudioFileCreateWithURL(CFURLCreateWithString(NULL,(CFStringRef)inFileName,NULL),kAudioFileM4AType,inASBD, NULL,kAudioFileFlags_EraseFile, &fOutputAudioFile);
I started to get these exceptions
2011-09-25 10:27:31.701 tester[1120:a0f] -[NSURL length]: unrecognized
selector sent to instance 0x1001c0360
2011-09-25 10:27:31.701 tester[1120:a0f] -[NSURL length]: unrecognized selector sent to instance 0x1001c0360.
I've looked at several other questions and answers and in all of those cases the problem was related to a NSURL being passed when a NSString was expected; however, I can't find where/if I'm doing that. I've looked at the documentation and as far as I can tell with my extremely limited knowledge of Apple's APIs. I'm not doing anything wrong.
Any help would be greatly appreciated.
May be help you, i had same problem
I was trying to make UIImage from :
[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]]];
Then its solved with by making string with [NSString stringWithFormat:]
NSString *urlStr =[NSString stringWithFormat:#"%#", [_photosURLs objectAtIndex:indexPath.row]];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
The error message is pretty clear. NSURL class does not have a -length instance method.
Have you tried to create the NSURL object with Objective-C syntax and cast it to CFURLRef?
I had the same issue while getting url from string like
[NSString stringWithFormat:#"%#Activity/GetBudget/%#",self.baseURL,activityID]
and I resolved it by calling absoluteString
like this
[[NSString stringWithFormat:#"%#Activity/GetBudget/%#",self.baseURL,activityID] absoluteString]

Resources