-1

I am trying to use MDCSnackBar on my app.

It works well on iOS 12 simulator but the snack bar is not appearing on my phone (iOS 13). I also tried to run the app on a 13.4 simulator and the result is the same

This is how I use MDCSnackBar

func showSnackBar(messageText: String){
    let message = MDCSnackbarMessage()
    message.duration = 1
    message.text = messageText
    MDCSnackbarManager.show(message)
}

Any help, please?

Vikram Parimi
  • 777
  • 6
  • 29
DragonNest
  • 11
  • 2
  • Just to be clear, I use Swift 5 with XCode 11. And my app has SceneDelegate in it – DragonNest May 13 '20 at 05:03
  • This might help someone in future: For me adding "window = UIWindow(frame: UIScreen.main.bounds)" in to AppDelegate's "didFinishLaunchingWithOptions" method for iOS 13 and above, created this issue. – patel dhruval Dec 06 '21 at 20:04

1 Answers1

1

I used the below podfile to install the MDCSnackBar .

use_frameworks!
platform :ios, '12.0'

install! 'cocoapods'

target 'podSnack' do
  use_frameworks!
  pod 'MaterialComponents/Snackbar','109.2.0'
end

Code to display MDCSnackBar

import UIKit
import MaterialComponents.MaterialSnackbar


class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func showAlert(){
        let message = MDCSnackbarMessage()
        message.duration = 1
        message.text = "The groundhog (Marmota monax) is also known as a woodchuck or whistlepig."
         MDCSnackbarManager.show(message)
    }
}

Output in iOS simulator 13.3

  • Hi, thank you for your help. I tried your solution; it was work when I try on a different project. But still didn't work on my project. So I decided to rebuild my app (I copy-paste the files) into a new one, and your solution comes to work. – DragonNest May 28 '20 at 05:12