Skip to content

Commit

Permalink
Readme and new classes for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
chiarotto committed Dec 11, 2015
1 parent cc7eef6 commit be2999e
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 20 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,62 @@
# catapush-ios-swift-sdk-example
Catapush sdk iOS App Example written in Swift

![Catapush Logo](https://github.com/Catapush/catapush-ios-swift-sdk-example/blob/master/catapush_logo.png)

# Catapush iOS SDK Example

This project shows how quickly Catapush iOS SDK can be integrated into your current app to receive Catapush messages and display them with a customizable bubble layout. Check out the official website: [Catapush - reliable push notification service](http://www.catapush.com).

![alt tag](https://github.com/Catapush/catapush-ios-swift-sdk-example/blob/master/catapush_screen_shot.jpg)


##Usage


1. git clone https://github.com/Catapush/catapush-ios-swift-sdk-example.git
2. cd catapush-ios-sdk-example
3. pod install
4. open catapush-ios-sdk-example.xcworkspace
5. Get your App Key from [Catapush Dashboard](http://www.catapush.com) and insert it together with a couple of credentials of your choice into your application delegate application:didFinishLaunchingWithOption:
```ruby
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Catapush.setAppKey("YOUR_APP_KEY")
Catapush.startWithIdentifier("test", andPassword: "test")
return true
}
```
6. Run the app
7. Back to your [Catapush Dashboard](http://www.catapush.com) and send some important message.


##Advanced
Read the following documentation to enable push notification: [Catapush - Apple APNs Push Notification setup manual](http://www.catapush.com/docs-ios?__hssc=240266844.6.1447949295248&__hstc=240266844.8906dd1311d28178e3c8bdbb3bf2886a.1447404199228.1447945741012.1447949295248.9&hsCtaTracking=315ccd2b-1bb0-4020-b9f9-8b8dec529f1f|efb89882-78ec-4125-9441-59cdfd6082b2).


## UI appearance
Easily configure the UI appearance by changing TextFont, Background color attributes.

```ruby
..

```
###Example
The following code shows how to change the appearance of the message bubbles and the navigation bar:
```ruby
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// ...





}
```
![alt tag](https://github.com/Catapush/catapush-ios-swift-sdk-example/blob/master/catapush_screen_shot_custom_red.jpg)


##Clipboard
Use Long tap to copy a text into clipboard.

![alt tag](https://github.com/Catapush/catapush-ios-swift-sdk-example/blob/master/catapush_screen_shot_clipboard.jpg)
40 changes: 39 additions & 1 deletion catapush-ios-swift-sdk-example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
9D10DD8F1C1986C7009E610E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D10DD8D1C1986C7009E610E /* Main.storyboard */; };
9D10DD911C1986C7009E610E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9D10DD901C1986C7009E610E /* Assets.xcassets */; };
9D10DD941C1986C7009E610E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D10DD921C1986C7009E610E /* LaunchScreen.storyboard */; };
9DB47C831C19B12600E49771 /* MessageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DB47C821C19B12600E49771 /* MessageCollectionViewCell.swift */; };
9DB47C851C19BEE300E49771 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DB47C841C19BEE300E49771 /* Constants.swift */; };
9DFABD9B1C1B07B70074BB1D /* MessageCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DFABD9A1C1B07B70074BB1D /* MessageCollectionView.swift */; };
E3115C3B0DE42FDA997F74CC /* libPods-catapush-ios-swift-sdk-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B5313E40EA4676E6058BFE1 /* libPods-catapush-ios-swift-sdk-example.a */; };
/* End PBXBuildFile section */

Expand All @@ -26,6 +29,9 @@
9D10DD931C1986C7009E610E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9D10DD951C1986C7009E610E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9D10DD9B1C19884F009E610E /* catapush-ios-swift-sdk-example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "catapush-ios-swift-sdk-example-Bridging-Header.h"; sourceTree = "<group>"; };
9DB47C821C19B12600E49771 /* MessageCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageCollectionViewCell.swift; sourceTree = "<group>"; };
9DB47C841C19BEE300E49771 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
9DFABD9A1C1B07B70074BB1D /* MessageCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageCollectionView.swift; sourceTree = "<group>"; };
E42BE7840CBBA428B7969ED5 /* Pods-catapush-ios-swift-sdk-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-catapush-ios-swift-sdk-example.release.xcconfig"; path = "Pods/Target Support Files/Pods-catapush-ios-swift-sdk-example/Pods-catapush-ios-swift-sdk-example.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -71,16 +77,35 @@
9D10DD881C1986C7009E610E /* catapush-ios-swift-sdk-example */ = {
isa = PBXGroup;
children = (
9DB47C811C19B05000E49771 /* view */,
9DB47C801C19B03C00E49771 /* controller */,
9D10DD891C1986C7009E610E /* AppDelegate.swift */,
9D10DD8B1C1986C7009E610E /* ViewController.swift */,
9D10DD8D1C1986C7009E610E /* Main.storyboard */,
9D10DD901C1986C7009E610E /* Assets.xcassets */,
9D10DD921C1986C7009E610E /* LaunchScreen.storyboard */,
9D10DD951C1986C7009E610E /* Info.plist */,
9DB47C841C19BEE300E49771 /* Constants.swift */,
);
path = "catapush-ios-swift-sdk-example";
sourceTree = "<group>";
};
9DB47C801C19B03C00E49771 /* controller */ = {
isa = PBXGroup;
children = (
9D10DD8B1C1986C7009E610E /* ViewController.swift */,
);
name = controller;
sourceTree = "<group>";
};
9DB47C811C19B05000E49771 /* view */ = {
isa = PBXGroup;
children = (
9DB47C821C19B12600E49771 /* MessageCollectionViewCell.swift */,
9DFABD9A1C1B07B70074BB1D /* MessageCollectionView.swift */,
);
name = view;
sourceTree = "<group>";
};
A0473A12389A226780752755 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -125,6 +150,12 @@
TargetAttributes = {
9D10DD851C1986C7009E610E = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = VZ77JRQQAE;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
};
};
};
};
};
Expand Down Expand Up @@ -213,7 +244,10 @@
buildActionMask = 2147483647;
files = (
9D10DD8C1C1986C7009E610E /* ViewController.swift in Sources */,
9DFABD9B1C1B07B70074BB1D /* MessageCollectionView.swift in Sources */,
9D10DD8A1C1986C7009E610E /* AppDelegate.swift in Sources */,
9DB47C831C19B12600E49771 /* MessageCollectionViewCell.swift in Sources */,
9DB47C851C19BEE300E49771 /* Constants.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -327,6 +361,8 @@
baseConfigurationReference = 0775F01A5B9716E79CCCD803 /* Pods-catapush-ios-swift-sdk-example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "catapush-ios-swift-sdk-example/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.catapush.ios.swift.example.catapush-ios-swift-sdk-example";
Expand All @@ -339,6 +375,8 @@
baseConfigurationReference = E42BE7840CBBA428B7969ED5 /* Pods-catapush-ios-swift-sdk-example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "catapush-ios-swift-sdk-example/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.catapush.ios.swift.example.catapush-ios-swift-sdk-example";
Expand Down
89 changes: 81 additions & 8 deletions catapush-ios-swift-sdk-example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,115 @@
//

import UIKit
import Foundation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate,CatapushDelegate,MessagesDispatchDelegate,UIAlertViewDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Catapush.setAppKey("1936ff755bc74f186c9ed888d573fcc9")
Catapush.startWithIdentifier("test", andPassword: "test")
Catapush.setupCatapushStateDelegate(self, andMessagesDispatcherDelegate: self)

if let loptions = launchOptions {
let remoteNotification = loptions[UIApplicationLaunchOptionsRemoteNotificationKey]
if case let sender as String = remoteNotification!["sender"] {
if sender == "catapush" {
// Wake up, it's Catapush!
}
}

}

if NSProcessInfo().operatingSystemVersion.majorVersion > 8 {
let notificationSettings = UIUserNotificationSettings(forTypes: [.Sound,.Alert,.Badge], categories: [])
application.registerUserNotificationSettings(notificationSettings)
} else {
application.registerForRemoteNotificationTypes([.Sound,.Alert,.Badge])
}

application.applicationIconBadgeNumber = 0;


return true
}




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.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
Catapush.applicationDidEnterBackground(application)
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
Catapush.applicationWillEnterForeground(application)
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
Catapush.applicationDidBecomeActive(application)
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
Catapush.applicationWillTerminate(application)
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Catapush.registerForRemoteNotificationsWithDeviceToken(deviceToken)
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("Did Fail Register Notification",error)
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
CatapushRemoteNotifications.application(application,
didReceiveRemoteNotification: userInfo,
fetchCompletionHandler: completionHandler)
}

func catapushDidConnectSuccessfully(catapush: Catapush!) {
let connectedAV = UIAlertView( title: "Connected",
message: "Catapush Connected",
delegate: self,
cancelButtonTitle: "Ok")
connectedAV.show()
}


func catapush(catapush: Catapush!, didFailOperation operationName: String!, withError error: NSError!) {
if error.domain == CATAPUSH_ERROR_DOMAIN {
print("Error code:\(error.code)")
}
let errorMessage = "The operation " + operationName + " is failed with error " + error.localizedDescription
let flowErrorAlertView = UIAlertView(title: "Error", message: errorMessage, delegate: self, cancelButtonTitle: "Ok")
flowErrorAlertView.show()
}

func libraryDidReceiveMessageIP(messageIP: MessageIP!) {
MessageIP.sendMessageReadNotification(messageIP)
for message in Catapush.allMessages() {
print("Message: \(message.body)")
}
}


/**

Customize appearance of message bubbles

*/






}

Loading

0 comments on commit be2999e

Please sign in to comment.