diff --git a/sample/theRunAround/Classes/mainViewController.h b/sample/theRunAround/Classes/mainViewController.h index 82f7a37902..2759d1cff6 100644 --- a/sample/theRunAround/Classes/mainViewController.h +++ b/sample/theRunAround/Classes/mainViewController.h @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - + * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,11 +23,11 @@ @class Runs; -@interface mainViewController : UIViewController { - + IBOutlet FBLoginButton* _fbButton; IBOutlet UIButton* _addRunButton; Facebook *_facebook; @@ -35,16 +35,16 @@ NSArray *_permissions; UserInfo *_userInfo; MyRunViewController *_myRunController; - + IBOutlet UITextField *_location; IBOutlet UITextField *_distance; IBOutlet UIDatePicker *_date; - + IBOutlet UIView *_logoutView; IBOutlet UIScrollView *_loginView; IBOutlet UIView *_headerView; IBOutlet UIView *_addRunView; - + UITableView *_friendTableView; NSManagedObjectContext *_managedObjectContext; } @@ -56,6 +56,7 @@ @property(nonatomic, retain) UIView *addRunView; @property(nonatomic, retain) MyRunViewController *myRunController; @property(nonatomic, retain) NSManagedObjectContext *managedObjectContext; +@property(nonatomic, retain) Facebook *facebook; - (IBAction) fbButtonClick: (id) sender; - (IBAction) addRunButtonClick: (id) sender; diff --git a/sample/theRunAround/Classes/mainViewController.m b/sample/theRunAround/Classes/mainViewController.m index d66cd966f1..ee6a63ae42 100644 --- a/sample/theRunAround/Classes/mainViewController.m +++ b/sample/theRunAround/Classes/mainViewController.m @@ -27,12 +27,13 @@ @implementation mainViewController -@synthesize managedObjectContext = _managedObjectContext, +@synthesize managedObjectContext = _managedObjectContext, logoutView = _logoutView, loginView = _loginView, headerView = _headerView, addRunView = _addRunView, - myRunController = _myRunController; + myRunController = _myRunController, + facebook = _facebook; /////////////////////////////////////////////////////////////////////////////////////////////////// // Private helper function for login / logout @@ -43,7 +44,7 @@ - (void) login { - (void) logout { [_session unsave]; - [_facebook logout:self]; + [_facebook logout:self]; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -53,10 +54,14 @@ - (void) logout { * initialization */ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if (!kAppId) { + NSLog(@"Missing app id!"); + exit(1); + } if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - _permissions = [[NSArray arrayWithObjects: + _permissions = [[NSArray arrayWithObjects: @"publish_stream",@"read_stream", @"offline_access",nil] retain]; - + } return self; } @@ -64,13 +69,13 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - + _location.keyboardType = UIKeyboardTypeDefault; _location.returnKeyType = UIReturnKeyDone; _location.delegate = self; _distance.returnKeyType = UIReturnKeyDone; _distance.delegate = self; - + _session = [[Session alloc] init]; _facebook = [[_session restore] retain]; if (_facebook == nil) { @@ -89,7 +94,7 @@ - (void)viewDidLoad { [[self view] addSubview:[self headerView]]; [_headerView addSubview:_fbButton]; - + } @@ -99,7 +104,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface } - (void)dealloc { - + [_facebook release]; [_permissions release]; [_userInfo release]; @@ -125,13 +130,13 @@ - (IBAction) fbButtonClick: (id) sender { */ - (IBAction) addRunButtonClick: (id) sender { [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:0.75]; - [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight + [UIView setAnimationDuration:0.75]; + [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; [_loginView removeFromSuperview]; [_headerView removeFromSuperview]; - + [self.view addSubview:self.addRunView]; [UIView commitAnimations]; @@ -141,10 +146,10 @@ - (IBAction) addRunButtonClick: (id) sender { * IBAction for Add My Run button click */ - (IBAction) insertRun: (id) sender{ - - NSEntityDescription *runEntity = [NSEntityDescription entityForName:@"Runs" + + NSEntityDescription *runEntity = [NSEntityDescription entityForName:@"Runs" inManagedObjectContext:_managedObjectContext]; - Runs *newRun = [[[NSManagedObject alloc] initWithEntity:runEntity + Runs *newRun = [[[NSManagedObject alloc] initWithEntity:runEntity insertIntoManagedObjectContext:_managedObjectContext] autorelease]; newRun.location = _location.text; @@ -152,38 +157,38 @@ - (IBAction) insertRun: (id) sender{ newRun.facebookUid = [f numberFromString:_userInfo.uid]; newRun.date = _date.date; - + if (_distance.text) { - newRun.distance = [f numberFromString:_distance.text]; + newRun.distance = [f numberFromString:_distance.text]; } - + [f release]; - + NSError *error = nil; if (![_managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } - - [_addRunView removeFromSuperview]; + + [_addRunView removeFromSuperview]; [self.view addSubview:_headerView]; _myRunController.managedObjectContext = _managedObjectContext; [self.myRunController viewWillAppear:YES]; [self.view addSubview:_loginView]; - + SBJSON *jsonWriter = [[SBJSON new] autorelease]; - - NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: + + NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil]; - + NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks]; - + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; - - NSString *caption = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@", + + NSString *caption = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@", @"I run",_distance.text, @"miles at", _location.text ,@"on", [dateFormatter stringFromDate:_date.date]]; NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys: @@ -192,7 +197,7 @@ - (IBAction) insertRun: (id) sender{ @"It finally happened, I started exercising.", @"description", @"http://itsti.me/", @"href", nil]; NSString *attachmentStr = [jsonWriter stringWithObject:attachment]; - + NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: kAppId, @"api_key", @@ -201,11 +206,11 @@ - (IBAction) insertRun: (id) sender{ attachmentStr, @"attachment", nil]; [dateFormatter release]; - + [_facebook dialog: @"stream.publish" andParams: params andDelegate: self]; - + } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -213,7 +218,7 @@ - (IBAction) insertRun: (id) sender{ /** * FBSessionDelegate - */ + */ -(void) fbDidLogin { [_logoutView removeFromSuperview]; [_addRunView removeFromSuperview]; @@ -221,18 +226,18 @@ -(void) fbDidLogin { _fbButton.isLoggedIn = YES; [_fbButton updateImage]; _addRunButton.hidden = NO; - - _userInfo = [[[[UserInfo alloc] initializeWithFacebook:_facebook andDelegate: self] - autorelease] + + _userInfo = [[[[UserInfo alloc] initializeWithFacebook:_facebook andDelegate: self] + autorelease] retain]; [_userInfo requestAllInfo]; - + [self.view addSubview:self.loginView]; } /** * FBSessionDelegate - */ + */ -(void) fbDidLogout { [_session unsave]; [_loginView removeFromSuperview]; @@ -248,7 +253,7 @@ -(void) fbDidLogout { - (void)userInfoDidLoad { [_session setSessionWithFacebook:_facebook andUid:_userInfo.uid]; [_session save]; - + _myRunController = [[MyRunViewController alloc] init]; _myRunController.managedObjectContext = _managedObjectContext; _myRunController.userInfo = _userInfo; @@ -258,11 +263,11 @@ - (void)userInfoDidLoad { } - (void)userInfoFailToLoad { - [self logout]; + [self logout]; _fbButton.isLoggedIn = NO; _addRunButton.hidden = YES; [self.view addSubview:self.logoutView]; - + } /** * UITextFieldDelegate diff --git a/sample/theRunAround/Classes/theRunAroundAppDelegate.m b/sample/theRunAround/Classes/theRunAroundAppDelegate.m index 3b5a0dbc3a..6819236c93 100644 --- a/sample/theRunAround/Classes/theRunAroundAppDelegate.m +++ b/sample/theRunAround/Classes/theRunAroundAppDelegate.m @@ -33,15 +33,15 @@ @implementation theRunAroundAppDelegate #pragma mark - #pragma mark Application lifecycle -- (BOOL)application:(UIApplication *)application - didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch controller = [[mainViewController alloc] init]; controller.managedObjectContext = [self managedObjectContext]; controller.view.frame = CGRectMake(0, 20, 320, 460); [window addSubview:controller.view]; - + [window makeKeyAndVisible]; return YES; @@ -49,11 +49,11 @@ - (BOOL)application:(UIApplication *)application /** - * applicationWillTerminate: saves changes in the application's managed object + * applicationWillTerminate: saves changes in the application's managed object * context before the application terminates. */ - (void)applicationWillTerminate:(UIApplication *)application { - + NSError *error = nil; if (managedObjectContext != nil) { if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { @@ -63,17 +63,21 @@ - (void)applicationWillTerminate:(UIApplication *)application { } } +- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { + return [controller.facebook handleOpenURL:url]; +} + #pragma mark - #pragma mark Core Data stack /** * Returns the managed object context for the application. - * If the context doesn't already exist, it is created and bound to the persistent + * If the context doesn't already exist, it is created and bound to the persistent * store coordinator for the application. */ - (NSManagedObjectContext *) managedObjectContext { - + if (managedObjectContext != nil) { return managedObjectContext; } @@ -88,15 +92,15 @@ - (NSManagedObjectContext *) managedObjectContext { /** * Returns the managed object model for the application. - * If the model doesn't already exist, it is created by merging all of the models + * If the model doesn't already exist, it is created by merging all of the models * found in the application bundle. */ - (NSManagedObjectModel *)managedObjectModel { - + if (managedObjectModel != nil) { return managedObjectModel; } - managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; + managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; return managedObjectModel; } @@ -110,23 +114,23 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } - - NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] + + NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"theRunAround.sqlite"]]; - + NSError *error = nil; - persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] + persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; - if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType - configuration:nil - URL:storeUrl - options:nil + if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType + configuration:nil + URL:storeUrl + options:nil error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } - + return persistentStoreCoordinator; } @@ -138,7 +142,7 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { * Returns the path to the application's Documents directory. */ - (NSString *)applicationDocumentsDirectory { - return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) + return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; } @@ -147,11 +151,11 @@ - (NSString *)applicationDocumentsDirectory { #pragma mark Memory management - (void)dealloc { - + [managedObjectContext release]; [managedObjectModel release]; [persistentStoreCoordinator release]; - + [window release]; [super dealloc]; } diff --git a/sample/theRunAround/theRunAround-Info.plist b/sample/theRunAround/theRunAround-Info.plist index 32894445df..a20af923f9 100644 --- a/sample/theRunAround/theRunAround-Info.plist +++ b/sample/theRunAround/theRunAround-Info.plist @@ -2,6 +2,17 @@ + CFBundleURLTypes + + + CFBundleURLName + + CFBundleURLSchemes + + fb[your-app-id] + + + CFBundleDevelopmentRegion English CFBundleDisplayName diff --git a/sample/theRunAround/theRunAround.xcodeproj/project.pbxproj b/sample/theRunAround/theRunAround.xcodeproj/project.pbxproj index cbd464cf19..f05b35897d 100755 --- a/sample/theRunAround/theRunAround.xcodeproj/project.pbxproj +++ b/sample/theRunAround/theRunAround.xcodeproj/project.pbxproj @@ -269,7 +269,14 @@ isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "theRunAround" */; compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; projectRoot = ""; @@ -338,7 +345,7 @@ GCC_PREFIX_HEADER = theRunAround_Prefix.pch; INFOPLIST_FILE = "theRunAround-Info.plist"; PRODUCT_NAME = theRunAround; - SDKROOT = iphonesimulator3.2; + SDKROOT = iphonesimulator4.1; }; name = Debug; }; @@ -368,7 +375,7 @@ PREBINDING = NO; PROVISIONING_PROFILE = ""; "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; - SDKROOT = iphonesimulator4.0; + SDKROOT = iphonesimulator4.1; }; name = Debug; };