FBConnect - template not using my template bundle - fbconnect

I registered a template bundle for my app, one that only uses *actor*, so I brought it up like this:
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 12345;
[dialog show];
(using my bundle id, of course)
But all I get when the dialog comes up is "Do you want to publish this story to your Profile?". The "story" doesn't show up in the dialog, and if I click Publish I end up with a blank story in my feed.
Then I tried registering another one which a) has only a one-line story, to make things simpler (the first one had everything) and b) uses a custom key.
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.templateBundleId = 12345;
dialog.templateData = #"{\"flavor\": \"chocolate chip\"}";
[dialog show];
Same result, blank story. I've done a lot of google searching and can't find anyone else with this problem, so I must be doing something incredibly silly. Can anyone advise, please?

I fixed it, but I don't quite understand the fix (I'm new to Obj-C as well as iPhone).
I have an ivar called session, which stores the FBConnect session, for which I had an #property and #synthesize as usual. I removed both of those and explicitly retained the session when it was allocated, instead of relying on the property to do it, and it started working. I don't see how these are functionally different, but in comparing my code to the sample, which worked, I noticed this difference and tried it. The release is in the dealloc method, which is where it was all along.
I would love an explanation if anyone can give one!

Related

How to save a UIImageView to a CoreData Database

What is the SIMPLEST way to save a UIImageView to a CoreData Database. I have tried this:
Save:
UIImage *image = imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[newContact setValue:imageData forKey:#"imageViewFinal"];
Retrive:
imageView.image = [matches valueForKey:#"imageViewFinal"];
and I have added an Attribute called 'imageViewFinal' with a Binary Data type.
PROBLEM:
When I go to build it and click the save button, the app crashes, what's the problem?
Thanks, Seb.
What #ShermanLo said is right, the crash log shows that you've modified your model but did not handle the conflict between the old & new store model versions in the right way.
So just delete your App in your device/simulator, and rebuild/run it.
Note: Whenever you've modified your models, you need to do it this way unless you offer an approach to handle. There're many related QAs on SO. :)

NSNotification with multithreading XCODE

I am a newbie to IPHONE development. I am facing a issue in working with NSNotification with multithreading.
I have a few images in a gallery.I select the image. Selected images get stored in core data.I have a button (upload). When i click on it i need to show a hud with a NSNotification saying (Uploading with image name). ie. "uploading image1.jpg" then i need to call the next thread to display "uploading image2.jpg" and so on. I need a sample code for this.
I need to know how to send and receive NSNotification with multithreading. Kindly help me in this issue.
Thanks in advance.
Consider using MBProgressHUD for this.
The demo project include examples very similar to what you're doing.
The components also has other feature you may want, like a progress indicator.
From the main page, configuring an async task to have a HUD notification is as simple as:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Do something...
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});

Issue with Map view delegate method 'mapView:regionDidChange:' do not call

