FBRequestConnection class method not found - objective-c

I am trying to run a Facebook multi-query as instructed by the tutorial on the Facebook developer's site for FacebookSDK for iOS, below is the code I have in my iOS app:
-(BOOL) FBGetFriendList
{
if (FBSession.activeSession.isOpen)
{
// Multi-query to fetch the active user's friends
// Initial query is stored in reference named "friends"
// Second query picks up the "uid2" info from the first query
// and gets the friend details.
NSString *query =
#"{"
#"'friends':'SELECT uid2 FROM friend WHERE uid1 = me()',"
#"'friendinfo':'SELECT uid, name, pic_square FROM user WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM #friends)',"
#"}";
// Setup the query parameter
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:query, #"q", nil];
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *_connection, id _result, NSError *_error) {
// check for errors here
if (_error)
{
NSLog(#"FacebookSDKPlugin > FBGetFriendList() > request error!");
}
else
{
#synchronized(friendList)
{
if (friendList == nil)
{
friendList = [[NSMutableArray alloc] init];
}
else
{
[friendList removeAllObjects];
}
NSArray *facebookData = [(NSDictionary *)_result objectForKey:#"data"];
int count = facebookData.count;
for (int i = 0; i < count; ++i)
{
NSDictionary<FBGraphUser> *tempObject = [facebookData objectAtIndex:i];
FacebookFriend *tempFriend = [[FacebookFriend alloc] initWithID:[tempObject.id copy] name:[tempObject.name copy]];
[friendList addObject:tempFriend];
}
}
}
}];
return YES;
}
return NO;
}
However, during compilation there is a warning:
Class method '+startWithGraphPath:parameters:HTTPMethod:completionHandler:' not found (return type defaults to 'id')
I ignored the error and compiled on my iPad2, which crashed with this error:
2012-09-03 11:53:13.377 +[FBRequestConnection startWithGraphPath:parameters:HTTPMethod:completionHandler:]: unrecognized selector sent to class 0xa05350
2012-09-03 11:53:13.379 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBRequestConnection startWithGraphPath:parameters:HTTPMethod:completionHandler:]: unrecognized selector sent to class 0xa05350'
I have included "FBRequest.h", and "Facebook.h", and I can see the method in "FBRequest.h". However I don't understand why the compiler cannot find the function. Does anybody have any idea how to solve this issue?

Opps I realized I have been using the older version of FacebookSDK, which explains why the code doesn't work as stated in the official tutorial. Updating to the latest version of the SDK (Version 3.0.8) fixed this issue!

Related

Core data disable journal_mode don't work

