Skip to content

Commit

Permalink
Merge pull request #2 from nark/master
Browse files Browse the repository at this point in the history
Ftext
  • Loading branch information
ProfDrLuigi authored Apr 1, 2020
2 parents cdc4001 + 20002f3 commit 1966a3a
Show file tree
Hide file tree
Showing 39 changed files with 1,805 additions and 315 deletions.
1 change: 1 addition & 0 deletions Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ github "kishikawakatsumi/KeychainAccess"
github "1024jp/GzipSwift"
github "ashleymills/Reachability.swift"
github "sparkle-project/Sparkle"
github "MessageKit/MessageKit"
2 changes: 2 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
github "1024jp/GzipSwift" "5.1.1"
github "BiAtoms/Socket.swift" "2.4.0"
github "IBM-Swift/BlueRSA" "1.0.35"
github "MessageKit/MessageKit" "3.1.0"
github "ashleymills/Reachability.swift" "v5.0.0"
github "kishikawakatsumi/KeychainAccess" "v4.1.0"
github "krzyzanowskim/CryptoSwift" "1.3.0"
github "nathantannar4/InputBarAccessoryView" "4.3.2"
github "sindresorhus/Preferences" "v1.0.1"
github "sparkle-project/Sparkle" "v1.23.0"
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,22 @@ https://developer.apple.com/library/archive/documentation/ToolsLanguages/Concept

Minimal connection to a Wired 2.0 server:

// import module
import WiredSwfit

// this automatically load P7 and Wired 2.0 specification
let spec = P7Spec()

// the Wired URL to connect to
let url = Url(withString: "wired://guest@locahost:4871")
let url = Url(withString: "wired://192.168.1.23:4871")

// init connection
let connection = Connection(withSpec: spec, delegate: self)
connection.nick = "Me"
connection.status = "Testing WiredSwift"

// perform connect
if self.connection.connect(withUrl: url) {
if connection.connect(withUrl: url) {
// connected
} else {
// not connected
print(self.connection.socket.errors)
print(connection.socket.errors)
}

### Interactive socket
Expand Down
123 changes: 84 additions & 39 deletions Wired iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,106 @@
//

import UIKit
import CoreData
import WiredSwift_iOS
import Reachability

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ConnectionDelegate {
func connectionDidReceiveMessage(connection: Connection, message: P7Message) {
print("connectionDidReceiveMessage: \(message)")
extension UserDefaults {
func image(forKey key: String) -> UIImage? {
var image: UIImage?
if let imageData = data(forKey: key) {
image = try! NSKeyedUnarchiver.unarchivedObject(ofClass: UIImage.self, from: imageData)
}
return image
}

func connectionDidReceiveError(connection: Connection, message: P7Message) {
print("connectionDidReceiveError: \(message)")
func set(image: UIImage?, forKey key: String) {
var imageData: NSData?
if let image = image {
imageData = try! NSKeyedArchiver.archivedData(withRootObject: image, requiringSecureCoding: false) as NSData
}
set(imageData, forKey: key)
}


}


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// this automatically load P7 and Wired 2.0 specification
let spec = P7Spec()

// the Wired URL to connect to
let url = Url(withString: "wired://192.168.1.23:4871")
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
public static let shared:AppDelegate = UIApplication.shared.delegate as! AppDelegate

// init connection
let connection = Connection(withSpec: spec, delegate: self)
connection.nick = "Me"
connection.status = "Testing WiredSwift"
var window:UIWindow?

// perform connect
if connection.connect(withUrl: url) {
// connected

connection.joinChat(chatID: 1)
} else {
// not connected
print(connection.socket.errors)
override init() {
super.init()

// Default preferences
UserDefaults.standard.register(defaults: [
"WSUserNick": "WiredSwift",
"WSUserStatus": "Share The Wealth"
])

if UserDefaults.standard.image(forKey: "WSUserIcon") == nil {
if let image = UIImage(named: "DefaultIcon") {
UserDefaults.standard.set(image: image, forKey: "WSUserIcon")
}
}

return true
UserDefaults.standard.synchronize()
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Logger.setMaxLevel(.INFO)

let splitViewController = window!.rootViewController as! UISplitViewController
splitViewController.preferredDisplayMode = UISplitViewController.DisplayMode.primaryOverlay

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
return true
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "Wired3")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

// MARK: - Core Data Saving support

func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "AccountConnection_Ready.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "AccountConnection_Ready-1.pdf",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "AccountConnection_Ready-2.pdf",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "AccountConnection_Disabled.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "AccountConnection_Disabled-1.pdf",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "AccountConnection_Disabled-2.pdf",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Wired iOS/Assets.xcassets/DefaultUser.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "WiredClient.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "WiredClient-2.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "WiredClient-1.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Wired iOS/Assets.xcassets/Logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "WiredClient-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "WiredClient-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "WiredClient.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 19 additions & 5 deletions Wired iOS/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -11,9 +13,18 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="Logo" translatesAutoresizingMaskIntoConstraints="NO" id="eJW-yg-GBb">
<rect key="frame" x="143" y="384" width="128" height="128"/>
</imageView>
</subviews>
<color key="backgroundColor" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="eJW-yg-GBb" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="GJH-Ry-qma"/>
<constraint firstItem="eJW-yg-GBb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="gkG-QH-qLP"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
Expand All @@ -22,4 +33,7 @@
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<image name="Logo" width="128" height="128"/>
</resources>
</document>
Loading

0 comments on commit 1966a3a

Please sign in to comment.