Tuesday, October 25, 2011

Mad Pig Klondike version 1.1 in development. Update 2

Finished working on the next release of Mad Pig Klondike Solitaire.
Added Facebook posting and implemented analytics for the new features.


--- Version 1.1 - Testing Pre-release.

  • Post App Store link, info and player comments to Facebook. You can now tell your friends about Mad Pig Klondike.
  • Post Screenshot of results page to Facebook. You can now post your awesome scores.
  • Bottom corner buttons for Options and New Game only work when touch starts on them. Drag release over them will no longer envoke the buttons.
  • Separated touch areas for New Game and Yes dialog so a quick double tap will not start a new game.
  • Added Game mode to Results Screen. Now your screen shots will show the game type! 

I implemented two buttons for posting to Facebook. One on the menu to post user comment, with App Store link to Mad Pig Klondike Solitaire. The second button is on the end game score results page for posting a screen shot of the results to Facebook. 

I had to implement each type of post differently. 

Facebook Post from the menu:
When the button is touched, it calls a method that first checks for internet reachability. I've used Apple's reachability code here. Any app that doesn't have some testing of internet connection and handling of issues will be rejected by Apple. So any time Klondike tries to connect to the internet, the app checks first. 

If Klondike can reach the internet, it then checks to see if there is a previously saved Facebook session. Klondike saves a session after a successful log in to Facebook. The saving of the session allows SSO (single sign on). I'm using the newer Facebook SDK. With the old one, the user would have to log in each time they post. Not very user friendly. If there is a saved session, Klondike calls a method to post a dialog to Facebook. The dialog will post an icon, app link, description, and any text the user wants to add.

The tricky part is if there isn't a saved session. If there isn't, Klondike sends the user to log in to Facebook and requests permissions to post to the feed. Then the Facebook app returns to Klondike. Originally, I had the post method being called right after the authorization. This caused problems because the post would get called before Facebook was done. The post would fail and sometimes it would cause odd things to happen.  To get around this, I set a flag that a dialog type post needs to be posted. Then when Facebook is done with the login, Facebook calls it's delegate method for didLogin. In didLogin, I check the flag for dialog post and if it's YES, I call the post method. This solved the failed posts and odd behaviors. 

I had to do a similar thing for the other Facebook button. For posting a screen shot, I bring up an Alert dialog to ask the user if they want to post a screen shot to Facebook. This teaches the user what the button does and let's them back out of it if they want. The alert is using a delegate to handle the user selecting YES. If the user selects YES, the corresponding delegate method gets fired off. This method is in my AppDelegate. I couldn't get it to work in my Facebook class.  The method sets a flag for posting a screen shot to YES and calls a method to check reachability and then if the session is valid. Also, the Facebook button on the screen is disabled do the user can't post duplicate images. If the session is valid, it will post an image to the user's feed using a Post request. If the session is not valid, it will send the user to login and asks for permissions to post to the feed. Once again, it will return and call the didLogin method. 

In the didLogin method, I check to see if the post screen shot  flag is YES. If it is, I then call the method that does a screenshot and posts it to Facebook. I call this method with a .2 second delay because if I call it immediately, the screenshot is really messed up. It's a double image, cropped. I'm guessing it didn't have time to draw properly before the method was called. Adding the small delay fixed it. 

For the first time a user posts to Facebook from the menu page, it fails on the first post after the user gives the app permissions. I can't figure out why it fails or how to truly fix it. Instead I try to post on the error/fail and this works. It's a really odd behavior, but only happens the first time. 

Originally, I was able to get the posting of both types to work nicely once a user is logged in and thought everything was working great. Then I tested having the user not logged in and then I tested removing the app from Facebook and basically having the initial experience of the user. The initial experience was rough and had issues. Even though it would only rarely affect the user, we want our user experience to be smooth. Therefore, I had to jump through all the above mentioned coding hoops to get this stuff to work nicely. 

The good news, I'm learning about delegates. The bad, is it took much more time that I had wanted it to and I'm kinda hacking the solution.

Looking to the future, it looks like I might have an easier time when I implement Twitter, due to Apple including a nice library in iOS 5. Hopefully it will be. 



No comments:

Post a Comment