Pushdy
  • GIỚI THIỆU
  • Cài đặt Mobile Push
    • iOS
    • Android
  • Cài đặt web push
    • Trình duyệt phổ biến
  • Sử dụng Dashboard
    • Tạo ứng dụng
    • Tạo trường dữ liệu thuộc tính
    • Tạo trường dữ liệu sự kiện
    • Gửi Push cơ bản
    • Gửi A/B Push
    • Gửi Push tự động
    • Gửi Push kích hoạt
    • Gợi ý sản phẩm
    • Banner Thông Minh
    • Max Leads
    • Đồng bộ đối tượng quảng cáo Facebook
    • Đồng bộ đối tượng quảng cáo Google
    • Liên kết tài khoản thống kê Google Analytics
    • Sử dụng Template
    • Sử dụng User Segment
    • Thiết lập Webhook Events
    • Thêm thành viên quản trị
  • Tham chiếu SDK/API
    • Rest API Reference
    • Web Push SDK
    • iOS Native SDK
    • Android Native SDK
    • React Native SDK
    • Web Event Tracking
  • Cài đặt khác
    • Cách tạo Firebase Server Key
    • Cách tạo iOS Push Certificate
    • Cách tạo Safari Push Certificate
Powered by GitBook
On this page
  • Các hàm trong iOS Native SDK
  • initWithClientKey
  • setDeviceID
  • getDeviceID
  • registerForPushNotification
  • getDeviceToken
  • getPendingNotification
  • getPendingNotifications
  • setAttribute
  • pushAttribute
  • getPlayerId
  • Các Delegation trong iOS Native SDK
  • readyForHandlingNotification
  • onNotificationReceived
  • onNotificationOpened
  • Một số hàm dùng để tuỳ biến hiển thị Push Notification
  • setPushBannerAutoDismiss
  • setPushBannerAutoDismissDuration
  • setCustomPushBanner
  • setCustomMediaKey
  1. Tham chiếu SDK/API

iOS Native SDK

Các hàm trong iOS Native SDK

initWithClientKey

Khởi tạo Pushdy SDK với Client Key. Bạn có thể sao chép Client Key tại Dashboard của Pushdy sau khi bạn tạo ứng dụng. Mỗi ứng dụng sẽ có 1 Client Key duy nhất. Hàm initWithClientKey được sử dụng trong hàm didFinishLaunchingWithOptions trong file AppDelegate của bạn.

NSString *clientKey = @"YOUR_CLIENT_KEY";
[Pushdy initWithClientKey:clientKey delegate:self launchOptions:launchOptions];
let clientKey = "YOUR_CLIENT_KEY"
Pushdy.initWith(clientKey: clientKey, delegate: self, launchOptions: launchOptions)

setDeviceID

Bạn có thể tuỳ chỉnh Device ID theo logic của bạn. Nếu bạn không sử dụng hàm này, Device ID sẽ được tự động sinh ra để đảm bảo định danh user là duy nhất. Hàm này phải được gọi ngay trước hàm initWithClientKey khi bạn khởi tạo Pushdy SDK để đảm bảo Custom Device ID được lưu lại trước khi Pusdy SDK gửi yêu cầu tới máy chủ.


NSString *customDeviceID = @"YOUR CUSTOM ID";
[Pushdy setDeviceID:customDeviceID];
let customDeviceID = "YOUR CUSTOM ID"
Pushdy.setDeviceID(customDeviceID)

getDeviceID

Với hàm này bạn có thể truy xuất Device ID của bạn.

NSString *yourDeviceID = [Pushdy getDeviceID]
let yourDeviceID = Pushdy.getDeviceID()

registerForPushNotification

Sử dụng để hiển thị cửa sổ xin quyền Push Notification. Để tăng tỷ lệ user đồng ý nhận Push Notification, bạn nên gọi hàm này sau khi đã hiển thị đầy đủ thông tin về lợi ích của việc bật Push Notification với user.

[Pushdy registerForPushNotifications];
Pushdy.registerForPushNotifications()

checkNotificationEnabled

Kiểm tra xem người dùng có bật Push Notification cho iOS App của bạn hay không.

[Pushdy checkNotificationEnabled:^(BOOL enabled) {
    // ...
}];
Pushdy.checkNotificationEnabled { (enabled:Bool) in
    // ...
}

getDeviceToken

Lấy APNs Token. Token này chỉ có khi người dùng bật Push Notification cho App.

NSString *deviceToken = [Pushdy getDeviceToken];
let deviceToken = Pushdy.getDeviceToken()

getPendingNotification

Lấy Notification mới nhất từ danh sách các Notification chưa được xử lý.

NSDictionary *latestNotification = [Pushdy getPendingNotification];
let latestNotification = Pushdy.getPendingNotification()

getPendingNotifications

Lấy danh sách toàn bộ Notification từ danh sách hàng đợi chưa được xử lý.

NSArray *pendingNotifications = [Pushdy getPendingNotifications];
let pendingNotifications = Pushdy.getPendingNotifications()

setAttribute

