Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading without internet #103

Closed
wants to merge 10 commits into from
Binary file added Bruin Bite.xcodeproj.zip
Binary file not shown.
415 changes: 415 additions & 0 deletions Bruin Bite.xcodeproj/MenuVC.swift

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions Bruin Bite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
770251AE201D4079002E4515 /* Resources */,
D601296F579F59F8E568D410 /* [CP] Embed Pods Frameworks */,
2AFA409F20BBD7A00007FB85 /* Embed App Extensions */,
F938AA584118C90F12FE1731 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -595,6 +596,7 @@
"${BUILT_PRODUCTS_DIR}/FacebookLogin/FacebookLogin.framework",
"${BUILT_PRODUCTS_DIR}/Moya/Moya.framework",
"${BUILT_PRODUCTS_DIR}/Pulsator/Pulsator.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/Repeat/Repeat.framework",
"${BUILT_PRODUCTS_DIR}/Result/Result.framework",
"${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework",
Expand All @@ -612,6 +614,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FacebookLogin.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Moya.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pulsator.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Repeat.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Result.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework",
Expand All @@ -623,6 +626,21 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Bruin Bite/Pods-Bruin Bite-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F938AA584118C90F12FE1731 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Bruin Bite/Pods-Bruin Bite-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
Binary file added Bruin Bite.xcworkspace.zip
Binary file not shown.
15 changes: 11 additions & 4 deletions Bruin Bite/Storyboards/Menu.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="RAT-qB-Fj9">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="RAT-qB-Fj9">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -27,6 +27,12 @@
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<label key="backgroundView" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loading..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Myk-zG-zTM">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="menuCardCell" id="3Wq-Cu-Ohf" customClass="MenuCardCollectionViewCell" customModule="Bruin_Bite" customModuleProvider="target">
<rect key="frame" x="5" y="0.0" width="365" height="214"/>
Expand Down Expand Up @@ -106,7 +112,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fRI-GQ-wjj" userLabel="Allergens View" customClass="AllergensBarScrollView" customModule="Bruin_Bite" customModuleProvider="target">
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fRI-GQ-wjj" userLabel="Allergens View" customClass="AllergensBarScrollView" customModule="Bruin_Bite" customModuleProvider="target">
<rect key="frame" x="0.0" y="548" width="375" height="55"/>
<color key="backgroundColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand Down Expand Up @@ -136,6 +142,7 @@
<connections>
<outlet property="allergensBar" destination="fRI-GQ-wjj" id="VHL-kb-3Yb"/>
<outlet property="backgroundTopBar" destination="DoT-Hh-LNo" id="mh4-dU-Vvb"/>
<outlet property="loadingLabel" destination="Myk-zG-zTM" id="cP1-hH-DIa"/>
<outlet property="menuCardsCollection" destination="H9C-p3-hMb" id="hir-Sr-zQM"/>
<segue destination="G2B-ru-Cr9" kind="show" identifier="segueToItemDetailVC" id="lgn-hs-Vbn"/>
</connections>
Expand Down
96 changes: 92 additions & 4 deletions Bruin Bite/View Controllers/MenuVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,86 @@
import UIKit
import Moya
import SnapKit
import Reachability

class NetworkManager: NSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this class to a new file called NetworkManager.swift under the Helpers folder.


var reachability: Reachability!

// Create a singleton instance
static let sharedInstance: NetworkManager = { return NetworkManager() }()


override init() {
super.init()

// Initialise reachability
reachability = Reachability()!

// Register an observer for the network status
NotificationCenter.default.addObserver(
self,
selector: #selector(networkStatusChanged(_:)),
name: .reachabilityChanged,
object: reachability
)

do {
// Start the network status notifier
try reachability.startNotifier()
} catch {
print("Unable to start notifier")
}
}

@objc func networkStatusChanged(_ notification: Notification) {
// Do something globally here!
}

static func stopNotifier() -> Void {
do {
// Stop the network status notifier
try (NetworkManager.sharedInstance.reachability).startNotifier()
} catch {
print("Error stopping notifier")
}
}

// Network is reachable
static func isReachable(completed: @escaping (NetworkManager) -> Void) {
if (NetworkManager.sharedInstance.reachability).connection != .none {
completed(NetworkManager.sharedInstance)
}
}

// Network is unreachable
static func isUnreachable(completed: @escaping (NetworkManager) -> Void) {
if (NetworkManager.sharedInstance.reachability).connection == .none {
completed(NetworkManager.sharedInstance)
}
}

// Network is reachable via WWAN/Cellular
static func isReachableViaWWAN(completed: @escaping (NetworkManager) -> Void) {
if (NetworkManager.sharedInstance.reachability).connection == .cellular {
completed(NetworkManager.sharedInstance)
}
}

// Network is reachable via WiFi
static func isReachableViaWiFi(completed: @escaping (NetworkManager) -> Void) {
if (NetworkManager.sharedInstance.reachability).connection == .wifi {
completed(NetworkManager.sharedInstance)
}
}
}



class MenuVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{

let provider = MoyaProvider<API_methods>()
let reachability = Reachability()!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this. Delete this.


@IBOutlet weak var allergensBar: AllergensBarScrollView!
var topBar = TopBar()
Expand All @@ -39,8 +115,20 @@ class MenuVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSo
NSAttributedStringKey.underlineStyle: 1
] as [NSAttributedStringKey: Any]