I want to disable the journal mode in my core data app.
This is the code:
- (NSPersistentContainer *)persistentContainer {
// The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
#synchronized (self) {
if (_persistentContainer == nil) {
_persistentContainer = [[NSPersistentContainer alloc] initWithName:#"My_App"];
NSURL *url = [[self applicationFilesDirectory] URLByAppendingPathComponent:#"My_App.sqlite"];
NSPersistentStoreDescription *description=[[NSPersistentStoreDescription alloc]initWithURL:url];
NSMutableDictionary *pragmaOptions=[NSMutableDictionary dictionary];
[pragmaOptions setObject:#"DELETE" forKey:#"journal_mode"];
[description setOption:pragmaOptions forKey:#"NSQlitePragmaOptions"];
_persistentContainer.persistentStoreDescriptions=#[description];
[_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
if (error != nil) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
NSLog(#"Unresolved error %#, %#", error, error.userInfo);
abort();
}
}];
}
}
return _persistentContainer;}
I also verified with this:
NSArray *descriptionArray=[_persistentContainer persistentStoreDescriptions];
NSPersistentStoreDescription * description=[descriptionArray objectAtIndex:0];
NSLog(#"%#",description.options);
and the result of NSLog is:
{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
NSQlitePragmaOptions = {
"journal_mode" = DELETE;
};
but when I restart my app I always find in the application directory all the three file My_App.sqlite, My_App.sqlite-shm and My_App.sqlite-wal.
Why doesn't it work?

EXC_BAD_ACCESS during NSFileVersion call to removeOtherVersionsOfItemAtURL: inside coordinated write block

I'm using what seems to be a simple invocation of the NSFileVersion class method removeOtherVersionsOfItemAtURL: inside a coordinated writing block for some iCloud conflict resolution.
When my devices go into 'spaz mode', which is a technical term for repeatedly opening and closing the application on a few devices, an EXC_BAD_ACCESS exception is thrown internally. Code snippet:
- (void)compareVersionChanges:(NSFileVersion *)version {
if (![DataLoader iCloudPreferenceEnabled]) {
NSLog(#"Ignoring iCloud changes (version comparison) based on user preference");
return;
}
NSLog(#"compareVersionChanges");
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^(void) {
NSError *readError = nil;
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:(id)self];
[coordinator coordinateReadingItemAtURL:[version URL] options:0 error:&readError byAccessor:^(NSURL *newURL) {
DataContext *loadedContext = nil;
NSData *data = [NSData dataWithContentsOfURL:newURL];
NSError *e = nil;
loadedContext = [self convertXmlDataToContext:data error:&e];
if (e) {
NSLog(#"Done loading, error: %#", e);
[[DataLoader applicationDelegate] displayError:e];
loadedContext = nil;
}
if (!loadedContext) {
return;
}
id appDelegate = [DataLoader applicationDelegate];
DataContext *inMemoryContext = nil;
if (appDelegate != nil && [appDelegate respondsToSelector:#selector(context)]) {
inMemoryContext = [appDelegate performSelector:#selector(context)];
}
if (inMemoryContext) {
NSLog(#"Performing iCloud context synchronizating...");
DataContextSynchronizer *synchronizer = [[DataContextSynchronizer alloc] init];
ChangeSet *changes = [synchronizer compareLocalContext:inMemoryContext andRemoteContext:loadedContext];
if ([[changes changes] count] > 0) {
[SelectionManager disable];
#synchronized(appDelegate) {
NSLog(#"Applying synchronization changes...");
[synchronizer applyChangeSet:changes toDataContext:inMemoryContext];
NSLog(#"Synchronization changes applied");
}
[SelectionManager enable];
if ([appDelegate respondsToSelector:#selector(setSkipRefreshSave:)]) {
[appDelegate performSelector:#selector(setSkipRefreshSave:) withObject:[NSNumber numberWithBool:YES]];
}
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^(void) {
[SelectionManager notifyListeners];
});
if ([appDelegate respondsToSelector:#selector(setSkipRefreshSave:)]) {
[appDelegate performSelector:#selector(setSkipRefreshSave:) withObject:[NSNumber numberWithBool:NO]];
}
[self save:[[DataLoader applicationDelegate] context]];
} else {
NSLog(#"No sync changes applicable.");
}
NSError *coordinateWriteRemoveError = nil;
[coordinator coordinateWritingItemAtURL:newURL options:NSFileCoordinatorWritingForDeleting error:&coordinateWriteRemoveError byAccessor:^(NSURL *theURL) {
theURL = [theURL copy];
NSError *removeOtherVersionsError = nil;
[NSFileVersion removeOtherVersionsOfItemAtURL:theURL error:&removeOtherVersionsError];
if (removeOtherVersionsError) {
NSLog(#"Error removing other versions: %#", removeOtherVersionsError);
}
}];
if (coordinateWriteRemoveError) {
NSLog(#"Error occurred coordinating write for deletion of other file versions: %#", coordinateWriteRemoveError);
}
}
}];
if (readError) {
NSLog(#"Done loading (outside block) error: %#", readError);
}
});
}
I thought a little syntax highlighting might make this easier to examine:
Link to image of code snippet and failure stack in Xcode
The error actually occurs on line 1404, and as you can see from the below screenshot, it's deep in Apple code territory.
Link to image of debugger
Before submitting a radar, I thought I'd check here to see if there's something I'm doing wrong? The extra [... copy] on line 1402 was just a quick check to make sure I'm not losing the reference to the block-provided argument, and will be removed.
Edit: An important note! I'm using ARC.
Edit 2: I've noticed that when calling:
[NSFileVersion otherVersionsOfItemAtURL:theURL]
The return value is nil, which indicates (via the documentation):
...or nil if there is no such file. The array does not contain the version object returned by the currentVersionOfItemAtURL: method.
So by checking the return value of this method before I make the call to removeOtherVersionsOfItemAtURL:, it has alleviated the issue. But I still find it strange that an EXC_BAD_ACCESS is thrown, rather than that method handling it properly.
I've noticed that when calling:
[NSFileVersion otherVersionsOfItemAtURL:theURL]
immediately prior to the call to removeOtherVersionsOfItemAtURL:, the return value is nil, which indicates (via the documentation):
Returns: An array of file version objects or nil if there is no such
file. The array does not contain the version object returned by the
currentVersionOfItemAtURL: method.
So by checking the return value of this method before I make the call to removeOtherVersionsOfItemAtURL:, it has alleviated the issue. But I still find it strange that an EXC_BAD_ACCESS is thrown by removeOtherVersionsOfItemAtURL:, rather than that method simply returning NO, or simply populating the provided NSError object.
I'll be filing a Radar and will update here when I hear back.

Calling Obj-C Code from JavaScript via Console: Arguments get dropped?

Having a heck of a time with this one.
I've got a super-simple Cocoa app containing one WebView, a WebScripting API defined in the page, and a single NSObject defined on that API. When I turn on the debugger tools (in the embedded WebView), I can see the API on the JavaScript window object, and I can see my "api" property defined on that -- but when I call the API's "get" method, the arguments aren't being serialized -- when the Obj-C method gets called, the arguments are missing. See below, which hopefully illustrates:
I've combed through the docs, I've (apparently) set the appropriate methods to expose everything that needs to be exposed, and I can see the method being called. There has to be something stupid I'm missing, but as a relative newbie to this environment, I'm not seeing it.
Thanks in advance for your help!
Have you set WebKitDeveloperExtras to YES in your default user defaults when you send -[NSUserDefaults registerDefaults:]?
Depending on what version of Xcode you're using you could be getting a known error. If you're using LLDB on anything but the most recent version, it might not be giving you the right variables in the debugger. The solution has been to use GDB instead of LLDB until Apple fixes the problem. But I think they fixed the problem in the latest version. I'd change the debugger to use GDB and see if you're getting the right variables in Xcode. (Product-> Edit Scheme...-> Run -> Debugger). I came across this problem in iOS, though, so I don't know its applicability to OSX. Worth a try anyway.
I originally came across the problem here: https://stackoverflow.com/a/9485349/1147934
I process javascript in the main thread of my app from a local file stored in the apps directory. I check for beginning and ending tokens for the js functions I am executing and whether the function contains a variable.
Hopefully this can give you some good ideas for your issue. You could also do alerts in the js to see if the values post correctly as you run the app (I am sure you thought of that already, but it's worth mentioning.) Happy coding! I hope this helps!
in the .h file define:
NSMutableString *processedCommand;
NSArray *commandArguments;
In the .m file:
// tokens
#define kOpenToken #"<%%"
#define kCloseToken #"%%>"
// this will throw
-(void)executeJScriptCommand:(NSString *)aCommand {
[self performSelectorOnMainThread:#selector(executeThisCommand:) withObject:aCommand waitUntilDone:YES];
}
// this will throw
-(NSString *)executeCommand:(NSString *)command {
NSString *aCommand = [[[command stringByReplacingOccurrencesOfString:kOpenToken withString:#""]
stringByReplacingOccurrencesOfString:kCloseToken withString:#""]
stringByTrimmingLeadingAndTrailingWhitespaces];
if ([aCommand hasPrefix:#"="])
{
// variable. get value
[self getVariableFromCommand:aCommand];
}
else {
[self executeThisCommand:aCommand];
}
NSString *returnValue = [NSString stringWithString:processedCommand];
self.processedCommand = nil;
self.commandArguments = nil;
return returnValue;
}
-(void)executeThisCommand:(NSString *)aCommand {
BOOL hasError = NO;
// clear result
self.processedCommand = nil;
self.commandArguments = nil;
BOOL isFromJS = NO;
NSString *function = nil;
NSMutableArray *commandParts = nil;
#try {
// first, break the command into its parts and extract the function that needs to be called, and the (optional) arguments
commandParts = [[NSMutableArray alloc] initWithArray:[aCommand componentsSeparatedByString:#":"]];
if ([[[commandParts objectAtIndex:0] lowercaseString] isEqualToString:#"js-call"]) {
isFromJS = YES;
[commandParts removeObjectAtIndex:0];
}
// get our function, arguments
function = [[commandParts objectAtIndex:0] retain];
[commandParts removeObjectAtIndex:0];
if ([commandParts count] > 0){
if (isFromJS == YES) {
NSString *arguments = [[commandParts objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([arguments length] > 0) {
self.commandArguments = [arguments JSONValue];
}
}
else {
self.commandArguments = [NSArray arrayWithArray:commandParts];
}
}
// build invoke
SEL sel = NSSelectorFromString(function);
if ([self respondsToSelector:sel]) {
[self performSelectorOnMainThread:sel withObject:nil waitUntilDone:YES];
// using invocation causes a SIGABORT because the try/catch block was not catching the exception.
// using perform selector fixed the problem (i.e., the try/catch block now correctly catches the exception, as expected)
}
else {
[appDelegate buildNewExceptionWithName:#"" andMessage:[NSString stringWithFormat:#"Object does not respond to selector %#", function]];
}
}
#catch (NSException * e) {
hasError = YES;
[self updateErrorMessage:[NSString stringWithFormat:#"Error processing command %#: %#", aCommand, [e reason]]];
}
#finally {
[function release];
[commandParts release];
}
if (hasError == YES) {
[appDelegate buildNewExceptionWithName:#"executeThisCommand" andMessage:self.errorMessage];
}
}
// this can return nil
-(NSString *)getQueryStringValue:(NSString *)name {
NSString *returnValue = nil;
if (queryString != nil) {
returnValue = [queryString objectForKey:[name lowercaseString]];
}
return returnValue;
}

Using ZXing in OSX to get QRCode data

I'm looking to implement a class that will be able to read a QR Code from a file (jpeg, bmp, whatever) and output that information as an NSString.
The problem I'm having is that every project seems to revolve around getting the iPhone to do this with the camera.
I am looking to do this on an OSX Desktop with an Image File. I've attempted to use the Objective-C OSX project included with ZXing, but I have been unable to get it to play nice with my own projects.
Has anybody had any success in doing this? Thanks!
So here was what I came up with and it seems to work for me.
- (NSString*) movieFrameAsString:(CGImageRef)targetMovieFrame
{
#try
{
ZXCGImageLuminanceSource* luminancesource = [[ZXCGImageLuminanceSource alloc] initWithCGImage:targetMovieFrame];
ZXHybridBinarizer* binarizerInput = [[ZXHybridBinarizer alloc] init];
[binarizerInput initWithSource:luminancesource];
ZXBinaryBitmap* binarybitmapInput = [[ZXBinaryBitmap alloc] initWithBinarizer:binarizerInput];
ZXDecodeHints* decodehints = [[ZXDecodeHints alloc] init];
ZXQRCodeReader* qrcodereader = [[ZXQRCodeReader alloc] init];
ZXResult* results = [qrcodereader decode:binarybitmapInput hints:decodehints];
[luminancesource release];
[binarizerInput release];
[binarybitmapInput release];
[decodehints release];
[qrcodereader release];
return [results text];
}
#catch (ZXReaderException* rex)
{
if (![rex.reason isEqualToString:#"Could not find three finder patterns"])
{
//NSLog(#"failed to decode, caught ReaderException '%#'", rex.reason);
}
}
#catch (ZXIllegalArgumentException* iex)
{
//NSLog(#"failed to decode, caught IllegalArgumentException '%#'", iex.reason);
}
#catch (id ue)
{
//NSLog(#"Caught unknown exception: %#", ue);
}
return 0;
}
The targetMovieFrame is brought in, it runs it through the cocktail of filters to produce a binary image. It produces results by decoding the image using hints, and using a method included in the QRCodeReader object. Then I return the results, which is an NSString. Everything else is just exceptions being caught and returned.

Last FM API SIG_ABRT error

I'm getting a SIG_ABRT error in the one line within the else of this method in the FMCallback class of the Last FM API.
- (void)fire {
if(_identifier == nil) {
[_target performSelector:_selector withObject:_userInfo];
} else {
[_target performSelector:_selector withObject:_identifier withObject:_userInfo];
}
}
The console output shows this:
2011-05-29 13:52:24.533 QueryTesting[6918:707] +[LastFM loginCallback:data:]: unrecognized selector sent to class 0x19550
2011-05-29 13:52:24.625 QueryTesting[6918:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[LastFM loginCallback:data:]: unrecognized selector sent to class 0x19550'
What does this mean? Am I not sending enough information with my request?
EDIT:
Here is the code to create the FMEngine (api key x'd out):
+ (void)logUserInWithUsername:(NSString *) username andPassword:(NSString *) password {
FMEngine *fmEngine;
fmEngine = [[FMEngine alloc] init];
NSString *authToken = [fmEngine generateAuthTokenFromUsername:username password:password];
NSDictionary *urlDict = [NSDictionary dictionaryWithObjectsAndKeys:username, #"username", authToken, authToken, _LASTFM_API_KEY_, #"XXXXXXXXXXXXXXXX", nil, nil];
[fmEngine performMethod:#"auth.getMobileSession" withTarget:self withParameters:urlDict andAction:#selector(loginCallback:data:) useSignature:YES httpMethod:POST_TYPE];
}
- (void)loginCallback:(NSString *)identifier data:(id)data {
// data is either NSData or NSError
NSLog(#"Got Data (%#): %#", identifier, data);
}
You've defined a -[LastFM loginCallback:data:] method, not +[LastFM loginCallback:data:].