luatnd / ios-pushdy-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pushdy

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Swift >= 4.2

Installation

Pushdy is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PushdySDK'

Usage

Import

Import module in Swift language:

import PushdySDK

Import module in Objective-C language (You must generate brigde header to support Swift first):

#import <PushdySDK/PushdySDK-Swift.h>

Initialization

In application:didFinishLaunchingWithOptions method, initialize Pushdy SDK as below:

// Swift language
let clientKey = "your client key from Pushdy application"
Pushdy.initWith(clientKey: clientKey, delegate: self, launchOptions: launchOptions)
// Objective-C language
NSString *clientKey = @"your client key from Pushdy application";
[Pushdy initWithClientKey:clientKey delegate:self launchOptions:launchOptions];

Then you can call registerForPushNotifications method to register receiving push notification.

// Swift language
Pushdy.registerForPushNotifications()
// Objective-C language
[Pushdy registerForPushNotifications];

Methods

  • getDeviceToken

Get device token from pushdy

// Swift language
Pushdy.getDeviceToken()
// Objective-C language
[Pushdy getDeviceToken];
  • checkNotificationEnabling

Check allowing notification or not

// Swift language
Pushdy.checkNotificationEnabling { (enabled:Bool) in

}
// Objective-C language
[Pushdy checkNotificationEnabling:^(BOOL enabled) {
        
}];
  • setDeviceID

Using your device id instead of Pushdy device id

// Swift language
let yourDeviceID = ...
Pushdy.setDeviceID(yourDeviceID)
// Objective-C language
NSString* yourDeviceID = ...;
[Pushdy setDeviceID:yourDeviceID];
  • getPendingNotification

Get pending notification which is not handled

// Swift language
Pushdy.getPendingNotification()
// Objective-C language
[Pushdy getPendingNotification];
  • setAttribute

Set value for an attribute. You can set "commitImmediately" variable to true to commit your value immediately.

// Swift language
try? Pushdy.setAttribute("", value: "") 

// Equivalent to
try? Pushdy.setAttribute("network_carrier", value: "your_network_carrier", commitImmediately: false)
// Objective-C language
[Pushdy setAttribute:@"network_carrier" value:@"your_network_carrier" error:nil];

// Equivalent to
[Pushdy setAttribute:@"network_carrier" value:@"your_network_carrier" commitImmediately:FALSE error:nil];
  • pushAttribute

Push value into a type of array attributer. You can set "commitImmediately" variable to true to commit your value immediately.

// Swift language
let books:[String] = [
"book_1",
"book_2"
]
try? Pushdy.pushAttribute("bought_books", value: books)

// Equivalent to
try? Pushdy.pushAttribute("bought_books", value: books, commitImmediately: false)
// Objective-C language

NSArray *books = @[@"book_1", @"book_2"];
[Pushdy pushAttribute:@"bought_books" value:books error:nil];

// Equivalent to
[Pushdy pushAttribute:@"bought_books" value:books commitImmediately:FALSE error:nil];

Pushdy Delegation

For listen the Pushdy callback and adapt your logic with Pushdy, you must implement PushdyDelegate in your App Delegate

// Swift language
import PushdySDK
class AppDelegate: UIResponder, UIApplicationDelegate, PushdyDelegate {

}
// Objective-C language
#import <PushdySDK/PushdySDK-Swift.h> // You must generate brigde header first
@interface AppDelegate : UIResponder <UIApplicationDelegate, PushdyDelegate> {
  
}

-readyForHandlingNotification :

Determine that the application can handle push notification or not. Default is true. If false, incoming push will be pushed to pending notifications and you can process pending notifications later.

// Swift language
func readyForHandlingNotification() -> Bool {
    var already = true
    // Example: already = pass through login or tutorial/introdution screen
    return already
}
// Objective-C language
- (BOOL)readyForHandlingNotification {
    BOOL already = YES;
    // Example: already = pass through login or tutorial/introduction screen
    return already;
}

-onNotificationReceived:fromState :

When the application received a notification, Pushdy will trigger this method.

// Swift language
func onNotificationReceived(_ notification: [String : Any], fromState: String) {
        if fromState == "not_running" {
            // Example: is_app_launched_from_push = true
        }
        else if fromState == "active" {
            // Example: Play a sound to notitfy user
        }
        else if fromState == "inactive" {
            // Example: Play a sound to notitfy user
        }
        else if fromState == "background" {
            
        }
    }
// Objective-C language
- (void)onNotificationReceived:(NSDictionary<NSString *,id> *)notification fromState:(NSString *)fromState {
    if ([fromState isEqualToString:@"not_running"]) {
        // Example: is_app_launched_from_push = true
    }
    else if ([fromState isEqualToString:@"active"]) {
        // Example: Play a sound to notitfy user
    }
    else if ([fromState isEqualToString:@"inactive"]) {
        // Example: Play a sound to notitfy user
    }
    else if ([fromState isEqualToString:@"background"]) {

    }
}

-onNotificationOpened:fromState :

When user tap push notification banner (system notification or in app notification banner), Pushdy will trigger this method.

// Swift language
func onNotificationOpened(_ notification: [String : Any], fromState: String) {
     // Handle notification
}
// Objective-C language
- (void)onNotificationOpened:(NSDictionary<NSString *,id> *)notification fromState:(NSString *)fromState {
    // Handle notification
}

And some other delegate methods...

Customize In App Notification Banner

We use PDYNotificationView view for default displaying in app push notification. Pushdy also provides some method to adjust default notification view and set your custom view.

  • setPushBannerAutoDismiss :

Turn on/off auto dismiss for in app notification banner.

// Swift language
Pushdy.setPushBannerAutoDismiss(true)
// Objective-C language
[Pushdy setPushBannerAutoDismiss:TRUE];
  • setPushBannerDismissDuration :

Set auto dismiss duration for default custom view.

// Swift language
Pushdy.setPushBannerDismissDuration(5) // 5 seconds
// Objective-C language
[Pushdy setPushBannerDismissDuration:5]; // 5 seconds
  • setCustomPushBanner :

Set custom notification banner view. Implementating PDYPushBannerActionProtocol protocol is required.

// Swift language
let yourCustomView = ...
Pushdy.setCustomPushBanner(yourCustomView)
// Objective-C language
UIView* yourCustomView = ...
[Pushdy setCustomPushBanner:yourCustomView];

*** Note:

Pushdy SDK use _nms_image key for displaying thumbnail image from json push payload as default.

{
   "aps" : {
        ...
   },
   "_nms_image" : "https://domain.com/path/image.png"
}

If you want to custom your own key, use setCustomMediaKey method for override it.

// Swift language
PDYNotificationView.setCustomMediaKey("your_custom_media_key")
// Objective-C language
[PDYNotificationView setCustomMediaKey:@"your_custom_media_key"];

Author

Pushdy Team, contact@pushdy.com

License

Pushdy is available under the MIT license. See the LICENSE file for more info.

About

License:MIT License


Languages

Language:Swift 97.5%Language:Ruby 2.5%