Skip to content

Instantly share code, notes, and snippets.

@shiningabdul
shiningabdul / IntentHandler.swift
Last active Mar 2, 2020
IntentHandler extension for handling SiriKit requests
View IntentHandler.swift
import Intents
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.
if intent is OrderPizzaIntent {
return OrderPizzaIntentHandler()
}
@shiningabdul
shiningabdul / ViewController.swift
Last active Mar 1, 2020
ViewController that loads an INUIAddVoiceShortcutButton.
View ViewController.swift
import UIKit
import IntentsUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let addShortcutButton = INUIAddVoiceShortcutButton(style: .blackOutline)
let intent = OrderPizzaIntent()
@shiningabdul
shiningabdul / ViewController.swift
Created Oct 8, 2018
Updated view controller to donate shortcut
View ViewController.swift
@IBAction func showButtonTapped(_ sender: Any) {
guard let newMessage = messageField.text else {
return
}
messageLabel.text = newMessage
let intent = IntentManager.shared.intent(withMessage: newMessage)
IntentManager.shared.donateShortcuts(withIntent: intent)
}
View IntentManager.swift
import Foundation
import Intents
class IntentManager {
static let shared = IntentManager()
func intent(withMessage message:String) -> ShowMessageIntent {
let intent = ShowMessageIntent()
intent.message = message
return intent
@shiningabdul
shiningabdul / ViewController.swift
Created Oct 7, 2018
Starting view controller content
View ViewController.swift
class ViewController: UIViewController {
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var messageField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
View UIViewController.swift
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
// Use Stripe to charge the user
STPAPIClient.shared().createToken(with: payment) { (stripeToken, error) in
guard error == nil, let stripeToken = stripeToken else {
print(error!)
return
}
let url = URL(string:"http://localhost:3000/pay")
guard let apiUrl = url else {
View index.js
// Add packages we need
const express = require('express')
const bodyParser = require('body-parser')
var stripe = require('stripe')('YOUR SECRET KEY FROM STRIPE')
// Create an express app
const app = express()
// Use body parser so we can parse the body of requests
app.use(bodyParser.json())
View UIViewController.swift
class UIViewController: UIViewController, PKPaymentAuthorizationViewControllerDelegate {
@objc private func applePayButtonTapped(sender: UIButton) {
// Cards that should be accepted
let paymentNetworks:[PKPaymentNetwork] = [.amex,.masterCard,.visa]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
let request = PKPaymentRequest()
request.merchantIdentifier = "merchant.com.shiningdevelopers"
request.countryCode = "CA"
View UIViewController.swift
import UIKit
import PassKit
import Stripe
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
View AppDelegate.swift
import UIKit
import Stripe
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
You can’t perform that action at this time.