Feed Dialog not working on iOS SDK 3.0 beta (API error code 110) - dialog

I am updating my app to use the new Facebook SDK for iOS (3.0). However, I have run across an issue trying to use the feed dialog. I followed the instructions on Facebook's developer website regarding how to use the feed dialog with the new SDK, but I am getting this error when I show the dialog:
API Error Code: 110
API Error Description: Invalid user id
Error Message: Missing user cookie (to validate session user)
Here is my code:
Facebook *facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
facebook.accessToken = FBSession.activeSession.accessToken;
facebook.expirationDate = FBSession.activeSession.expirationDate;
NSMutableDictionary *feedParams = [[NSMutableDictionary alloc] init];
[feedParams setObject:self.video.alternateLink.href
forKey:#"link"];
// link title = video title
[feedParams setObject:self.video.title.stringValue
forKey:#"name"];
// link picture = video thumbnail
[feedParams setObject:self.video.mediaGroup.highQualityThumbnail.URLString
forKey:#"picture"];
NSDictionary *privacyDict = [NSDictionary dictionaryWithObjectsAndKeys:#"CUSTOM", #"value", #"SELF", #"friends", nil];
SBJSON *jsonWriter = [[SBJSON alloc] init];
[feedParams setObject:[jsonWriter stringWithObject:privacyDict error:NULL]
forKey:#"privacy"];
[jsonWriter release];
[facebook dialog:#"feed"
andParams:feedParams
andDelegate:self];
[feedParams release];
self.facebook = facebook;
[facebook release];
It seems like an authentication problem, but I am passing a valid access token to the Facebook object, so I'm not sure what the problem is. If anybody could help me, that would be great. Thanks.

You may use FBSession.activeSession when integrating with the legacy Facebook class, as you have shown. One possible gotcha when you use activeSession, rather than directly instantiating a session object, is that it may not be open. Here is a simple sample that shows the form for integrating the Facebook class with active session:
if (FBSession.activeSession.isOpen) {
// Create a Facebook instance
Facebook *facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID
andDelegate:nil]; // commonly self
// Set the session information for the Facebook instance
facebook.accessToken = FBSession.activeSession.accessToken;
facebook.expirationDate = FBSession.activeSession.expirationDate;
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"I'm using the the Facebook SDK for iOS", #"name",
#"Facebook for iOS", #"caption",
#"Check out the Facebook SDK for iOS!", #"description",
#"https://developers.facebook.com/ios", #"link",
#"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", #"picture",
nil];
// Invoke the dialog
[facebook dialog:#"feed" andParams:params andDelegate:nil];
[facebook release];
}
If the active session is not open, then you would get a failure along the lines of what you are seeing. A call along the lines of the following, somewhere earlier in your logic remedy this:
[FBSession openActiveSessionWithAllowLoginUI:YES];
Hope this helps!

Related

Passbook : get base64 string from the server, convert and save pkpass to iOS

#import <PassKit/PassKit.h>
// convert base64 string to pkpass data
NSData *passData = [[NSData alloc] initWithBase64EncodedString:strEncodeData options:0];
NSLog(passData);
// init a pass object with the data
PKPass *pass = [[PKPass alloc] initWithData:passData];
NSLog(pass);
//init a pass library
PKPassLibrary *passLib = [[PKPassLibrary alloc] init];
//check if pass library contains this pass already
if([passLib containsPass:pass]) {
//pass already exists in library, show an error message
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Pass Exists" message:#"The pass you are trying to add to Passbook is already present." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
//present view controller to add the pass to the library
PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
[vc setDelegate:(id)self];
[self presentViewController:vc animated:YES completion:nil];
}
I am tring to save passbook to ios wallet. I need to use base64 data instead of uri because of secure issue. The flow I assumed for this is like below
get base64 string from the server.
convert base64 to pkpass data with "initWithBase64EncodedString"
save pkpass to wallet with "PKAddPassesViewController"
With above code, the progress is stop on second step with nil error, even the decoded base64 string is correct. So I cannot be sure the code after 2nd step will functionate without errors.
thanks for answer in advance.
I know its late but i ran into the same problem after lot of research figure the issue is with initWithBase64EncodedString:passBase64 when base64 string decode from server response with mime type like:data:application/vnd.apple.pkpass;base6 NSData get nil. Maybe its a bug but if you use NSData+Base64 classes from https://github.com/l4u/NSData-Base64 its old but you can configure it to work with ARC and than convert data from base64 string to NSData problem goes away.

What Does The Random String In URI Of A PlayList In Spotify Stand For

I am currently integrating Spotify with our music player app. So I visited the official site of Spotify and studied its tutorial.
But when I came across code:
-(void)playUsingSession:(SPTSession *)session
{
// Create a new player if needed
if (self.player == nil)
{
self.player = [[SPTAudioStreamingController alloc] initWithClientId:[SPTAuth defaultInstance].clientID];
}
[self.player loginWithSession:session callback:^(NSError *error)
{
if (error != nil)
{
NSLog(#"*** Logging in got error: %#", error);
return;
}
NSURL *trackURI = [NSURL URLWithString:#"spotify:track:58s6EuEYJdlb0kO7awm3Vp"];
[self.player playURIs:#[ trackURI ] fromIndex:0 callback:^(NSError *error)
{
if (error != nil)
{
NSLog(#"*** Starting playback got error: %#", error);
return;
}
}];
}];
}
I don't know what "58s6EuEYJdlb0kO7awm3Vp" in this line means
NSURL *trackURI = [NSURL URLWithString:#"spotify:track:58s6EuEYJdlb0kO7awm3Vp"];
Is it the id of the track?
Because it is hardcoded, so I don't know how could I request it.
I read the documentation of the APIs especially on the part of SPTPlaylists. But I can't find any explanation of what this string stands for.
Please help me. Thanks in advance!
In the example, 58s6EuEYJdlb0kO7awm3Vp is the Spotify ID for the track, and spotify:track:58s6EuEYJdlb0kO7awm3Vp is its Spotify URI. There is some information in the Spotify Web API User Guide about how identifiers for the Spotify catalog work.
You can use the Spotify desktop client to find out the ID/URI of an album, artist, track or playlist by right-clicking on the header of the view that shows its contents, or you can use the Web API Search endpoint to find out these identifier.
We have just updated the iOS SDK Tutorial to explain better where this ID comes from.

iOS 7 Core Data and iCloud sync

I am looking to integrate in my new app the option to sync core data in iCloud and so share the information on users devices. I looked around on the web but haven't found a good example or tutorial on how to do this with iOS7.
The last that I have done is to analyze the Apple receipt demo app and included in my app. It seams to work, at least at first view. Adding a record on one device and after a short while, the other device show the data - so far I was happy.
BUT, after restoring the app, the information was gone, on both devices. So i looked into the app (iExplorer) and have found the local Core Data and all my data is there. The next that I have observed is that the debugger shows this: (XXX) are of course not the real values :-)
2014-07-09 19:40:12.830 XXX[199:3507] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](771): CoreData: Ubiquity: mobile~XXXXX:XXX
Using local storage: 1
2014-07-09 19:40:12.837 XXX[199:60b] asynchronously added persistent store!
2014-07-09 19:40:13.478 XXX[199:1803] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](771): CoreData: Ubiquity: mobile~XXXXX:XXX
Using local storage: 0
What means first it seams like to use the local storage but than change to local storage 0.
this is the code used from Apple's demo app:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
// assign the PSC to our app delegate ivar before adding the persistent store in the background
// this leverages a behavior in Core Data where you can create NSManagedObjectContext and fetch requests
// even if the PSC has no stores. Fetch requests return empty arrays until the persistent store is added
// so it's possible to bring up the UI and then fill in the results later
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
// prep the store path and bundle stuff here since NSBundle isn't totally thread safe
NSPersistentStoreCoordinator* psc = persistentStoreCoordinator;
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:#"XXX.sqlite"];
// do this asynchronously since if this is the first time this particular device is syncing with preexisting
// iCloud content it may take a long long time to download
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
// this needs to match the entitlements and provisioning profile
NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];
NSString* coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:#"XXXXX"];
cloudURL = [NSURL fileURLWithPath:coreDataCloudContent];
// The API to turn on Core Data iCloud support here.
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:#"XXX", NSPersistentStoreUbiquitousContentNameKey, cloudURL, NSPersistentStoreUbiquitousContentURLKey, [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil];
NSError *error = nil;
[psc lock];
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
/*
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. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
Typical reasons for an error here include:
* The persistent store is not accessible
* The schema for the persistent store is incompatible with current managed object model
Check the error message to determine what the actual problem was.
*/
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
[psc unlock];
// tell the UI on the main thread we finally added the store and then
// post a custom notification to make your views do whatever they need to such as tell their
// NSFetchedResultsController to -performFetch again now there is a real store
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"asynchronously added persistent store!");
[[NSNotificationCenter defaultCenter] postNotificationName:#"RefetchAllDatabaseData" object:self userInfo:nil];
});
});
return persistentStoreCoordinator;
}
Could anyone help with tutorial or solution?
Try these sample apps for iOS and OSX.
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/