while using map view in my application some times MKMapKit delegate method 'mapView: regionDidChange' do not call.
Its happens only when I drag the map. but when i zoom in or Zoom out Its working perfectly. So its create issue related to place new annotations on map while dragging the map.
I have do this code in mapView:regionDidChange:
int j=0;
-(void) mapView:(MKMapView *)mapsView regionDidChangeAnimated:(BOOL)animated{
zoomLevel = self.mapView.region.span.latitudeDelta;
if (![appDelegate internetConnected]){
return;
}
if (appDelegate.isMapViewRegionChanged) {
if (j==0) {
j++;
return;
}else{
j=0;
appDelegate.isMapViewRegionChanged = FALSE;
return;
}
}
[self callGetMapViewWithObject:nil];
}
/*
first boolean is to check Internet connection.
[appDelegate internetConnected]
Second condition is to return when we navigate from any view controller too map View controller.
appDelegate.isMapViewRegionChanged
Third is a method to place new annotations.
[self callGetMapViewWithObject:nil];
*/
I checked all conditions and booleans but my coding is not reason for this bug.
so may be its related to region did change method.
So while using my app with map, 20% of time its behave like Ideal(method do not call).
can some one help me out with this.
Thank you in advance.
EDIT It broke randomly, so I now call the function again (undoing what I said below), no changes extra... and um, it works. I feel like I'm flipping a coin.
I just had this happen because I have a subclassed MKMapView. I don't know if you're subclassing this or not, but for some reason Apple's super functions, eg: -(void) scrollViewDidScroll; called super but was not intercepted properly and skipped that call.
When I removed the "overridden" call, that was just a call to [super scrollView], it started working properly.
I don't know why apple's code is broken that way (calling super doesn't have the same effect not overriding it), but make sure you're not subclassing these:
ScrollView functions
MKMapView functions...
or perhaps using the WildCard Gesture Recognizer provided very kindly by the answer to why Map Views don't respond to touchesBegan/Moved etc here: How to intercept touches events on a MKMapView or UIWebView objects? .
If this doesn't help, ensure you don't have a view on top of the other views, improper delegates, xibs are arranged and hooked up, the usual stuff.

Getting UITabBarController to work with Core Data

I've been reading this thread on Stackoverflow and have been trying to replicate the solution with no success in my own project.
My project has 4 tabs. In my app delegate I do this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Page1 *page1 = (Page1 *)[navController topViewController];
Page2 *page2 = (Page2 *)[navController topViewController];
Page3 *page3 = (Page3 *)[navController topViewController];
Page4 *page4 = (Page4 *)[navController topViewController];
page1.managedObjectContext = self.managedObjectContext;
page2.managedObjectContext = self.managedObjectContext;
page3.managedObjectContext = self.managedObjectContext;
page4.managedObjectContext = self.managedObjectContext;
[self.window makeKeyAndVisible];
return YES;
}
In the originating thread it says I need to create a IBOutlet to each navController for each tab I want to use Core data on.
Whilst you can assign multiple delegates for the UINavigationController the same is not true for the outlets, you can only ever supply ONE outlet for the navController.
I can get Page1 to work, but the other pages simply crash; because of the lack of an IBOutlet.
Do I really need X IBOutlets for Y Tabs or can I do it another way?
Another issue is that the originating thread the accepted answer is:
Ideally you want to pass either the
NSManagedObjectContext,
NSFetchedResultsController or the
relevant NSManagedObject "down" into
the UIViewController.
But there is no code or example of how to do this.
Ideally, I do not want to use a singelton or use the app delegate all over the place.
Any confirmation and clarification would be great.
Thanks.
Your immediate problem has nothing to do with Core Data. You are assigning the same navigation controller to each tab when you need a separate navigation controller for each tab otherwise the navigation controller's hierarchy of views will get scrambled every time you change tabs.
The pattern recommended in the question you linked to is called "dependency injection" and it is the one that Apple recommends in most cases. However, in the case of tabbars or any other complex view/view-controller hierarchy, dependency injection can get to complicated. It's a particular issue with tabbars because you don't usually load all tab view/view-controllers when the app starts but wait until each tab is selected before loading its elements.
Instead, you can use an alternative pattern that exploits the UIApplication objects singleton status. Since there is only one application object, there is only one application delegate object. That means that anywhere in the app you can make a call like this:
(MyApplicationDelegate *) appDelegate=(MyApplicationDelegate *)[[UIApplication sharedApplication] delegate];
... and always get the same application object. Then, if you have the managed object context defined as a property of the app delegate you can get the context just by:
theManagedObjectContext=appDelegate.managedObjectContext
Add these two lines to every view controller and you can always be sure of getting the app delegate's managed object context.

NSFetchRequest data into a view?

I am just getting started with the CoreData API and am following a few tutorials. I get the basics of storing and retrieving objects, but am having trouble connecting all the pieces in terms of MVC.
I have a CustomView into which I draw some stuff with CoreAnimation, including some text layers that will get their strings from an NSManagedObject. I started with a basic CoreData application template so the managedObjectContext etc are declared in the appDelegate, and I'm just not sure how I should be getting data from the CoreData stack into the view. By the way, this is all in code, not interface builder.
So my question is, if I want to build my app in a pure MVC way, how should I go about getting data from the stack into the view? How should I give my view access to the initialized NSManagedObjectContext, for example?
I have been reading Cocoa Design Patterns but am a bit of a dunce when it comes to MVC. I know its a pretty general question, but if someone can just say, "set the delegate, grab a pointer..." whatever it is, that would be great!
Thanks in advance!
So I did some more poking around and it seems the easiest way to do this is to get a pointer to the AppDelegate and then a pointer to the managedObjectContext. From there, execute a fetch request and put it into your view!
In a good tutorial Björn Sållarp does it this way:
From the app delegate he creates the rootViewController and sends it the context with:
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.managedObjectContext = context;
rootViewController.entityName = #"Counties";
In the rootViewController's h file you declare:
NSManagedObjectContext *managedObjectContext;
Create its property:
#property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
and in m you
#synthesize managedObjectContext;
Then its there for your use.

Resources