Skip to content

Commit

Permalink
#5 Adds support for server version 0.1.1
Browse files Browse the repository at this point in the history
* #5 Adds support for server version 0.1.1 while maintaining support for v0.1.0

* #5 Removes print used for debugging
  • Loading branch information
OttoFI authored Jul 9, 2021
1 parent f44426b commit 4b9c9f1
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 27 deletions.
6 changes: 4 additions & 2 deletions babyProject/babyProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,14 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = LS85FFZ453;
INFOPLIST_FILE = babyProject/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = fi.turkuforge.babyProject;
PRODUCT_BUNDLE_IDENTIFIER = fi.turkuforge.babyproject;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
Expand All @@ -410,13 +411,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = LS85FFZ453;
INFOPLIST_FILE = babyProject/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = fi.turkuforge.babyProject;
PRODUCT_BUNDLE_IDENTIFIER = fi.turkuforge.babyproject;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down

This file was deleted.

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.
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.
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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
"size" : "20x20"
},
{
"filename" : "Icon-29.png",
"filename" : "BabyProjectLogo-29.png",
"idiom" : "iphone",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "Icon[email protected]",
"filename" : "BabyProjectLogo[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "Icon[email protected]",
"filename" : "BabyProjectLogo[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "Icon[email protected]",
"filename" : "BabyProjectLogo[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "Icon[email protected]",
"filename" : "BabyProjectLogo[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
Expand Down Expand Up @@ -67,21 +67,25 @@
"size" : "20x20"
},
{
"filename" : "BabyProjectLogo-30.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "BabyProjectLogo-41.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
Expand All @@ -99,11 +103,13 @@
"size" : "76x76"
},
{
"filename" : "BabyProjectLogo-83,5-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "BabyProjectLogo-1025.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 20 additions & 1 deletion babyProject/babyProject/Data/CustomData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,26 @@ struct bpRootResponse: Codable {
struct bpEmbedded: Codable {
let channelList: [bpChannel]

enum CodingKeys: String, CodingKey {
enum CodingKeysOld: String, CodingKey {
case channelList = "bp:channelList"
}

enum CodingKeysNew: String, CodingKey {
case channelList = "bp:channel"
}

init(from decoder: Decoder) throws {
let containerOld = try decoder.container(keyedBy: CodingKeysOld.self)
let containerNew = try decoder.container(keyedBy: CodingKeysNew.self)

if let decodedChannelList = try containerOld.decodeIfPresent([bpChannel].self, forKey: CodingKeysOld.channelList) {
channelList = decodedChannelList
} else if let decodedChannelList = try containerNew.decodeIfPresent([bpChannel].self, forKey: CodingKeysNew.channelList) {
channelList = decodedChannelList
} else {
throw DecodingError()
}
}
}

struct bpChannelList: Codable {
Expand Down Expand Up @@ -91,3 +108,5 @@ struct RecivedMessage: Codable {
message = dict["message"] as? String ?? ""
}
}

struct DecodingError: Error {}
4 changes: 3 additions & 1 deletion babyProject/babyProject/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Baby Project</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -17,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
Expand Down
11 changes: 9 additions & 2 deletions babyProject/babyProject/Views/ChannelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ class ChannelViewController: MessagesViewController, MessagesDataSource, Message
var channel: bpChannel?

var socketClient = StompClientLib()
// Currently hardcoded url, due to issues with API outputting two identical JSON fields `_links`
lazy var url = NSURL(string: "https://api.turkuforge.fi/connect/websocket")!
lazy var url = { () -> NSURL in
if let safeSockjsEndpoint = GlobalValues.sockjsEndpoint {
// Currently adding "/websocket" to bypass the need to first fetch sockjsEndpoint and then connect to a new link given in the response
return NSURL(string: "\(safeSockjsEndpoint)/websocket")!
} else {
// Currently hardcoded url, due to issues with API outputting two identical JSON fields `_links`
return NSURL(string: "https://api.turkuforge.fi/connect/websocket")!
}
}()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
15 changes: 10 additions & 5 deletions babyProject/babyProject/Views/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import UIKit
import Combine

struct GlobalValues {
static var rootUrl = "https://api.turkuforge.fi"
static var sockjsEndpoint: URL?
}

class ViewController: UIViewController {

@IBOutlet weak var channelCollection: UICollectionView!
Expand All @@ -25,20 +30,20 @@ class ViewController: UIViewController {
}
}
var result: bpRootResponse?
let rootURL = "https://api.turkuforge.fi"

override func viewDidLoad() {
super.viewDidLoad()
preventLargeTitleCollapsing()

let url = URL(string: rootURL)!
let url = URL(string: GlobalValues.rootUrl)!
self.cancellable = URLSession.shared.dataTaskPublisher(for: url)
.map { $0.data }
.decode(type: bpRootResponse.self, decoder: JSONDecoder())
.eraseToAnyPublisher()
.sink(receiveCompletion: { print ("Received completion: \($0).") },
receiveValue: { response in self.channels = response.embedded.channelList
print("here is self channel first ______ \(response)")
.sink(receiveCompletion: { _ in },
receiveValue: { response in
self.channels = response.embedded.channelList
GlobalValues.sockjsEndpoint = response.links.sockJsEndpoint?.href
})
}

Expand Down

0 comments on commit 4b9c9f1

Please sign in to comment.