What’s New in iOS 9.3

iOS-120With this update your iPhone, iPad and iPod touch gain improvements to Notes, News, Health, Apple Music and a new feature called Night Shift that may even help you get a better night’s sleep by shifting the colors in your display to the warmer end of the spectrum at night.

Continue reading





Health Update

Dear friends,

I have some bad news I feel I must share with you: earlier this year I was diagnosed with colon cancer. I’ve spent most of February in hospital for two major operations to remove several tumours and fistulas, and I’m waiting for chemo and radiotherapy to start. The surgery alone has put a major strain on my body and my mind, and I’m not sure how I will react to the next few months of treatment.

This means that I will not be able to write as much content here as I have in the past, if I can produce any content at all. I know this sucks for you as much as it does for me. I’ve been battling with this disease since last year without knowing what it was at that time, and this is reflected in the reduced number of articles I’ve written in 2015.

I will let you know as soon as I feel better, but I fear that it will take the remainder of this year (2016) until I’m whipped back into shape. I have wonderful doctors who look after me, and good health insurance too, who have so far covered all expenses of this distasteful affair. Thank god for that!

If you feel that you’ve been “cheated out of your membership”, please contact me and we’ll work something out. If you need alternatives for learning iOS development, please look into the likes of Lynda.com and Pluralsight.com, who update much more frequently than I ever could. At the same time, they charge you more per month than what I’m asking for in a year to cover the cost of hardware and hosting. And: they’re professional teachers, whereas I am hobbyist hacker.

Thank you for your understanding, and thank you for your loyal support.

All the best, and Happy Hacking,

 

JAY





How to play videos in iOS 9

Until iOS 8 we could use the trusty old MPMoviePLayerViewController class to play videos on our devices, but that’s been deprecated in iOS 9. From now on, Apple recommend we use the AVPlayerViewController class instead. It has many advantages and even supports picture-in-picture out of the box.

Although AVPlayerViewController is a subclass of UIViewController, instances of it cannot be presented using presentViewController – but Apple make sure not to mention this little tidbit. It’s much more “fun” to figure this out on our own.

Here’s how we can use it with a local video from the main bundle:

@import AVFoundation;
@import AVKit;

// ...

// grab a local URL to our video
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@"video" withExtension:@"mp4"];

// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];

// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];

// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;

First we grab a URL to either a local or remote video. Next we create an AVPlayer with this URL, and add said player to the newly created AVPlayerViewController instance. You can auto-play a video by using the player’s play method, or remove it and leave it up to the user to start the video.

Next we’ll present the controller by adding it as a subview to our current view, making sure it has the same frame size.

The class works equally well with local and remote URLs. To play a remote asset, construct the URL like this:

NSURL *videoURL = [NSURL URLWithString:@"https://github.com/versluis/Movie-Player/blob/master/Movie%20Player/video.mov?raw=true"];




What’s new in iOS 9.2

This update contains improvements and bug fixes including:

Apple Music improvements

  • You can now create a new playlist when adding a song to a playlist
  • Your most recently changed playlist is now listed at the top when adding songs to playlists
  • Download albums or playlists from your iCloud Music Library by tapping the iCloud download button
  • See which songs have been downloaded with the new download indicator next to each song in My Music and Playlists
  • See works, composers, and performers while browsing Classical music in the Apple Music catalog

