Skip to content

fruktorum/DevinoPushSDK-iOS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DevinoSDK

Requirements

  • Xcode 11+
  • Swift 5+
  • iOS 11.0+

Quick start guide

Create APNs Certificate in Apple Developer Account

  • Creating an Explicit App ID in Identifiers
  • Generating a new APNs certificate for your application in Certificates
  • Creating the Development and Distribution Provisioning Profile in Profiles
  • Creating the App Group ID in Identifiers -> AppGroups (AppGroupID is required for your application and NotificationExtension to exchange important data through a common data container, remember this ID for further integration steps)

Adding DevinoSDK to your Xcode project

  1. Move DevinoSDK.framework to the Frameworks project folder:

  1. Set the necessary copy options to the project:

  1. After that, your project in Xcode should contain DevinoSDK.framework:

  1. Go to Build Phases and add DevinoSDK.framework to Embed Frameworks:

Adding Devino Notification Service Extension to your Xcode project

  1. Adding Notification Service Extension (File -> New -> Target -> Notification Service Extension):

  1. Correctly setup all targets iOS versions in project and Project Deployment Target, every targets must have the same versions.

  1. Connection DevinoNotificationService:
import DevinoSDK
import UserNotifications

class NotificationService: DevinoNotificationService {
    
    override var appGroupsId: String? {
        return "group.com.fruktorum.DevinoPush"
    }
    
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        super.didReceive(request, withContentHandler: contentHandler)
        // Your code
    }
}
  1. Add AppGroups in Signing & Capabilities for project targets and NotificationService
  2. While debugging the NotificationService, make sure you have started the project correctly. You should build and run the NotificationService extension schema.

Notification Service Extension needed to modify the contents of notifications (for example, to display pictures in notifications).

Configuring DevinoSDK in AppDelegate:

1. Adding import DevinoSDK:

import DevinoSDK

2. Initialize DevinoUNUserNotificationCenter:

let devinoUNUserNotificationCenter = DevinoUNUserNotificationCenter()

3. Setting the AppGroupID previously created in Apple Developer Account (appGroupId):

let appGroupId = "group.com.fruktorum.DevinoPush" //example

4. Making settings in the didFinishLaunchingWithOptions method:

Add the Devino API key (key) and the PushApplication identifier (applicationId), which are issued after registering your application in your personal account. Also, you can specify the interval for updating geolocation data in minutes (geoDataSendindInterval). The default is 0 minutes - never transfer data. Also register the Apple Push Notification service.

Example didFinishLaunchingWithOptions:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// set Devino configurations:
    let config = Devino.Configuration(key: "<key>", applicationId: <id>, appGroupId: <appGroupId>, geoDataSendindInterval: 1)
    Devino.shared.activate(with: config)
    Devino.shared.trackLaunchWithOptions(launchOptions)
// registration process with Apple Push Notification service:
    application.registerForRemoteNotifications()
    return true
 }

5. In the didFinishLaunchingWithOptions method, assign the delegate object to the UNUserNotificationCenter object:

// assign delegate object to the UNUserNotificationCenter object:
    UNUserNotificationCenter.current().delegate = devinoUNUserNotificationCenter

6. Handlers of Action buttons in notifications:

devinoUNUserNotificationCenter.setActionForUrl { url in
    // url action
}
devinoUNUserNotificationCenter.setActionForDefault {
    // default action
}
devinoUNUserNotificationCenter.setActionForDismiss {
    // dismiss action
}
devinoUNUserNotificationCenter.setActionForCustomDefault { action in
    // tap action on push
}

7. Authentification with deviceToken:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Devino.shared.registerForNotification(deviceToken)
}

8. Tracking subscription status:

func applicationWillEnterForeground(_ application: UIApplication) {
    Devino.shared.trackAppLaunch()
}

9. Tracking application termination:

func applicationWillTerminate(_ application: UIApplication) {
    Devino.shared.trackAppTerminated()
}

10. Receive Remote Notifications:

public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    Devino.shared.trackReceiveRemoteNotification(userInfo)
    completionHandler(.newData)
}

