Archived
Added done button to keyboard in Customization View Controller, added code for Firebase notifications (non-functional without APNs key from a developer account)
This commit is contained in:
@@ -599,7 +599,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer: k.duezgoeren@gmail.com (R9NVDFCQHW)";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
@@ -661,7 +661,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer: k.duezgoeren@gmail.com (R9NVDFCQHW)";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
|||||||
+32
-19
@@ -10,7 +10,7 @@ import UIKit
|
|||||||
import Firebase
|
import Firebase
|
||||||
|
|
||||||
@UIApplicationMain
|
@UIApplicationMain
|
||||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
|
||||||
|
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
@@ -19,28 +19,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
|
|
||||||
FirebaseApp.configure()
|
FirebaseApp.configure()
|
||||||
|
|
||||||
// if #available(iOS 10.0, *) {
|
if #available(iOS 10.0, *) {
|
||||||
// // For iOS 10 display notification (sent via APNS)
|
// For iOS 10 display notification (sent via APNS)
|
||||||
// UNUserNotificationCenter.current().delegate = self
|
UNUserNotificationCenter.current().delegate = self
|
||||||
//
|
|
||||||
// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
|
||||||
// UNUserNotificationCenter.current().requestAuthorization(
|
|
||||||
// options: authOptions,
|
|
||||||
// completionHandler: {_, _ in })
|
|
||||||
// } else {
|
|
||||||
// let settings: UIUserNotificationSettings =
|
|
||||||
// UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
|
||||||
// application.registerUserNotificationSettings(settings)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// application.registerForRemoteNotifications()
|
|
||||||
|
|
||||||
Messaging.messaging().subscribe(toTopic: "substitutions-ios")
|
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
||||||
Messaging.messaging().subscribe(toTopic: "substitutions-broadcast")
|
UNUserNotificationCenter.current().requestAuthorization(
|
||||||
Crashlytics.sharedInstance().setUserIdentifier(UserDefaults.standard.string(forKey: "username"))
|
options: authOptions,
|
||||||
|
completionHandler: {_, _ in })
|
||||||
|
} else {
|
||||||
|
let settings: UIUserNotificationSettings =
|
||||||
|
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
||||||
|
application.registerUserNotificationSettings(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
application.registerForRemoteNotifications()
|
||||||
|
InstanceID.instanceID().instanceID { (result, error) in
|
||||||
|
if let error = error {
|
||||||
|
print("Error fetching remote instance ID: \(error)")
|
||||||
|
} else if let result = result {
|
||||||
|
print("Remote instance ID token: \(result.token)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Messaging.messaging().delegate = self
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
|
||||||
|
print("Firebase registration token: \(fcmToken)")
|
||||||
|
|
||||||
|
let dataDict:[String: String] = ["token": fcmToken]
|
||||||
|
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
|
||||||
|
// TODO: If necessary send token to application server.
|
||||||
|
// Note: This callback is fired at each app startup and whenever a new token is generated.
|
||||||
|
}
|
||||||
|
|
||||||
func applicationWillResignActive(_ application: UIApplication) {
|
func applicationWillResignActive(_ application: UIApplication) {
|
||||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
||||||
|
|||||||
@@ -163,12 +163,25 @@
|
|||||||
<connections>
|
<connections>
|
||||||
<outlet property="collectionView" destination="hWP-3N-RUn" id="RFo-DP-uPX"/>
|
<outlet property="collectionView" destination="hWP-3N-RUn" id="RFo-DP-uPX"/>
|
||||||
<outlet property="defaultSegments" destination="omP-RH-Hlh" id="hVo-ND-9EG"/>
|
<outlet property="defaultSegments" destination="omP-RH-Hlh" id="hVo-ND-9EG"/>
|
||||||
|
<outlet property="textToolbar" destination="cDy-2Q-2zk" id="UlY-Aa-f41"/>
|
||||||
<outlet property="txtClasses" destination="bCV-w1-hVY" id="lDD-NQ-f8f"/>
|
<outlet property="txtClasses" destination="bCV-w1-hVY" id="lDD-NQ-f8f"/>
|
||||||
<outlet property="txtCourses" destination="69O-Fo-TQF" id="AC7-pO-Jms"/>
|
<outlet property="txtCourses" destination="69O-Fo-TQF" id="AC7-pO-Jms"/>
|
||||||
<outlet property="txtName" destination="TpM-Mz-EpI" id="W0o-NR-E96"/>
|
<outlet property="txtName" destination="TpM-Mz-EpI" id="W0o-NR-E96"/>
|
||||||
</connections>
|
</connections>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="fIE-1y-qpc" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="fIE-1y-qpc" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
|
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="cDy-2Q-2zk">
|
||||||
|
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||||
|
<items>
|
||||||
|
<barButtonItem style="plain" systemItem="flexibleSpace" id="Tsa-Dg-qek"/>
|
||||||
|
<barButtonItem systemItem="done" id="nSG-vf-dVd">
|
||||||
|
<connections>
|
||||||
|
<action selector="textDismissButton:" destination="8XB-jK-YFD" id="aXf-TS-Wxk"/>
|
||||||
|
</connections>
|
||||||
|
</barButtonItem>
|
||||||
|
</items>
|
||||||
|
</toolbar>
|
||||||
</objects>
|
</objects>
|
||||||
<point key="canvasLocation" x="2691" y="-514"/>
|
<point key="canvasLocation" x="2691" y="-514"/>
|
||||||
</scene>
|
</scene>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MagazineLayout
|
import MagazineLayout
|
||||||
|
|
||||||
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout {
|
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout, UITextFieldDelegate {
|
||||||
|
|
||||||
var courses = [String]()
|
var courses = [String]()
|
||||||
var translatedCourses = [String]()
|
var translatedCourses = [String]()
|
||||||
@@ -24,6 +24,16 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
|||||||
@IBOutlet weak var txtCourses: UITextField!
|
@IBOutlet weak var txtCourses: UITextField!
|
||||||
@IBOutlet weak var defaultSegments: UISegmentedControl!
|
@IBOutlet weak var defaultSegments: UISegmentedControl!
|
||||||
|
|
||||||
|
@IBOutlet weak var textToolbar: UIToolbar!
|
||||||
|
|
||||||
|
@IBAction func textDismissButton(_ sender: Any) {
|
||||||
|
view.endEditing(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
textField.inputAccessoryView = textToolbar
|
||||||
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
courses = self.df.courses
|
courses = self.df.courses
|
||||||
@@ -45,6 +55,10 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
|||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
self.txtName.delegate = self
|
||||||
|
self.txtClasses.delegate = self
|
||||||
|
self.txtCourses.delegate = self
|
||||||
|
|
||||||
self.txtName.text = prefs.string(forKey: "username")
|
self.txtName.text = prefs.string(forKey: "username")
|
||||||
self.txtClasses.text = prefs.string(forKey: "classes")
|
self.txtClasses.text = prefs.string(forKey: "classes")
|
||||||
self.txtCourses.text = prefs.string(forKey: "courses")
|
self.txtCourses.text = prefs.string(forKey: "courses")
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class DataFetcher {
|
|||||||
var infoList = [String]()
|
var infoList = [String]()
|
||||||
var menuList = [String]()
|
var menuList = [String]()
|
||||||
var isPersonalEmpty = true
|
var isPersonalEmpty = true
|
||||||
|
var personalPlanCount = 0
|
||||||
do {
|
do {
|
||||||
let doc = try SwiftSoup.parse(html)
|
let doc = try SwiftSoup.parse(html)
|
||||||
|
|
||||||
@@ -119,6 +120,7 @@ class DataFetcher {
|
|||||||
date <- mDate, time <- mTime, room <- mRoom)
|
date <- mDate, time <- mTime, room <- mRoom)
|
||||||
_ = try db.run(insertPersonal)
|
_ = try db.run(insertPersonal)
|
||||||
isPersonalEmpty = false
|
isPersonalEmpty = false
|
||||||
|
personalPlanCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if courses != nil && courses != "" && classes != nil && classes != "" {
|
} else if courses != nil && courses != "" && classes != nil && classes != "" {
|
||||||
@@ -131,6 +133,7 @@ class DataFetcher {
|
|||||||
date <- mDate, time <- mTime, room <- mRoom)
|
date <- mDate, time <- mTime, room <- mRoom)
|
||||||
_ = try db.run(insertPersonal)
|
_ = try db.run(insertPersonal)
|
||||||
isPersonalEmpty = false
|
isPersonalEmpty = false
|
||||||
|
personalPlanCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,6 +141,7 @@ class DataFetcher {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefs.set(personalPlanCount, forKey: "personalPlanCount")
|
||||||
if isPersonalEmpty {
|
if isPersonalEmpty {
|
||||||
personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: ""))
|
personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: ""))
|
||||||
let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "")
|
let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "")
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ class InfoViewController : UIViewController {
|
|||||||
self.df.doAsync(do: "info") { infoArray in
|
self.df.doAsync(do: "info") { infoArray in
|
||||||
self.content.text = infoArray[0] as? String
|
self.content.text = infoArray[0] as? String
|
||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
|
if let tabItems = self.tabBarController?.tabBar.items {
|
||||||
|
let tabItem = tabItems[1]
|
||||||
|
if self.prefs.integer(forKey: "personalPlanCount") != 0 {
|
||||||
|
tabItem.badgeValue = "\(self.prefs.integer(forKey: "personalPlanCount"))"
|
||||||
|
} else {
|
||||||
|
tabItem.badgeValue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
let layout = MagazineLayout()
|
let layout = MagazineLayout()
|
||||||
var collectionView: UICollectionView
|
var collectionView: UICollectionView
|
||||||
let identifier = "menu_cell"
|
let identifier = "menu_cell"
|
||||||
|
let prefs = UserDefaults.standard
|
||||||
|
|
||||||
required init?(coder decoder: NSCoder) {
|
required init?(coder decoder: NSCoder) {
|
||||||
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
||||||
@@ -62,6 +63,14 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
self.items = menuItems as! [String]
|
self.items = menuItems as! [String]
|
||||||
self.collectionView.reloadData()
|
self.collectionView.reloadData()
|
||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
|
if let tabItems = self.tabBarController?.tabBar.items {
|
||||||
|
let tabItem = tabItems[1]
|
||||||
|
if self.prefs.integer(forKey: "personalPlanCount") != 0 {
|
||||||
|
tabItem.badgeValue = "\(self.prefs.integer(forKey: "personalPlanCount"))"
|
||||||
|
} else {
|
||||||
|
tabItem.badgeValue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +92,6 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// generated stubs filled with return values
|
|
||||||
|
|
||||||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeModeForItemAt indexPath: IndexPath) -> MagazineLayoutItemSizeMode {
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeModeForItemAt indexPath: IndexPath) -> MagazineLayoutItemSizeMode {
|
||||||
let widthMode = MagazineLayoutItemWidthMode.fullWidth(respectsHorizontalInsets: true)
|
let widthMode = MagazineLayoutItemWidthMode.fullWidth(respectsHorizontalInsets: true)
|
||||||
let heightMode = MagazineLayoutItemHeightMode.dynamic
|
let heightMode = MagazineLayoutItemHeightMode.dynamic
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MagazineLayout
|
import MagazineLayout
|
||||||
import Crashlytics
|
import Crashlytics
|
||||||
|
import Firebase
|
||||||
|
|
||||||
class PlanViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout {
|
class PlanViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout {
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
var substs = [SubstModel]()
|
var substs = [SubstModel]()
|
||||||
let refreshControl = UIRefreshControl()
|
let refreshControl = UIRefreshControl()
|
||||||
let df = DataFetcher.sharedInstance
|
let df = DataFetcher.sharedInstance
|
||||||
|
let planPrefs = UserDefaults.standard
|
||||||
let layout = MagazineLayout()
|
let layout = MagazineLayout()
|
||||||
var collectionView: UICollectionView
|
var collectionView: UICollectionView
|
||||||
var url = ""
|
var url = ""
|
||||||
@@ -33,12 +35,16 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
|
Messaging.messaging().subscribe(toTopic: "substitutions-ios")
|
||||||
|
Messaging.messaging().subscribe(toTopic: "substitutions-broadcast")
|
||||||
|
Crashlytics.sharedInstance().setUserIdentifier(UserDefaults.standard.string(forKey: "username"))
|
||||||
|
|
||||||
view.addSubview(collectionView)
|
view.addSubview(collectionView)
|
||||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||||
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||||
collectionView.topAnchor.constraint(equalTo: view.topAnchor), // getToolbarBottomAnchor()),
|
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||||
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||||
])
|
])
|
||||||
collectionView.register(UINib(nibName: "PlanViewCell", bundle: nil), forCellWithReuseIdentifier: identifier)
|
collectionView.register(UINib(nibName: "PlanViewCell", bundle: nil), forCellWithReuseIdentifier: identifier)
|
||||||
@@ -80,6 +86,14 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
|||||||
self.substs = substitutions as! [SubstModel]
|
self.substs = substitutions as! [SubstModel]
|
||||||
self.collectionView.reloadData()
|
self.collectionView.reloadData()
|
||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
|
if let tabItems = self.tabBarController?.tabBar.items {
|
||||||
|
let tabItem = tabItems[1]
|
||||||
|
if self.planPrefs.integer(forKey: "personalPlanCount") != 0 {
|
||||||
|
tabItem.badgeValue = "\(self.planPrefs.integer(forKey: "personalPlanCount"))"
|
||||||
|
} else {
|
||||||
|
tabItem.badgeValue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user