Facebook iOs sdk iphone : Call from multiple viewcontroller - facebook

i followed the official guide from facebook dev doc for implementing SSO from my iphone app,
but all is in the same viewcontroller who hold istance of "Facebook" class.
Now consider i want to login in first viewcontroller of one navigationcontroller and then call graph api from the third viewcontroller of the same navigationcontroller.
I think i can share the variable from one controller to another, but i wish to know if there is some "classic" ways to accomplish this. Indeed what i wish to accomplish in something like:
At the start of app i wish to login and then call graph api (or fql) wherever i need in my app.
Thx

I just did this:
in the YourApp_AppDelegate.h
#import "FBConnect.h"
Facebook *facebook;
#property (nonatomic, retain) Facebook *facebook;
In the YourApp_AppDelegate.m
#synthesize facebook;
Then in your application didFinishLaunchingWithOptions: function:
facebook = [[Facebook alloc] initWithAppId:#"YOUR_FACEBOOK_API"];
From your viewController.h (any of them),
#import "YourApp_AppDelegate.h"
YourApp_AppDelegate *appDelegate;
And then, in your viewController.m viewDidLoad function:
appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];
Now, anytime you want to refer to your Facebook singleton, just refer to it like:
[appDelegate.facebook authorize:nil delegate:self];

facebook = [[Facebook alloc] initWithAppId:#"YOUR_FACEBOOK_API" andDelegate:self];
Thats how it looks like on my code :)

Related

iOS enabling AirPrint for uiwebview contents

I am super new to XCode and App development. I currently am loading up a web based application in uiwebviews on the iPad. When one particular page is loaded, it displays a pdf file. I would like to be able to print this pdf file using AirPrint. I am looking for a simple solution. Currently the app I am working on has 6 files which it uses.
-ViewController.m
-ViewController.h
-MainStoryboard_iPad.storyboard
-MainStoryboard_iPhone.storyboard
-AppDelegate.h
-AppDelegate.m
In the MainStoryboard files, there are many windows (graphical) which are liked to a central navigation system. If it is possible to spend some time to really explain what I need to do, and not 'take a look at this link.' I have programming experience, but never with XCode or any product related to Apple.
I figured out how to do this. Firstly I found a piece of code here, iOS Air print for UIwebview, I had no idea how to implement this at the time, but then I did as follows.
My application was a single view XCode project
In my storyboard I inserted a button (on my navigation bar) and changed its Identifier to 'Action' then, making sure to have the 'tuxedo' editor view open, displaying my ViewController.m file, I clicked and dragged from the button to the ViewController.m file while holding down control. This inserted my IBAction method after asking for my buttons id.
myActionButton
Then I copied in the code specified in response 3 of the question. My ViewController.m looked something link this.
#import "ViewController.h"
#interface ViewController()
#end
#implementation ViewController()
//Some stuff here
#end
#synthesize webView
-(IBAction)myActionButton:(id)sender{
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
}
Also in my ViewController.h file
#import ...
#interface ViewController : ...
{
IBOutlet UIWebView *webView
}
#property (nonatomic,retain) IBOutlet UIWebView *webView
#end
I didn't setup the webviews so I am not 100% sure on how they are created, but there is a good series for beginners on youtube at HackLife87 which shows how to make a single view app. I think XCode Tutorial Video #7 involves setting up views.
Since I am extremely green to XCode and IPad app development, I managed to solve my problem by combining knowledge from watching the aforementioned XCode tutorial videos and then implementing the solution provided on stackoverflow by Hafthor.

how to come back to app when going to app store from app in ios

