Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Upgrade to swift 3 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions MeatChat/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
Expand Down Expand Up @@ -34,6 +44,16 @@
"filename" : "[email protected]",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
Expand Down
12 changes: 6 additions & 6 deletions MeatChat/MCAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ class MCAppDelegate : UIResponder, UIApplicationDelegate {

var window:UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
} catch {
print(error)
}

let defaultDefaults = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("DefaultDefaults", ofType: "plist")!) as? Dictionary<String,AnyObject>
NSUserDefaults.standardUserDefaults().registerDefaults(defaultDefaults!)
let defaultDefaults = NSDictionary(contentsOfFile: Bundle.main.path(forResource: "DefaultDefaults", ofType: "plist")!) as? Dictionary<String,AnyObject>
UserDefaults.standard.register(defaults: defaultDefaults!)

return true
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
if let nc=self.window?.rootViewController as? UINavigationController {
if let vc=nc.topViewController as? MCPostListViewController {
vc.postViewController?.closePostWithPosted(false)
}
}
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
if let nc=self.window?.rootViewController as? UINavigationController {
if let vc=nc.topViewController as? MCPostListViewController {
vc.resumePlay()
}
}
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
if let nc=self.window?.rootViewController as? UINavigationController {
if let vc=nc.topViewController as? MCPostListViewController {
vc.flushItems()
Expand Down
39 changes: 20 additions & 19 deletions MeatChat/MCPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,59 @@

import Foundation
import UIKit
import DateToolsSwift

class MCPost :NSObject {

var postData: [String : AnyObject]
var attributedString : NSAttributedString;
var videoUrl : NSURL;
var videoUrl : URL;
var created :Int;
var fingerprint :String;


init(dict: NSDictionary ) {
self.postData = dict.dictionaryWithValuesForKeys(["message","created"])
self.postData = dict.dictionaryWithValues(forKeys: ["message","created"]) as [String : AnyObject]
self.created = (dict["created"] as? Int)!
self.fingerprint = (dict["fingerprint"] as? String)!
self.attributedString=NSAttributedString()
let media: String = (dict["media"]!.substringFromIndex(22) as String)
self.videoUrl=NSURL()
let media: String = ((dict["media"]! as AnyObject).substring(from: 22) as String)
self.videoUrl=URL(string: "")!
super.init()
self.setAttributedBody()
let videoData: NSData = NSData(base64EncodedString: media, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)!
videoData.writeToURL(self.path()!, atomically: false)
let videoData: Data = Data(base64Encoded: media, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)!
try? videoData.write(to: self.path()!, options: [])
self.videoUrl = self.path()!
do {
try self.videoUrl.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey)
try (self.videoUrl as NSURL).setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
} catch {
print(error)
}
return
}

func path() -> NSURL? {
func path() -> URL? {

let fileManager = NSFileManager.defaultManager()
let fileManager = FileManager.default

let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)

let documentDirectory: NSURL = urls.first!
let finalPath = documentDirectory.URLByAppendingPathComponent(String(self.created)+".mp4")
let documentDirectory: URL = urls.first!
let finalPath = documentDirectory.appendingPathComponent(String(self.created)+".mp4")
return finalPath
}



func relativeTime() -> String {
let epoch: NSTimeInterval = Double(created)/1000
let postDate: NSDate = NSDate(timeIntervalSince1970: epoch)
return postDate.dateTimeAgo()
let epoch: TimeInterval = Double(created)/1000
let postDate: Date = Date(timeIntervalSince1970: epoch)
return postDate.timeAgoSinceNow
}

func cleanup() {
do {
try NSFileManager.defaultManager().removeItemAtURL(self.path()!)
try FileManager.default.removeItem(at: self.path()!)
} catch {
print(error)
}
Expand All @@ -79,10 +80,10 @@ class MCPost :NSObject {


do {
let string:NSMutableAttributedString = try NSMutableAttributedString(data: html.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding ], documentAttributes: nil)
string.addAttribute(NSBackgroundColorAttributeName, value: UIColor.whiteColor(), range: NSMakeRange(0,string.length))
let string:NSMutableAttributedString = try NSMutableAttributedString(data: html.data(using: String.Encoding.utf8)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 ], documentAttributes: nil)
string.addAttribute(NSBackgroundColorAttributeName, value: UIColor.white, range: NSMakeRange(0,string.length))
string.addAttribute(NSForegroundColorAttributeName, value: UIColor(white: 0.23, alpha: 1.0), range: NSMakeRange(0,string.length))
string.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(17), range: NSMakeRange(0,string.length))
string.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 17), range: NSMakeRange(0,string.length))
string.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0,string.length))
self.attributedString=string

Expand Down
10 changes: 5 additions & 5 deletions MeatChat/MCPostCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class MCPostCell : UITableViewCell {
override func awakeFromNib() {
self.videoPlayer=AVPlayer();
let layer:AVPlayerLayer=AVPlayerLayer(player: self.videoPlayer)
self.videoPlayer!.actionAtItemEnd=AVPlayerActionAtItemEnd.None
layer.frame=CGRectMake(0, 0, 100, 75);
self.videoPlayer!.actionAtItemEnd=AVPlayerActionAtItemEnd.none
layer.frame=CGRect(x: 0, y: 0, width: 100, height: 75);
layer.videoGravity=AVLayerVideoGravityResizeAspectFill;
self.video?.layer.addSublayer(layer)
}

func playerItemDidReachEnd(notification:NSNotification)
func playerItemDidReachEnd(_ notification:Notification)
{
let p:AVPlayerItem = notification.object as! AVPlayerItem
p.seekToTime(kCMTimeZero)
p.seek(to: kCMTimeZero)
}

}
}
Loading