Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controllers for the FB example app + update BubbleWrap.
- Loading branch information
1 parent
f32db94
commit 7fe6710
Showing
10 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.repl_history | ||
build | ||
examples/FacebookGraph/build | ||
examples/FacebookGraph/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Facebook Graph Example | ||
|
||
The Facebook Graph API is a great example of how powerful RemoteModel is. Facebook auth code adapted from [facebook-auth-ruby-motion-example](https://github.com/aaronfeng/facebook-auth-ruby-motion-example) | ||
|
||
## Running | ||
|
||
You need [motion-cocoapods](https://github.com/HipByte/motion-cocoapods) installed to load the Facebook iOS SDK. | ||
|
||
It also appears that (as of May 9 2011), motion-cocoapods doesn't play nice with the FB SDK and you need to use `rake --trace` to get it to load correctly. | ||
|
||
You need to specify an FB app ID, which you can create [in FB's Developer app](https://www.facebook.com/developers): | ||
|
||
###### app_delegate.rby | ||
|
||
```ruby | ||
def application(application, didFinishLaunchingWithOptions:launchOptions) | ||
... | ||
@facebook = Facebook.alloc.initWithAppId("YOUR-APP-ID", andDelegate:self) | ||
... | ||
end | ||
``` | ||
|
||
###### Rakefile | ||
|
||
```ruby | ||
Motion::Project::App.setup do |app| | ||
... | ||
fb_app_id = "YOUR-APP-ID" | ||
app.info_plist['CFBundleURLTypes'] = [{'CFBundleURLSchemes' => ["fb#{fb_app_id}"]}] | ||
... | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
$:.unshift("/Library/RubyMotion/lib") | ||
require 'motion/project' | ||
require 'motion-cocoapods' | ||
|
||
Motion::Project::App.setup do |app| | ||
# Use `rake config' to see complete project settings. | ||
app.name = 'FacebookGraph' | ||
app.files = Dir.glob(File.join(app.project_dir, '../../vendor/BubbleWrap/lib/**/*.rb')) + | ||
Dir.glob(File.join(app.project_dir, '../../lib/**/*.rb')) + | ||
app.files | ||
end | ||
app.files_dependencies 'app/controllers/facebook_login_controller.rb' => 'app/initializers/remote_model.rb' | ||
fb_app_id = "YOUR-APP-ID" | ||
if fb_app_id == "YOUR-APP-ID" | ||
raise "You need to specify a Facebook App ID in ./Rakefile" | ||
end | ||
app.info_plist['CFBundleURLTypes'] = [{'CFBundleURLSchemes' => ["fb#{fb_app_id}"]}] | ||
|
||
app.pods do | ||
dependency 'Facebook-iOS-SDK' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,49 @@ | ||
class AppDelegate | ||
attr_accessor :facebook | ||
attr_accessor :navigationController | ||
|
||
def application(application, didFinishLaunchingWithOptions:launchOptions) | ||
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | ||
@navigationController = UINavigationController.alloc.init | ||
@window.rootViewController = @navigationController | ||
|
||
fb_app_id = "YOUR-APP-ID" | ||
if fb_app_id == "YOUR-APP-ID" | ||
raise "You need to specify a Facebook App ID in ./app/app_delegate.rb" | ||
end | ||
@facebook = Facebook.alloc.initWithAppId(fb_app_id, andDelegate:self) | ||
|
||
defaults = NSUserDefaults.standardUserDefaults | ||
|
||
if defaults["FBAccessTokenKey"] && defaults["FBExpirationDateKey"] | ||
@facebook.accessToken = defaults["FBAccessTokenKey"] | ||
@facebook.expirationDate = defaults["FBExpirationDateKey"] | ||
openFriendsContorller | ||
else | ||
@navigationController.pushViewController(FacebookLoginController.alloc.init, animated: false) | ||
end | ||
|
||
@window.rootViewController.wantsFullScreenLayout = true | ||
@window.makeKeyAndVisible | ||
true | ||
end | ||
|
||
def openFriendsContorller | ||
@navigationController.setViewControllers([FriendsController.alloc.initWithUserId], animated: false) | ||
end | ||
|
||
def fbDidLogin | ||
defaults = NSUserDefaults.standardUserDefaults | ||
defaults["FBAccessTokenKey"] = @facebook.accessToken | ||
defaults["FBExpirationDateKey"] = @facebook.expirationDate | ||
defaults.synchronize | ||
openFriendsContorller | ||
end | ||
|
||
def application(application, | ||
openURL:url, | ||
sourceApplication:sourceApplication, | ||
annotation:annotation) | ||
@facebook.handleOpenURL(url) | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
examples/FacebookGraph/app/controllers/facebook_login_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class FacebookLoginController < UIViewController | ||
def viewDidLoad | ||
self.title = "Login" | ||
self.view.backgroundColor = UIColor.whiteColor | ||
|
||
button = UIButton.buttonWithType UIButtonTypeRoundedRect | ||
button.when(UIControlEventTouchUpInside) do | ||
UIApplication.sharedApplication.delegate.facebook.authorize nil | ||
end | ||
button.setTitle("FB Login", forState: UIControlStateNormal) | ||
button.sizeToFit | ||
|
||
# ugly, dont really do this. | ||
width, height = button.frame.size.width, button.frame.size.height | ||
button.frame = CGRectMake(((self.view.frame.size.width - width) / 2).round, | ||
((self.view.frame.size.height - height) / 2).round, | ||
width, | ||
height) | ||
self.view.addSubview button | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
examples/FacebookGraph/app/controllers/friends_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class FriendsController < UITableViewController | ||
attr_reader :user | ||
|
||
def initWithUserId(id = "me") | ||
@user = User.new(id: id) | ||
self | ||
end | ||
|
||
def initWithUser(user) | ||
raise "User cannot be nil" if user.nil? | ||
@user = user | ||
self | ||
end | ||
|
||
def viewDidLoad | ||
super | ||
self.title = @user.name ? "Friends of #{@user.name}" : "Friends of #{@user.id}" | ||
|
||
defaults = NSUserDefaults.standardUserDefaults | ||
RemoteModule::RemoteModel.set_access_token(defaults["FBAccessTokenKey"]) | ||
|
||
@activity = UIActivityIndicatorView.alloc.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleGray) | ||
self.view.addSubview @activity | ||
@activity.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2) | ||
@activity.startAnimating | ||
|
||
@user.find_friends do |user| | ||
@activity.stopAnimating | ||
@activity.removeFromSuperview | ||
self.tableView.reloadData | ||
end | ||
end | ||
|
||
def tableView(tableView, numberOfRowsInSection:section) | ||
return @user.friends.count | ||
end | ||
|
||
def tableView(tableView, cellForRowAtIndexPath:indexPath) | ||
reuseIdentifier = "FriendCell" | ||
|
||
cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) || begin | ||
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:reuseIdentifier) | ||
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton | ||
cell | ||
end | ||
|
||
friend = @user.friends[indexPath.row] | ||
cell.textLabel.text = friend.name | ||
cell.detailTextLabel.text = friend.id | ||
|
||
cell | ||
end | ||
|
||
def tableView(tableView, didSelectRowAtIndexPath:indexPath) | ||
tableView.deselectRowAtIndexPath(indexPath, animated:true) | ||
friend = @user.friends[indexPath.row] | ||
|
||
UIApplication.sharedApplication.delegate.navigationController.pushViewController(FriendsController.alloc.initWithUser(friend), animated: true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule BubbleWrap
updated
7 files
+1 −0 | .gitignore | |
+10 −0 | README.md | |
+5 −0 | lib/app.rb | |
+11 −3 | lib/http.rb | |
+13 −1 | lib/kernel.rb | |
+7 −0 | lib/ui_button.rb | |
+11 −0 | lib/ui_view_controller.rb |