going to app store from app using this code
NSURL *myApplicationURL = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication]openURL:myApplicationURL];
Now how can i comeback from app store to app using cancel button.
Thanks for help.
Once you exit your Application you have no way to come back automatically, the user has to open the App again.
You can use show a modal SKStoreProductViewController (available on iOS 6) to show the AppStore inside your Application.
It is easy with the SKStoreProductViewController as redent84 answered and it is introduced in iOS 6+. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project and add #import to header file.
Then find the Apple id of the app by going in iTunes connect manage applications and clicking on app will show you apple id and other details and pass that to the SKStoreProductViewController.
Below is the code
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)AppStoreAction:(id)sender{
NSDictionary *appParameters = [NSDictionary dictionaryWithObject:#"533886215"
forKey:SKStoreProductParameterITunesItemIdentifier];
SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
[productViewController setDelegate:self];
[productViewController loadProductWithParameters:appParameters
completionBlock:^(BOOL result, NSError *error)
{
}];
[self presentViewController:productViewController
animated:YES
completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
In earlier versions you could link to the App Store: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/de/artist/apple/id284417353?mt=12"]] but with this once you exit app you cannot go back to your app.
But with this SKProductViewController you can hit cancel button and go back to your app.
Hope it helps.
try this ........You can use a URL scheme if you have control of the web page. Simply add a link using your scheme.
If your scheme is myapp: then:
Return to the app
See this site for a tutorial. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ refer:Return back to iPhone app from safari

Open a list of my apps in the App Store within my App

I have checked the (Top Paid Apps) sample code from Apple website where you can see all the top apps in the App store, I want to do the same in my app but to show only my apps in the App Store. Here is the URL which i found in that sample :
http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
What do I need to change in this URL to show only my Apps?
This is pretty easy with the SKStoreProductViewController introduced in iOS 6. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project. Then find the iTunes URL that links to your apps using iTunes. You can copy the link from the iTunes Store. For example the URL for the Apple apps is http://itunes.apple.com/de/artist/apple/id284417353?mt=12
It contains the iTunes identifier, that you pass to the SKStoreProductViewController.
Sample code:
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)showMyApps
{
SKStoreProductViewController* spvc = [[SKStoreProductViewController alloc] init];
[spvc loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier : #284417353}
completionBlock:nil];
spvc.delegate = self;
[self presentViewController:spvc animated:YES completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
You could use DAAppsViewController. It can be configured with a developer ID to show all the apps by that developer. It will use StoreKit if available, otherwise fallback to switching to the App Store.

Where should I implement my facebook ios sdk code in my Cocos2d Application?

I am attempting to add facebook integration to my ios game built using Cocos2D. I initially just made the CCLayer object (subclass of NSObject) a FBRequestDelegate, FBDialogDelegate, and FBSessionDelegate. Then I created a facebook object with
fb_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"publish_stream", #"offline_access",nil] retain];
facebook = [[Facebook alloc] initWithAppId:kAppId
andDelegate:self];
next I call
[facebook authorize:fb_permissions];
when the user pushes a button. It all works fine, goes to the facebook login page, correctly authorizes my application etc. Once it returns execution to my game, I expected the
- (void)fbDidLogin
method to be called, but it doesn't seem to be. I'm a little confused and just wondering if I've gone about this wrong? Should I implement my facebook sdk stuff in my root viewcontroller? ie. make my viewcontroller the FB delegate?
Is it that I'm missing a call to handleOpenURL? Which appears to be depracated? I'm having trouble locating decent documentation on this particular issue...
thanks!!
I think you will need to implement handleOpenURL in your App Delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
Edit: I see that execution returns to your game, so you may have already completed the following:
You will also need to edit your .plist file to handle the return from the authorization page. You will add an entry to MyApp-info.plist under
Information Property List->URL Types->Item 0->URL Schemes->Item 0 = "fbYOUR_APP_ID"
Follow the instructions at the end of Step 6 here: http://developers.facebook.com/docs/guides/mobile/#ios

Any examples/tutorials on using Google GData API - Youtube on iphone?

I need to list a specific users uploaded videos (YouTube) in a UITableView. I've downloaded the GData source and example projects (not iphone specific) but I can't seem to get it to work. Does anybody know of any good (or any at all ;)) tutorials out there?
Best regards,
Magnus
Assuming you have included the GData client libraries to your project, you need to make a call to fetch the user's uploads, and then display them. Here's the simplest way I can think of:
Create an instance variable in your table view controller class that will hold the feed data returned from the YouTube API.
RootViewController.h
#import "GDataYouTube.h"
#import "GDataServiceGoogleYouTube.h"
#interface RootViewController : UITableViewController {
GDataFeedYouTubeVideo *feed;
}
#property (nonatomic, retain) GDataFeedYouTubeVideo *feed;
Inside the implementation file, make a call to the API to fetch all uploaded videos. Inside the callback selector request:finishedWithFeed:error, store the results in whatever format suits, and reload the table view. In the table views cellForRowAtIndexPath method, format the cell as desired:
RootViewController.m
// get the youtube service
GDataServiceGoogleYouTube *service = [self youTubeService];
// feed id for user uploads
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:#"annoyingorange"
userFeedID:uploadsID];
// make API call
[service fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(request:finishedWithFeed:error:)];
Checkout the full source code for RootViewController.