Facebook sdk iOS logout error - objective-c

I'm currently working with the new Facebook SDK and I have a very strange problem. I have a viewcontroller, called FacebookExplorerTableViewController and in my viewdidload I have the following piece of code:
if(appDelegate.session.isOpen)
{
[self receiveAlbums];
}
else
{
appDelegate.session = [[FBSession alloc] init];
appDelegate.session = [FBSession sessionOpenWithPermissions:nil completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#"opened session");
if(!error) [self receiveAlbums];
else NSLog(#"error: %#",error);
}];
}
When I'm running it, everything's fine. However, I have another viewcontroller, named SharingSettingsTableViewController where I have the option to logout:
[appDelegate.session closeAndClearTokenInformation];
When I'm trying to logout, I get a xCode crash:
2012-08-09 21:29:19.683 My Albums[2197:17903] opened session
2012-08-09 21:29:19.684 My Albums[2197:17903] requesting albums
2012-08-09 21:29:19.695 My Albums[2197:17903] access token: (null)
2012-08-09 21:29:19.697 My Albums[2197:17903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x1b6d022 0x1f56cd6 0x1aac7db 0x1ac4e86 0x757a5 0x754f4 0xa17e2 0x9ef39 0x676f9 0x92c3f1 0x1b6ee99 0x55514e 0x5550e6 0x5fbade 0x5fbfa7 0x5fb266 0x57a3c0 0x57a5e6 0x560dc4 0x554634 0x232eef5 0x1b41195 0x1aa5ff2 0x1aa48da 0x1aa3d84 0x1aa3c9b 0x232d7d8 0x232d88a 0x552626 0x21ed 0x2155)
terminate called throwing an exception
It seems to run my completion block again! The 'requesting albums' in the console is coming from the call to receiveAlbums.
Why does this completion block run again? At the time I go to the Settings view controller, I've already deallocated the FacebookExplorerTableViewController! How can this run and how could I get rid of the error? :)
Thanks in advance!

I've had the same issue. My problem was retaining [FBSession activeSession].accessToken by passing it into a NSDictionary. The easiest solution was to pass a [NSString stringWithFormat:#"%#", [FBSession activeSession].accessToken] instead of straight [FBSession activeSession].accessToken usage.

Related

AFNetworking -[_NSInlineData URL]: unrecognized selector sent to instance

