How to use an AVAudioPlayer in iOS with Swift 5

import AVFoundation

var player: AVAudioPlayer?


let url = Bundle.main.path(forResource: "richtig", ofType: "wav")
do {
    try AVAudioSession.sharedInstance().setMode(.default)
    try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
    guard let url = url else {
        return
    }
    player = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: url))
} catch {
    print("Something went wrong")
}

@IBAction func playButton(_ sender: Any) {
    guard let player = player else {
    return
    }
    if player.isPlaying {
        player.stop()
    }
    else {
        player.play()
    }
}

Create an iOS 12 compatible app with Xcode 12

To make an app downwards compatible do the follwing

  • Change deployment target to iOS 12
  • Remove the methods in AppDelegate.swift
  • Add var window: UIWindow?
  • Remove SceneDelegate.swift
  • Remove the entry Application Scene Manifest in the info.plist.

Developing for iOS 14 with Xcode 12.4

Oh boy, Apple….

I’m still running macOS 10.15.7 Catalina on my Mac due to different reasons. My iPhone is already up to date on iOS 14.5.

That means my Mac can only run Xcode 12.4 which makes it incompatible with my iPhone for development. But there is a way.

DeviceSupport files

You need an additional DeviceSupport file. Do the following:

  • Close Xcode
  • Go to https://github.com/filsv/iPhoneOSDeviceSupport
  • Download the matching zip in my case 14.5
  • Unzip the archive
  • Copy the folder to
    • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/
  • Start Xcode

 

Debunking 3 iOS Development Myths

Let’s debunk some myths about iOS development:

Myth #1 – You need to code Objective-C

False – since 2014 you have an alternative: Swift. This language is open source under the Apache License 2.0 (since Swift 2.2) and even runs on Linux

Myth #2 – You need to be enrolled in the Apple Developer Program

False – To develop your app and test it on your own device you just need to have an Apple ID which You likely already have if you’ve ever purchased something in the iTunes or app store.

Side note: If you are looking forward to integrate Siri or Wallet or iCloud into your own app you’ll have to pay. Bummer 🙁

Myth #3 – You need to own a Mac (iMac, Mac Book, Mac Pro)

In theory yes, because you have to run XCode which is only available on Mac OS X. But wait: What if I run Mac OS X elsewhere? You can use a VMWare or Virtual Box as well or even build your own hackintosh.

 

 

My first iPhone App

After carrying around my iPhone 6 for two and a half years I finally wanted to know how to build an iOS app.

Getting started

I used this tutorial from apple and rolled with the punches:

Installing XCode

takes ages!  Download 4,6 GB 🙁

First issue: when accidentally making the wrong connection between a UI-Element and the ViewController (@IBOutlet instead of @IBAction) You have to remove the connection in the code _and_ in the storyboard via context menu.

First own app

After I was done with the tutorial I wrote an app I always wanted to write:

A music player app to make learning songs easy. Use case: You want to learn a solo from e.g. Metallica’s “Nothing else matters” and You want to play along the music.

Requirements so far:

Continue reading “My first iPhone App”