Added writing to file.
Merged
Porting to iOS 8.1