Skip to content

Commit

Permalink
Update to Swift 3 syntax & new Catapush lib API
Browse files Browse the repository at this point in the history
  • Loading branch information
chiarotto committed Dec 18, 2016
1 parent a8f796f commit 57d36c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion catapush-ios-swift-sdk-example-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
#ifndef catapush_ios_swift_sdk_example_Bridging_Header_h_h
#define catapush_ios_swift_sdk_example_Bridging_Header_h_h

#import "CatapushHeaders.h"
#import "Catapush.h"
#endif /* catapush_ios_swift_sdk_example_Bridging_Header_h_h */
25 changes: 22 additions & 3 deletions catapush-ios-swift-sdk-example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate,CatapushDelegate,MessagesD

Catapush.setAppKey("xxxxxxxxxxxxxx")

Catapush.registerUserNotification(self, voIPDelegate: nil)
Catapush.setIdentifier("test", andPassword: "test")

Catapush.start(withIdentifier: "test", andPassword: "test")
Catapush.registerUserNotification(self, voIPDelegate: nil)

Catapush.setupCatapushStateDelegate(self, andMessagesDispatcherDelegate: self)

do {

try Catapush.start()

} catch let error as NSError {

print("Error: \(error.localizedDescription)")

}

application.applicationIconBadgeNumber = 0;

return true
}

Expand All @@ -35,7 +46,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate,CatapushDelegate,MessagesD
}

func applicationWillEnterForeground(_ application: UIApplication) {
Catapush.applicationWillEnterForeground(application)

do {
try Catapush.applicationWillEnterForeground(application)
} catch let error as NSError {

print("Error: \(error.localizedDescription)")

}

}

func applicationDidBecomeActive(_ application: UIApplication) {
Expand Down
12 changes: 6 additions & 6 deletions catapush-ios-swift-sdk-example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ViewController: UIViewController,
for: indexPath) as! MessageCollectionViewCell
let messageIP = self.fetchedResultsController.object(at: indexPath) as! MessageIP
messageCell.messageTextView.text = messageIP.body
if let previousDate = self.previousDate(message: messageIP, indexPath: indexPath) {
if let previousDate = self.previousDate(messageIP, indexPath: indexPath) {
messageCell.setTimestamp(previousDate)
}
return messageCell
Expand All @@ -78,7 +78,7 @@ class ViewController: UIViewController,

let messageIP = self.fetchedResultsController.object(at: indexPath) as! MessageIP
let size = CGSize(width:collectionView.frame.size.width,height:CGFloat.greatestFiniteMagnitude)
let showTimestamp:Bool = (self.previousDate(message: messageIP, indexPath: indexPath) != nil)
let showTimestamp:Bool = (self.previousDate(messageIP, indexPath: indexPath) != nil)
let cellSize = MessageCollectionViewCell.sizeThatFits(size,text:messageIP.body,showTimestamp:showTimestamp)
return CGSize(width:self.collectionView.frame.size.width,height: cellSize.height)
}
Expand All @@ -100,11 +100,11 @@ class ViewController: UIViewController,
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
self.collectionView.reloadData()
for message in self.fetchedResultsController.fetchedObjects! {
self.markMessageIPAsReadIfNeeded(messageIP: message as! MessageIP)
self.markMessageIPAsReadIfNeeded(message as! MessageIP)
}
}

func markMessageIPAsReadIfNeeded(messageIP:MessageIP) {
func markMessageIPAsReadIfNeeded(_ messageIP:MessageIP) {
if messageIP.status.intValue == MESSAGEIP_STATUS.MessageIP_NOT_READ.rawValue {
messageIP.status = NSNumber(value: MESSAGEIP_STATUS.MessageIP_READ.rawValue)
MessageIP.sendMessageReadNotification(messageIP)
Expand All @@ -121,7 +121,7 @@ class ViewController: UIViewController,
}
DispatchQueue.main.async {
for message in self.fetchedResultsController.fetchedObjects! {
self.markMessageIPAsReadIfNeeded(messageIP: message as! MessageIP)
self.markMessageIPAsReadIfNeeded(message as! MessageIP)
}
self.collectionView.reloadData()
}
Expand All @@ -131,7 +131,7 @@ class ViewController: UIViewController,
Return previous date of message is 5 min

*/
func previousDate(message:MessageIP,indexPath:IndexPath) -> Date! {
func previousDate(_ message:MessageIP,indexPath:IndexPath) -> Date! {
if (indexPath.item > 0) {
let prevIndex = IndexPath(item: indexPath.row - 1, section: indexPath.section)
let prevMsg:MessageIP = self.fetchedResultsController.object(at: prevIndex) as! MessageIP
Expand Down

0 comments on commit 57d36c8

Please sign in to comment.