11. Tracking Local Notifications:

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, completionHandler: @escaping () -> Void) {
    Devino.shared.trackLocalNotification(notification, with: identifier)
    completionHandler()
}

Functionality DevinoSDK:

1. Change user notification status:

  • Subscription: if confirmation of receipt of notifications is not required or it has been successful;
  • Unsubscribe: if the user has disabled notifications in the application.

If the user has changed the notification settings in the system, the SDK monitors this event automatically.

2. Sending user notification status:

public func sendCurrentSubscriptionStatus(isSubscribe: Bool)

Example:

Devino.shared.sendCurrentSubscriptionStatus(isSubscribe: true)

3. Receive user notification status:

public func getLastSubscriptionStatus(_ completionHandler: @escaping (Bool) -> Void)

Example:

Devino.shared.getLastSubscriptionStatus { result in
    //do smth with result
}

4. Update user data:

public func setUserData(phone: String?, email: String?)

It is used in two cases:

  • The user logged in to the application (automatically);
  • The user has changed his personal data.

Example:

Devino.shared.setUserData(phone: "+79123456789", email: "test@gmail.com")

Phone format - +79XXXXXXXXX, email format - XXXX@XX.XX

To update user data, all fields are required.

5. Set a custom URL on the registartion screen:

final public func setupApiRootUrl(with apiRootUrl: String)

Example:

Devino.shared.setupApiRootUrl(with: "https://integrationapi.net")

5. Send geolocation:

In the Info.plist file sets the permissions Privacy - Location Always and When In Use Usage Description and Privacy - Location When In Use Usage Description to read the geolocation.

Definition method of tracking location:

public func trackLocation()

Geolocation tracking is called once every N minutes. Minutes are specified using the geoDataSendindInterval property in the settings. Example:

Devino.shared.trackLocation()

A notification with coordinates comes after determining the geolocation. Notification example:

Send custom Push Notifications:

Push notification options:

Parameter Type Description Example Required field
title String Push message header (up to 50 characters) "Title" No
text String Text Push Messages (up to 150 characters) "text" No
badge Badge .zero (0) - if you need to remove the badge icon, .one (1) .zero No
validity Int Push message lifetime, maximum is 2419200 (in seconds) 2419200 No
priority Priority Message sending priority .realtime No
silentPush Bool A flag that tells the recipient that it does not need to be displayed to the client when receiving a notification false No
options [String: Any] Additional parameters to be transferred to the device ["key": "value"] No
sound String The name of the sound file from the application. If no sound file is found, or if a default value is specified (“default”), the system plays a default warning sound. "push_sound.wav" No
buttons [ActionButton] Active buttons notification. A maximum of 3 objects can be added. [ActionButton(caption: "Title", action: "https://...")] No
linkToMedia String Additional attachments notifications (pictures, sounds, videos) "https://..." No
action String The action that should occur when a notification is clicked "https://..." No

Badge definition:

public enum Badge: Int {
    case zero = 0
    case one = 1
}

Priority definition:

public enum Priority: String {
    case mediul = "MEDIUM"
    case low = "LOW"
    case high = "HIGH"
    case realtime = "REALTIME"
}

ActionButton definition:

public class ActionButton {
    var caption: String //name button
    var action: String //urls/deep link
} 

Method definition:

public func sendPushNotification(title: String? = "Devino Telecom", text: String? = "Text notification", badge: DevinoSDK.Badge? = nil, validity: Int? = 2419200, priority: DevinoSDK.Priority = .realtime, silentPush: Bool? = nil, options: [String : Any]? = nil, sound: String? = "default", buttons: [DevinoSDK.ActionButton]? = nil, linkToMedia: String? = nil, action: String? = nil)

Example:

Devino.shared.sendPushNotification(sound: "push_sound.wav", linkToMedia: https://i.gyazo.com/3dd58384ebf8c8b9bf39e7f445c8fb16.png)

Logs from SDK:

Property definition:

public var logger: ((String) -> Void)?

Example:

Devino.shared.logger = { logStr in
   //do something 
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.0%
  • Objective-C 1.0%