How [FBDialogs canPresentShareDialogWithParams:nil] works?

Does anyone make [FBDialogs canPresentShareDialogWithParams:nil] works properly ?
It's always returning me NO. What should I put in params ?
if ([FBDialogs canPresentShareDialogWithParams:nil]) {
NSURL* url = [NSURL URLWithString:#"http://www.google.fr"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
} else {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbComposer setInitialText:#"Google rocks !"];
[self presentViewController:fbComposer animated:YES completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:#"Informations" message:#"You have to be registered into the settings of your phone in order to share" delegate:nil cancelButtonTitle:#"Close" otherButtonTitles:nil] show];
}
}
According to the HelloFacebookSample from the SDK (and my own experience!):
FBShareDialogParams *p = [[FBShareDialogParams alloc] init];
p.link = [NSURL URLWithString:#"http://developers.facebook.com/ios"];
BOOL canShareFB = [FBDialogs canPresentShareDialogWithParams:p];
canShareFB will return YES if the Facebook app is installed in the system; returns NO if no Facebook app is found.
The fact is it always returns NO.
I think this the issue.
Make sure to pass a non-nil instance of FBShareDialogParams to the canPresentShareDialogWithParams method. The SDK expects to receive a valid instance of FBShareDialogParmas so the SDK can make sure that the version of the Facebook app on the device can actually open the content that's going to be shared.
For example, if FB adds support for sharing video via Share Dialog in a future version of the Facebook app on iOS, the canPresentShareDialogWithParams would return NO if an older version of the Facebook app is present on the device.
I can understand how the docs: https://developers.facebook.com/ios/share-dialog/ might be confusing here (apologies!). We'll update them to reflect this.
Thanks for the feedback; hope that helps!

Getting iPhone notifications to call my delegate when the application is running in the background

I have an enterprise application that I want to keep running, so it can call a webservice and inform the user when there is something they need to do.
So, it now runs in the background, it makes the calls, gets results, but informing the user is my problem.
When I fire off a UILocalNotification the alert doesn't call my UIAlertDelegate, and I don't see how to set that alert to do that.
Here is my code for how I am doing the notification, and this actually brings up an alert, but I need it to then bring up a View so they can see the table, but the View it opens isn't one of the two my application uses.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(#"%# has a message for you.", nil), #"FYR"];
localNotif.alertAction = NSLocalizedString(#"Read Msg", nil);
localNotif.soundName = nil;
localNotif.applicationIconBadgeNumber = -1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:#"Your Background Task works", ItemListKey, #"Message from FYR", MessageTitleKey, nil];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
}
Also, so I tried to have an alert come up that I can set the delegate, so in my controller, where I call the above code I am also calling this:
[[NSNotificationCenter defaultCenter]
postNotificationName:#"ShowAlert"
object:nil
userInfo:mydata];
This notification is then picked up and eventually this function is called, and this does work, but the alert isn't visible to the user, I expect because it is in the background.
- (void) _showAlert:(NSString*)pushmessage withTitle:(NSString*)title {
NSLog(#"%#", #"Attemping to show alert");
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title
message:pushmessage
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alertView show];
if (alertView) {
[alertView release];
}
}
In the main delegate, I have this defined, and the appropriate functions:
#interface FYRViewAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> {
my thought being that if I can get the alert that pops up to call this delegate then it can execute this code:
- (void)alertView:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
alertview--;
if (buttonIndex == 0) {
} else {
[self.window addSubview:[tableController view]];
}
}
So, is there any way to get the UILocalNotification to use my delegate for the alert?
Or, is there a way to have an alert show up when the application is in the background?
Or, do I need to write two applications, so they communicate with remote notifications, so when the application is in the background one runs and then starts up the main application with a remote notification. I don't like this approach as it seems very messy, but would probably work.
Since the program never stops running
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
is only called at startup, the local notification never calls it and this also is never called:
- (void) application:(UIApplication*)application
didReceiveLocalNotification:(UILocalNotification *)localNotification {.
I suppose that you don't post notifications when the application is active. Couldn't you simply set a flag when you post a local notification and then check the flag when the application becomes active:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (localNotificationPosted) {
// Do whatever you need to do.
}
}
This will likely be the correct behavior, since the application will become active unless the user dismisses the notification. Even if the user dismisses the notification, showing new messages the next time the app is opened probably isn't a bad thing.

Resources