Skip to content

Commit

Permalink
Show alert on error
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 7, 2013
1 parent be8faac commit db0d54e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 13 additions & 10 deletions app/auto.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Auto
def initialize(type)
def initialize(type, owner)
@type = type
@owner = owner
@account_store = ACAccountStore.alloc.init
@account_type = @account_store.accountTypeWithAccountTypeIdentifier type
end
Expand Down Expand Up @@ -50,26 +51,28 @@ def options
end

def handle_error(error_ptr)
NSLog "*0"
case error_ptr.code
when ACErrorUnknown
NSLog "Error Unknown"
@owner.show_error "Error Unknown"
when ACErrorAccountMissingRequiredProperty
NSLog "Account missing required property"
@owner.show_error "Account missing required property"
when ACErrorAccountAuthenticationFailed
NSLog "Account authentication failed"
@owner.show_error "Account authentication failed"
when ACErrorAccountTypeInvalid
NSLog "Account type invalid"
@owner.show_error "Account type invalid"
when ACErrorAccountAlreadyExists
NSLog "Account already exists"
@owner.show_error "Account already exists"
when ACErrorAccountNotFound
# Occurs if the user has no accounts set up of the particular type
NSLog "Account not found"
@owner.show_error "Account not found"
when ACErrorPermissionDenied
NSLog "User denied permission"
@owner.show_error "User denied permission"
when ACErrorAccessInfoInvalid
NSLog "Access info invalid"
# This may indicate you haven't properly configured the app on Facebook
@owner.show_error "Access info invalid"
else
NSLog "Unknown error code"
@owner.show_error "Unknown error code"
end
end
end
14 changes: 13 additions & 1 deletion app/menu_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def viewDidLoad
"Auto-post to Sina Weibo"
]
self.title = "Social"
# If I don't show an alert here, when I first try to do so later there's a crash. Can't figure out why.
show_error 'Welcome'
end

def tableView(tableView, numberOfRowsInSection:section)
Expand Down Expand Up @@ -41,14 +43,24 @@ def tableView(tableView, didSelectRowAtIndexPath:indexPath)
end
end

def show_error(message)
alert = UIAlertView.alloc.initWithTitle("Error",
message: message,
delegate: self,
cancelButtonTitle: "OK",
otherButtonTitles:nil)
alert.show
end

private

def compose(service)
@composer = Composer.new self, service, "Test post from RubyMotion"
end

def auto(type)
@auto = Auto.new(type)
# pass a reference to the current view controller so we can display error alerts
@auto = Auto.new(type, self)
@auto.post_status "@andyw8 Test post from iOS #{Time.now}"
end
end

0 comments on commit db0d54e

Please sign in to comment.