@IBOutlet weak var loadingLabel: UILabel!


override func viewDidLoad() {
NetworkManager.isReachable { networkManagerInstance in
print("Network is available")
}

NetworkManager.isUnreachable { networkManagerInstance in
self.loadingLabel.text = "No internet!"
}

self.view.backgroundColor = UIColor.white

super.viewDidLoad()
Expand All @@ -50,6 +138,8 @@ class MenuVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSo
menuCardsCollection.dataSource = self
menuCardsCollection.alwaysBounceVertical = true
menuCardsCollection.allowsSelection = false



self.view.addSubview(topBar)
topBar.snp.makeConstraints { (make) -> Void in
Expand Down Expand Up @@ -321,7 +411,5 @@ class MenuVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSo
if (segue.identifier == "segueToItemDetailVC") {
let vc = segue.destination as! ItemDetailViewController
vc.menuItem = self.menuItem
}
}
} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change. please revert to older indentation.

}

1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ target 'Bruin Bite' do
pod 'Starscream'
pod 'Repeat'
pod "Pulsator"
pod 'ReachabilitySwift'

end
54 changes: 30 additions & 24 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
PODS:
- Alamofire (4.7.2)
- Alamofire (4.8.0)
- Bolts (1.9.0):
- Bolts/AppLinks (= 1.9.0)
- Bolts/Tasks (= 1.9.0)
- Bolts/AppLinks (1.9.0):
- Bolts/Tasks
- Bolts/Tasks (1.9.0)
- CZPicker (0.4.3)
- FacebookCore (0.3.0):
- Bolts (~> 1.8)
- FBSDKCoreKit (~> 4.27)
- FacebookLogin (0.3.0):
- Bolts (~> 1.8)
- FacebookCore (~> 0.3)
- FBSDKCoreKit (~> 4.27)
- FBSDKLoginKit (~> 4.27)
- FBSDKCoreKit (4.33.0):
- Bolts (~> 1.7)
- FBSDKLoginKit (4.33.0):
- FacebookCore (0.5.0):
- Bolts (~> 1.9)
- FBSDKCoreKit (~> 4.37)
- FacebookLogin (0.5.0):
- Bolts (~> 1.9)
- FacebookCore (~> 0.5)
- FBSDKCoreKit (~> 4.37)
- FBSDKLoginKit (~> 4.37)
- FBSDKCoreKit (4.38.1):
- Bolts (~> 1.9)
- FBSDKLoginKit (4.38.1):
- FBSDKCoreKit
- Moya (10.0.2):
- Moya/Core (= 10.0.2)
- Moya/Core (10.0.2):
- Alamofire (~> 4.1)
- Result (~> 3.0)
- Pulsator (0.5.1)
- ReachabilitySwift (4.3.0)
- Repeat (0.5.7)
- Result (3.2.4)
- SnapKit (4.0.0)
- Starscream (3.0.5)
- SwiftyJSON (4.1.0)
- SnapKit (4.2.0)
- Starscream (3.0.6)
- SwiftyJSON (4.2.0)

DEPENDENCIES:
- CZPicker
- FacebookLogin
- Moya (~> 10.0)
- Pulsator
- ReachabilitySwift
- Repeat
- SnapKit
- Starscream
- SwiftyJSON

SPEC CHECKSUMS:
Alamofire: e4fa87002c137ba2d8d634d2c51fabcda0d5c223
Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844
Bolts: ac6567323eac61e203f6a9763667d0f711be34c8
CZPicker: 55aa1751ea26e209814552da1a9a08cba8bbf72a
FacebookCore: 3ffa190a3f1f96cec0e44d3fc221bc322c595ffa
FacebookLogin: 0af839ea858faef99550d16596b87b4a8e8906e6
FBSDKCoreKit: 572b047a7e029bc44542bcf8a59414e7ff2b543e
FBSDKLoginKit: 88cb456349cfb3b554427ce4f8b43729d85dfb40
FacebookCore: 74288d0add931d361b1596beae787ab72c438249
FacebookLogin: ebcf34714a1cb9f0759d9f071cfb01ed500996cf
FBSDKCoreKit: 8d47857400e2f5bdea697a80daff882e91c84ef6
FBSDKLoginKit: 4621c690d9dd8628031a4791497062183ea34b0d
Moya: 2b0531a9fef318e0bc484030c3db1e6f279ccb66
Pulsator: f465ca37212d826523fe8c79b07c1a4c1a941f5e
ReachabilitySwift: 408477d1b6ed9779dba301953171e017c31241f3
Repeat: 73c5ee602aed8f3c7bf1aa12d4cd0d3dc3edea0a
Result: d2d07204ce72856f1fd9130bbe42c35a7b0fea10
SnapKit: a42d492c16e80209130a3379f73596c3454b7694
Starscream: faf918b2f2eff7d5dd21180646bf015a669673bd
SwiftyJSON: c29297daf073d2aa016295d5809cdd68045c39b3
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
SwiftyJSON: c4bcba26dd9ec7a027fc8eade48e2c911f229e96

PODFILE CHECKSUM: d796cb8069d903701ca59324d85a281c506be28f
PODFILE CHECKSUM: d94fc98ba096932c93fecaeb22de708dca702695

COCOAPODS: 1.4.0