Author Topic: Ch 16: Adopting In-App Purchases  (Read 4349 times)

ssamadgh

  • Newbie
  • *
  • Posts: 2
    • View Profile
Ch 16: Adopting In-App Purchases
« on: March 26, 2016, 02:09:02 AM »
with releasing Xcode 7.3 codes of Tic Tac Toe had many errors, Please Update it. or guide what must we do ?

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: Ch 16: Adopting In-App Purchases
« Reply #1 on: July 04, 2016, 07:02:57 PM »
I believe the errors you are referring to in the TicTacToe project are located in the TicTacToe.swift file and the InAppPurchaseManager.swift file. The first 4 issues, which are in the playerMove: method and the numberOfMovesInMatrixRow: method of the TicTacToe.swift file, read as, “++ is deprecated; it will be removed in Swift 3.” There are 6 issues in the buildErrorMessage: method of the InAppPurchaseManager.swift file and have to do with an update to the StoreKit constants syntax.  Finally, you’ll have to update the App Groups section under the Capabilities tab by removing the current app group listed and adding a new one with your company name.  I’ve corrected these issues and listed the updated code below. 

Update the playerMove: method and the numberOfMovesInMatrixRow: method in the TicTacToe.swift file by replacing the ++ statements with the underlined statements below.

// Check if game is over
        self.isGameOver = (moves.count == 9) || playerWins
       
        if self.isGameOver {
            // Check for a tie
            if moves.count == 9 && !playerWins {
                self.winnerName = NSLocalizedString("It's a tie!", comment:"A tie game")
                self.winnerMessage = ""
                self.ties += 1
            }
            else {
                if self.currentPlayerMark == "X" && Settings.sharedInstance.player1Mark == "X" {
                    self.player1Wins += 1
                    let winText = Settings.sharedInstance.player1Name.lowercaseString == "you"
                        ? NSLocalizedString("Win!", comment: "Singular win")
                        : NSLocalizedString("Wins!", comment: "Plural win")
                   
                    self.winnerName = Settings.sharedInstance.player1Name + " " + winText
                   
                    self.winnerMessage = ""
//                    let streakMessage = NSLocalizedString("game streak!", comment: "winning streak")
                }
                else {
                    self.player2Wins += 1
                    self.winnerName = Settings.sharedInstance.player2Name + " Wins!"
                }
               
            }


func numberOfMovesInMatrixRow(matrixRow: Matrix) -> Int {
        var moveCount = 0
        let positions = self.matrix[matrixRow]!
        for position in positions {
            if self.moves.contains(Move(position: position, mark: "XO")) {
                moveCount += 1
            }
        }
        return moveCount
    }


Update the buildErrorMessage: method in the InAppPurchaseManager.swift file as follows:

// Builds an error message from the NSError object
    func buildErrorMessage(error: NSError) -> String? {
       
        var message: String?
       
        if error.code != SKErrorCode.PaymentCancelled.rawValue && error.code != SKErrorCode.PaymentNotAllowed.rawValue {
           
            switch error.code {
            case SKErrorCode.Unknown.rawValue, SKErrorCode.ClientInvalid.rawValue:
                message = NSLocalizedString("This action is not allowed.", comment: "")
            case SKErrorCode.PaymentInvalid.rawValue:
                message = NSLocalizedString("Invalid Payment.", comment: "")
                break
            case SKErrorCode.StoreProductNotAvailable.rawValue:
                message = NSLocalizedString("Product not available.", comment: "")
                break
            default:
                break
            }
        }

        return message
    }


In the Capabilities tab under the App Groups section, remove the check in the App Groups checkbox next to “group.com.oakleafsd.TicTacToe” and click the + sign to add a new group using the format, group.com.mycompanyname.TicTacToe.  Replace “mycompanyname” with the same name you used in your bundle identifier.


Angelina
Oak Leaf Enterprises, Inc.