Game-of-whales / GOW-SDK-IOS

Game of Whales iOS SDK
http://www.gameofwhales.com
MIT License
0 stars 0 forks source link

How do i get my coins to save if the user closes the app? #1

Closed dehhaker closed 6 years ago

dehhaker commented 6 years ago

import UIKit import GoogleMobileAds import MessageUI

class HomeViewController: UIViewController, GADRewardBasedVideoAdDelegate, MFMailComposeViewControllerDelegate{

@IBOutlet weak var showAdButton: UIButton!
@IBOutlet weak var coinCountLabel: UILabel!
 @IBOutlet weak var stop: UILabel!

var rewardBasedAd: GADRewardBasedVideoAd!
var rewardBasedAdRequestInProgress = false

@IBAction func SendEmailButtonTapped(_ sender: Any) {
    if coinCount == 100000{

    let mailComposeViewController = configuredMailComposeViewController()
    if MFMailComposeViewController.canSendMail() {
        self.present(mailComposeViewController, animated: true, completion: nil)
    } else {
        self.showSendMailErrorAlert()
    }
    }else{
        let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
        self.addChildViewController(popOverVC)
        popOverVC.view.frame = self.view.frame
        self.view.addSubview(popOverVC.view)
        popOverVC.didMove(toParentViewController: self)

    }

}

func configuredMailComposeViewController() -> MFMailComposeViewController {
    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property

    mailComposerVC.setToRecipients(["Robunr47@gmail.com"])
    mailComposerVC.setSubject("Hi, I earned 100,000")
    mailComposerVC.setMessageBody("Congrats on earning 100,000 coins! I'm Proud of you. Pleas share and rate this app. I will get back to you in 48-72 hours with your amazon code :)", isHTML: false)

    return mailComposerVC
}

func showSendMailErrorAlert() {
    let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail.  Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
    sendMailErrorAlert.show()
}

// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}
var coinCount = 0

override func viewDidLoad() {
 super.viewDidLoad()

    createAndLoadRewardBasedVidoeAd()

    showAdButton.isEnabled = false

}
@IBOutlet weak var textf: UITextField!
@IBAction func Reedem(_ sender: Any) {
}

fileprivate func earnCoins(_ coins: NSInteger) {
    coinCount += coins
    coinCountLabel.text = "Coins: \(self.coinCount)"
    save()

}

    func save() {

                }

    fileprivate func createAndLoadRewardBasedVidoeAd(){
    rewardBasedAd = GADRewardBasedVideoAd.sharedInstance()
    rewardBasedAd.delegate = self

    if !rewardBasedAdRequestInProgress && rewardBasedAd.isReady == false {
    rewardBasedAd.load(GADRequest(),
                       withAdUnitID: "ca-app-pub-4477422135070128/2664511468")
        coinCountLabel.text = "Coins: \(self.coinCount)"

rewardBasedAdRequestInProgress = true }

}
@IBAction func buttonPressed(_ sender: Any) {
    showAdButton.isEnabled = false
    if rewardBasedAd.isReady == true{
        rewardBasedAd.present(fromRootViewController: self)
    } else {

    }
    createAndLoadRewardBasedVidoeAd()
}

func rewardBasedVideoAdDidOpen(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {

    print("An ad opened.\n")
}
func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    rewardBasedAdRequestInProgress = false
    print("An ad closed.\n")

}
func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {

   print("An ad has loaded.\n")
    showAdButton.isEnabled = true

}
func rewardBasedVideoAdDidStartPlaying(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
   showAdButton.isEnabled = true
   print("An ad started playing.\n")
}
func rewardBasedVideoAdWillLeaveApplication(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
   print("An ad caused focus to leave.\n")
}
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
                        didFailToLoadWithError error: Error) {
     rewardBasedAdRequestInProgress = false
    print("An ad failed to load.\n")
    showAdButton.isEnabled = true
}
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,didRewardUserWith reward: GADAdReward) {
    print("Reward received with currency: \(reward.type), amount \(reward.amount).")
    earnCoins(NSInteger(truncating: reward.amount))

}

}

maxkushnir84 commented 6 years ago

Hi @dehhaker, Can you please show us your implementation of the GOW SDK in your project,it will help us to better understand your issue and assist in the implementation process

Max

dehhaker commented 6 years ago

Hi nice to meet you. I have not implemented the GOW SDK yet. I only implemented the google ads sdk. And i got my coins to show and all that good stuff. The only problem is idk how to save the coins. And i dont want to change anything unless its necessary but here you go

On Nov 20, 2017 9:34 AM, "maxkushnir84" notifications@github.com wrote:

Hi, Can you please show us your implementation of the GOW SDK in your project,it will help us to better understand your issue and assist in the implementation process

Max

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Game-of-whales/GOW-SDK-IOS/issues/1#issuecomment-345731016, or mute the thread https://github.com/notifications/unsubscribe-auth/AKIVHOtT6Hnhduq9xPWQk1PotLqTIJAIks5s4ZuogaJpZM4Qju_A .