I'm using AFNetworking to connect to WebDAV servers for our iPad app (Easy Annotate).
Most functions and servers work correctly.
However, when creating a directory on one of the test servers, the app terminates with the following message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSInlineData URL]: unrecognized selector sent to instance 0x17cc88a0'
Crash location:
AFWebDAVManager.m
- (void)createDirectoryAtURLString:(NSString *)URLString
withIntermediateDirectories:(BOOL)createIntermediateDirectories
completionHandler:(void (^)(NSURL *directoryURL, NSError *error))completionHandler
{
__weak __typeof(self) weakself = self;
[self MKCOL:URLString success:^(__unused AFHTTPRequestOperation *operation, NSURLResponse *response) {
if (completionHandler) {
if([response.class.description isEqualToString:#"_NSZeroData"]) {
completionHandler(nil, nil);
}
else {
completionHandler([response URL], nil); <-- CRASH !!!
}
}
} ...
'response' (see above) is of type _NSInlineData with value:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>
I've found similar threads, which suggest adding $(inherited) to the 'other linker flags'. This did not solve the issue (or I made a mistake ;))
Any ideas what might cause this crash?
We just had the same issue, it's a typo in the code.
It should be completionHandler([operation.response URL], nil);
Best,
Thomas

Facebook login failing on iOS 6

When I try to login using Facebook iOS SDK I get the error The operation couldn't be completed (com.facebook.sdk error 2).
The state of the session is: FBSessionStateClosedLoginFailed.
THis is my code now:
-(void) callFBService{
NSArray *permissions = [[NSArray alloc] initWithObjects:#"email, publish_stream, user_likes, friends_likes", nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES
completionHandler:^(FBSession *fbsession,
FBSessionState status,
NSError *error) {
if(error)
{
NSLog(#"Session error");
[self fbResync];
[NSThread sleepForTimeInterval:0.5]; //half a second
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *fbsession, FBSessionState status, NSError *error) {
[self sessionStateChanged:fbsession state:status error:error];
}];
}
else
[self sessionStateChanged:fbsession state:status error:error];
}];
}
I have tried everything in the following posts:
The operation couldn’t be completed. (com.facebook.sdk error 2.) ios6
Facebook Registration : The operation couldn't be completed (com.facebook.sdk error 2)
Facebook SDK 3.1 iOS: Handle login if user remove app from Facebook Settings
Any ideas??? Please!
You're passing publish_stream in with read permissions, but publish_stream is a write permission. It's also deprecated (use publish_actions instead). Try removing that permission. You'll need to ask for that permission separately, after you get your user logged in with read permissions. See the SDK docs: https://developers.facebook.com/docs/technical-guides/iossdk/login/#read
In addition, a few things to check: Make sure your app on Facebook.com is configured correctly, including the bundle ID. Make sure the user you're attempting to log in has rights to the app (if the app is in sandbox mode, make sure the user is added as a tester and has approved this).

Objective-C errors after getting the IAP product response

This code is from the Phonegap Code: IAP Plugin. The error happens on the line of the code right after the "sent js". All the elements sent to the function are non-nil except for the last one 'nil'. I even logged them out to make sure they were sent. This code is right out of the plugin (https://github.com/usmart/InAppPurchaseManager-EXAMPLE) and has not been modified except for the logging. In the debugger i saw that none of the objects were nil, so i don't understand why the error is happening.
Here is the error:
[__NSArrayI JSONRepresentation]: unrecognized selector sent to
instance 0xdc542d0
2013-02-13 23:26:17.209 GoblinSlots[4519:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSArrayI JSONRepresentation]: unrecognized selector sent to
instance 0xdc542d0'
here is the code:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response
{
NSLog(#"got iap product response");
for (SKProduct *product in response.products) {
NSLog(#"sending js for %#", product.productIdentifier);
NSLog(#" title %#", product.localizedTitle );
NSLog(#" desc%# - %#", product.localizedDescription, product.localizedPrice );
NSArray *callbackArgs = [NSArray arrayWithObjects:
NILABLE(product.productIdentifier),
NILABLE(product.localizedTitle),
NILABLE(product.localizedDescription),
NILABLE(product.localizedPrice),
nil ];
NSLog(#"sent js");
NSString *js = [NSString stringWithFormat:#"%#.apply(plugins.inAppPurchaseManager, %#)", successCallback, [callbackArgs JSONSerialize]];
NSLog(#"js: %#", js);
[command writeJavascript: js];
}
All the stuff to do JSON serialization seems to be already included with the Cordova plugins.
There's no need to download and install yet another JSON library.(a)
It appears that PhoneGap is in the process of switching from SBJson to JSONKit.(b)
PhoneGap is also in the process of changing all the JSON methods to use a "cdvjk_" prefix. (c)
As far as I can tell, something didn't quite go right during those changes.
What I did was edit the file Plugins/InAppPurchaseManager.m , where I made these changes:
Add the line
#import <Cordova/CDVJSON.h>
Replace the line
return [self respondsToSelector:#selector(cdvjk_JSONString)] ? [self cdvjk_JSONString] : [self cdvjk_JSONRepresentation];
with
return [self JSONString];
. (What's the right way to push this or a better bugfix back to the nice PhoneGap people?)
JSONRepresentation is a category that SBJson adds so you have to include SBJson.h in the class that uses it.

How do I cancel a previous Facebook reauthorize call?

A quick question about the Facebook SDK for iOS. I'm trying to implement the functionality for a user to grant my app access to extended permissions.
While the code works fine when the user accepts the extended permission request (from the Facebook iOS app the user gets redirected to), I'm having trouble detecting when the user has returned to the app while having neither accepted the permissions, or clicking cancel then returning to the app.
If I click 'Cancel' and multitask back into the app, there is nothing logged and nothing shown on-screen. When I try to re-authorize again, the Facebook SDK throws an exception:
FBSession: It is not valid to reauthorize while a previous reauthorize call has not yet completed.
While I can catch the exception, it still doesn't help as I can't figure out how to stop the previous call in order to allow the user to try to re-authorize again.
Here's the code I'm using at the moment:
#try {
[[FBSession activeSession] reauthorizeWithPermissions:[self requiredPermissions]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
[self fetchUserPermissionsWithCompletionHandler:^(BOOL extendedGranted) {
if (extendedGranted) {
[self setCanPostToActivityStream:YES];
}
}];
}
else {
NSLog(#"%#", [error localizedDescription]);
}
}];
}
#catch (NSException *exception) {
NSLog(#"%#", exception);
}
Now, the issue is not with the code above - the code works fine. The issue I'm having, again, is cancelling the previous re-authorize call when the user doesn't return to the app successfully after allowing permissions. The Facebook SDK as it is doesn't seem to alert the app of this situation in any way.
From your App's delegate, when - (void)applicationDidBecomeActive:(UIApplication*)application is invoked, you need to make a call to the active session's handleDidBecomeActive method. Once you do that, the completion handler associated with your reauthorizeWithPublishPermissions call will be invoked, and will provide the appropriate error.
- (void)applicationDidBecomeActive:(UIApplication*)application
{
[[FBSession activeSession] handleDidBecomeActive];
}
What you should see coming back from the SDK is an error from the reauthorize completion handler.
{
"com.facebook.sdk:ErrorLoginFailedReason" = "com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled";
}
I tested something similar with the following setup: Xcode 4.5, iOS 5, Authorize against m.facebook.com. After an initial authorization I put code to hit reauthorize, then clicked Cancel and got this error.
[FBSession.activeSession
reauthorizeWithPublishPermissions:
[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Success case
} else {
// Check the error, info
// [[error userInfo] objectForKey:#"com.facebook.sdk:ErrorLoginFailedReason"]
}
}];
If you are not seeing this then it is a bug and you may want to file it with Facebook.

how to solve run time error of [NSURL fileURLWithPath:error:]: unrecognized selector sent to class?

I am beginner in IPhone Developing. I want play sound. so, that's why I have apply this code
(void)viewDidLoad
{
NSError* err;
path=[[NSBundle mainBundle] pathForResource:#"Animalfile" ofType:#"plist"];
dict=[NSDictionary dictionaryWithContentsOfFile:path];
NSArray *animalaudio=[dict valueForKey:#"audio"];
NSString *audiolist=[animalaudio objectAtIndex:currentsound];
AVAudioPlayer *audio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:audiolist error:&err]];
audio.delegate=self;
[audio play];
}
and I have got the run time error of
[NSURL fileURLWithPath:error:]: unrecognized selector sent to class 0x182121c
2012-07-14 14:51:21.711 plistdemo[1236:10703] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '+[NSURL fileURLWithPath:error:]:
unrecognized selector sent to class 0x182121c'
terminate called throwing an exceptionsharedlibrary apply-load-rules all
so, give any suggestion and source code which apply in my code
current documentation for NSURL doesn't list any such method like 'fileURLWithPath:error:'... seems like its either deprecated or incorrect.
instead try using something like:
[NSURL fileURLWithPath:audioList]
hope it helps...