[Pushdy setAttribute:@"your_attribute_name" value:@"your_value" error:nil];
try? Pushdy.setAttribute("your_attribute_name", value: "your_value") 

pushAttribute

Tương tự hàm setAttribute nhưng chỉ hoạt động với thuộc tính được định nghĩa là kiểu mảng (Array). Mảng giá trị mới sẽ được gắn thêm vào sau giá trị cũ.

NSArray *your_values_array = @[@"new_value_1", @"new_value_2"];
[Pushdy pushAttribute:@"your_attribute_name" value:your_values_array error:nil];
let your_values_array:[String] = [
    "new_value_1",
    "new_value_2"
]
try? Pushdy.pushAttribute("your_attribute_name", value: your_values_array)

getPlayerId

Lấy Player ID của người dùng, ID này do Pushdy sinh ra cho mỗi người dùng đầu cuối. Chú ý, mỗi 1 thiết bị sẽ có 1 Player ID duy nhất, trường hợp gỡ ứng dụng và cài lại thì Player ID vẫn giữ nguyên. Player ID chỉ thay đổi khi bạn thay đổi Device ID bằng hàm setDeviceID.

NSString *playerID = [Pushdy getPlayerID];
let playerID = Pushdy.getPlayerID()

Các Delegation trong iOS Native SDK

readyForHandlingNotification

Nếu hàm trả về giá trị là false có nghĩa là Push Notification sẽ không được xử lý ngay tại thời điểm nhận được mà sẽ được đưa vào hàng đợi. Bạn chỉ có thể lấy và xử lý Push Notification này bằng cách sử dụng hàm getPendingNotification hoặc getPendingNotifications . Mặc định giá trị được trả về sẽ là true, có nghĩa là Push Notification sẽ được xử lý ngay khi Device của bạn nhận được.

(BOOL)readyForHandlingNotification {
    BOOL already = YES;
    // your custom logic
    if (my_screen_name == "tutorial") {
        // không hiển thị push ở màn hình Tutorial mà sẽ chủ động hiển thị khi 
        // sau khi user hoàn thành tutorial
        already = NO;
    }
    return already;
}
func readyForHandlingNotification() -> Bool {
    var already = true
    // your custom logic
    if (my_screen_name == "tutorial") {
        // không hiển thị push ở màn hình Tutorial mà sẽ chủ động hiển thị khi 
        // sau khi user hoàn thành tutorial
        already = false;
    }
    return already
}

onNotificationReceived

Được gọi khi app của bạn nhận được Push Notification. Chú ý, sự kiện này chỉ xảy ra khi App của bạn đang được mở.

(void)onNotificationReceived:(NSDictionary<NSString *,id> *)notification 
                                fromState:(NSString *)fromState {
    NSLog(@"Received notification from state: %@", fromState);
}
func onNotificationReceived(_ notification: [String : Any], fromState: String) {
   print("Received notification from state: \(fromState)")     
}

onNotificationOpened

Được gọi khi người dùng nhấp vào Push Notification.

(void)onNotificationOpened:(NSDictionary<NSString *,id> *)notification 
                                fromState:(NSString *)fromState {
    NSLog(@"Opened notification from state: %@", fromState);
}
func onNotificationOpened(_ notification: [String : Any], fromState: String) {
     print("Opened notification from state: \(fromState)")     
}

Một số hàm dùng để tuỳ biến hiển thị Push Notification

setPushBannerAutoDismiss

Bật/tắt tự động ẩn cửa sổ cho Push Notification khi bạn đang mở App. Nếu bạn tắt điều khiển tự động, người dùng sẽ phải chủ động nhấp vào "x" button trên cửa sổ Push để tắt thông báo.

[Pushdy setPushBannerAutoDismiss:TRUE];
Pushdy.setPushBannerAutoDismiss(true)

setPushBannerAutoDismissDuration

Thiết lập thời gian hiển thị cửa sổ Push Notification khi bạn đang mở App. Mặc định, thời gian hiển thị là 5 giây. Hàm này chỉ hoạt động khi bạn bật chức năng tự động ẩn cửa sổ Push.

[Pushdy setPushBannerDismissDuration:5];
Pushdy.setPushBannerDismissDuration(5)

setCustomPushBanner

Tuỳ chỉnh cửa sổ hiển thị Push Notification.

[Pushdy setCustomPushBanner:yourUIView];
Pushdy.setCustomPushBanner(yourUIView)

setCustomMediaKey

Tuỳ chỉnh Json key cho media url để hiển thị ảnh trên cửa sổ Push Notification khi đang bật App. Mặc định, media_url sẽ là key được sử dụng.

[PDYNotificationView setCustomMediaKey:@"your_custom_media_key"];
PDYNotificationView.setCustomMediaKey("your_custom_media_key")
PreviousWeb Push SDKNextAndroid Native SDK

Last updated 5 years ago

Tracking dữ liệu để gửi lên Pushdy nhằm phục vụ phân đoạn người dùng khi gửi Push. Với hàm này, dữ liệu mới sẽ đè lên dữ liệu cũ. Bạn có thể xem thêm chi tiết cách định nghĩa thuộc tính tại phần .

Tạo thuộc tính