Code Monkey home page Code Monkey logo

donateviewcontroller's Introduction

DonateViewController

License Issues Pull Requests Code Size CodeFactor Open Source Helpers

A view controller to make donations.

Installation

Add https://github.com/GroupeMINASTE/DonateViewController.git to your Swift Package configuration (or using the Xcode menu: File > Swift Packages > Add Package Dependency)

Usage

โš ๏ธ You need to register your in app purchases in App Store Connect to make it work. The name and the price of purchases will be used.

First, import the package in your view controller where you want to open the DonateViewController.

// Import the package
import DonateViewController

Create a method to open it:

// Import the package
import DonateViewController

class MyViewController: UIViewController {

    // Some code...

    func openDonateViewController() {
        // Create the view controller
        let controller = DonateViewController()
        
        // Customize view title, header and footer (optional)
        controller.title = "Donate"
        controller.header = "Select an amount to donate:"
        controller.footer = "The donations help us to improve our projects (...)"
        
        // Add a delegate to get notified when a donation ends
        controller.delegate = self
        
        // Add donations
        controller.add(identifier: "my.app.identifier.mydonation1")
        controller.add(identifier: "my.app.identifier.mydonation2")
        // ... (add as many donations as you want)
        
        // And open your view controller: (two ways)
        
        // 1. In your navigation controller
        navigationController?.pushViewController(controller, animated: true)
        
        // 2. In a modal
        present(UINavigationController(rootViewController: controller), animated: true, completion: nil)
    }

    // Some code...

}

Then you need to implement the DonateViewControllerDelegate protocol to get notified when a donation ends:

// Import the package
import DonateViewController

class MyViewController: UIViewController, DonateViewControllerDelegate { // Add the protocol to the view controller

    // Some code...
    
    // The method we just created (no changes)
    func openDonateViewController() {
        // ...
    }
    
    // Implement delegate methods
    
    func donateViewController(_ controller: DonateViewController, didDonationSucceed donation: Donation) {
        // Handle when the donation succeed
        
    }
    
    func donateViewController(_ controller: DonateViewController, didDonationFailed donation: Donation) {
        // Handle when the donation failed
        
    }
    
    // Some code...

}

You can show a UIAlertController with a little message for exemple.

And call the openDonateViewController() method when you want to open the DonateViewController:

self.openDonateViewController()

This can be called when the user clicks on a UIButton (in the selector method) or when the user selects a table view cell.

That's all, you're ready to receive donations!

Customize colors for theming (iOS < 13)

Before iOS 13, no dark theme was implemented in controllers. If you want to implement your custom dark theme, subclass DonateViewController and DonateCell to change the colors of the views. (background, ...)

Donate to the developer

Feel free to make a donation to help the developer to make more great content! Donate now

donateviewcontroller's People

Contributors

nathanfallet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.