General improvements

  • A new Top Stories section in News so you can stay up to date with the most important news of the day (available in the United States, United Kingdom, and Australia)
  • Mail Drop in Mail for sending large attachments
  • iBooks now supports 3D Touch to peek and pop pages from the table of contents, your notes and bookmarks, or from search results inside a book
  • iBooks now supports listening to an audiobook while you browse your library, read other books, or explore the iBooks Store
  • iPhone support for the USB Camera Adapter to import photos and videos
  • Improved stability of Safari
  • Improved stability of Podcasts
  • Fixing an issue that caused mail attachments to be inaccessible for some users with POP email accounts
  • Resolving an issue for some users that caused attachments to overlap text in mail
  • Fixing an issue where Live Photos could have turned off after restoring from a previous iCloud backup
  • Addressing an issue that could cause search in Contacts to display no results
  • Resolving an issue that could have prevented Calendar from displaying all seven days in week view
  • Fixing an issue where Camera screen on iPad could be black when attempting to capture video
  • Addressing an issue that could cause instability in the Activity app when viewing the day of Daylight Savings Time transition
  • Fixing an issue that could prevent data from appearing in Health
  • Fixing an issue that could prevent Wallet updates and Lock screen alerts from displaying
  • Addressing an issue where updating iOS could prevent an alarm from going off
  • Fixing an issue where some users were unable to login to Find my iPhone
  • Fixing an issue that prevented some manual iCloud Backups from completing
  • Addressing an issue where using the iPad keyboard could unintentionally trigger text selection mode
  • Improved keyboard responsiveness when using Quick Reply
  • Improved punctuation input on the 10-key Chinese (Pinyin & Stroke) keyboards with new expanded view of punctuation symbols and better predictions
  • Fixing an issue on Cyrillic keyboards where caps lock would be enabled when typing in URL or email fields

Accessibility improvements

  • Fixing issues with VoiceOver when using Camera face detection
  • Adding support for VoiceOver to wake up the screen
  • Adding support for VoiceOver to invoke app switcher with 3D Touch gesture
  • Fixing an issue with Guided Access when trying to end phone calls
  • Improved functionality for Switch Control users when using 3D Touch
  • Fixing an issue with speech rate of Speak Screen
  • Siri support for Arabic (Saudi Arabia, United Arab Emirates)

For information on the security content of this update, please visit this website:
https://support.apple.com/HT201222





How to use Arrays in Swift

Swift has its own built-in Array class. Although it’s bridged to NSArray, a Swift Array is something entirely different. Swift Arrays do not work with such trusted methods like addObject anymore.

Because I will probably have forgotten most of this by tomorrow, here’s a quick lowdown on how to play with Swift Arrays.

// create an empty array [type in square brackets]
var emptyArray = [String]()

// create an array with inferred values
var array = ["one", "two", "three"]

// loop through the array
for value in array {
    print("The value is \(value)")
}

// insert new value at a particular index
array.insert("two and a half", atIndex: 2)
var value = array[2]

// add something to the end of our array
array += ["new value"]
// or
array.append("another value")

// grab the last entry in our array
value = array.last!

// add another array
let anotherArray = ["four", "five", "six"]
array += anotherArray

// how many entries does our array have?
print(array.count)

// remove the last item in the array
array.removeLast()

// remove an item at a particular index
array.removeAtIndex(3)

Swift Arrays and Lazy Initialisation

Swift Arrays don’t like being initialised with a closure. God only knows why. We can however solve this puzzle with a simple function that returns our initialised values:

    lazy var data: [String] = self.initData()
    
    func initData() -> [String] {
        
        // initialize data array and return it
        var data = [String]()
        
        let formatter = NSNumberFormatter()
        formatter.numberStyle = .SpellOutStyle
        
        for var i = 0; i < 30; i++ {
            let number = NSNumber.init(integer: i)
            data.append(formatter.stringFromNumber(number)!)
        }
        return data
    }

For everything else about Swift Arrays, check out the Collection Types section of The Swift Programming Language:





How to fix “no rule to process file” warning in Xcode

The other day Xcode was trying to tell me that it had “no rule to process a file”. It was a simple readme file that I had created on GitHub and subsequently pulled into my working copy.

Even though the project compiled fine, if there is a warning we can eliminate, we definitely should. Turns out it’s easy fix this problem.

Click on your project in the Project Navigator (the blue item on the left where you see all your project files), then head over to Build Phases. You’ll find a section called Compiled Sources. Expand it to see a selection of files.

Select the one Xcode is complaining about and remove it by clicking the little minus sign at the bottom.

Screen Shot 2015-12-09 at 12.51.27

Build the project again and see that warning disappear for good.