Push Notification Mobile SDKs


Syniverse Mobile SDKs enable easy integration between the mobile applications and the Syniverse Omni-channel API to send push notifications. The customer have the choice to integrate directly with the APIs but can optionally choose to use the mobile SDKs for integration to simplify the integration within the mobile application.

Syniverse iOS Mobile SDK for Push Notifications.

The SDK is available via CoCoaPods.org

https://cocoapods.org/

How to integrate the SDK within the mobile application

Step 1 : Before using scg-messaging-ios cocoapod a developer need to install pod utility on target OS with next command.

brew install pod

With pod utility installed, the developer can add the SCG messagin-ios SDK to the target project.

If this is a new project or a Podfile does not exist, run the following command.

pod init

Step 2: Add the following line to the Podfile. 

pod 'scg-messaing-ios'

Step 3: Install the pod using the following command.

pod install

After successful installation, the SCG messaging-ios SDK will be ready to use.

 

Interface

@interface SCGPush : NSObject
 
+ (instancetype _Nonnull) sharedInstance;
 
@property (atomic, copy, nonnull) NSString* accessToken;
@property (atomic, copy, nonnull) NSString* callbackURI;
@property (atomic, copy, nonnull) NSString* appID;
 
- (void) startWithAccessToken: (NSString* _Nonnull) accessToken
                        appId: (NSString* _Nonnull) appId
                  callbackUri: (NSString* _Nonnull) callbackUri;
 
- (void) registerPushToken:( NSString* _Nonnull) pushToken
     withCompletionHandler:( void (^ _Nullable)(NSString * _Nullable token)) completionBlock
              failureBlock:( void (^ _Nullable)(NSError * _Nullable error)) failureBlock;
 
- (void) unregisterPushToken:( NSString* _Nonnull) pushToken
       withCompletionHandler:( void (^ _Nullable)(NSString * _Nullable token)) completionBlock
                failureBlock:( void (^ _Nullable)(NSError * _Nullable error)) failureBlock;
 
- (void) reportStatus: ( NSString* _Nonnull) messageId
                   andMessageState: ( MessageState ) state
                   completionBlock: ( void(^ _Nullable)(void)    ) completionBlock
                      failureBlock: ( void(^ _Nullable) (NSError* _Nullable error)) failureBlock;
 
- (void) loadAttachmentWithMessageId:(NSString* _Nonnull) messageId
                     andAttachmentId:(NSString* _Nonnull) attachmentId
                     completionBlock:(void(^_Nullable)(NSURL* _Nonnull contentUrl, NSString* _Nonnull contentType))completionBlock
                        failureBlock:(void(^_Nullable)(NSError* _Nullable error))failureBlock;
 
- (void) resetBadgeForPushToken: (NSString* _Nonnull) pushToken
                completionBlock: (void(^_Nullable)(BOOL success, NSError* _Nullable error)) completionBlock;
     
@end

 

How to use the SDK

  • Import SDK into your source code
import SCGPushSDK
// Initialise instance of SDK
var SCGPushSdk: SCGPush = SCGPush.sharedInstance()

 

  •  SCG Push SDK provides a singleton to access all the SDK methods across the application. To access singleton instance, use sharedInstance() accessor
SCGPush.sharedInstance()

 

  • The sharedInstance will be available with a set of properties required for all operations, so before using SDK configure the properties
func initSdk() -> Bool {
        SCGPush.sharedInstance().appID = "APPLICATION ID"
        SCGPush.sharedInstance().callbackURI = "https://gateway1-scg-api.syniverse.com/scg-dra-core-service/proxy/" // Endpoint what will be use to send next callbacks DELIVERED|READ|CLICKTHRU|RESET_BADGET
        SCGPush.sharedInstance().accessToken = accessToken
        SCGPush.sharedInstance().type = "APN" // type could be "FCM" in case if you going to use Firebase Cloud Messaging for integraion
        return true
}

 

  • To register your mobile application with the Omni-channel API you need to call next method (Example is shown for Firebase Cloud Messaging flow. For APN it will require APN type and APN token.)
func registerInScgPushService(fcmToken: String, bundleId: String, baseUrl: String, accessToken: String) {
        var sdk: SCGPush = SCGPush.sharedInstance()
        sdk.start(withAccessToken: accessToken, appId: bundleId, callbackUri: baseUrl)
        sdk.registerToken(fcmToken, withCompletionHandler: { (registeredToken) in
            DemoApplication.shared().setState(state: DemoApplication.RegistrationStates.registered)
        }) { (error) in
            if let error = error as NSError? {
                if error.code == self.UnauthoruzedStatusCode {
                    self.alert?.error(message: "\(errorMsg). Invalid access token")
                } else {
                    self.alert?.error(message: "\(errorMsg): \(error.localizedDescription)")
                }
            } else {
                self.alert?.error(message: errorMsg)
            }
        }
    }

 

  • To unregister your mobile application with the Omni-channel API.
func unregisterButtonTapped(token: String) {
        var sdk: SCGPush = SCGPush.sharedInstance()
        sdk.unregisterPushToken(token, withCompletionHandler: {
        }) { (error) in
            if let error = error as NSError? {
                if error.code == self.UnauthoruzedStatusCode {
                    debugPrint("Warning: Access token has expired")
                }else {
                    debugPrint(errorMsg, ":", error.localizedDescription)
                }
            } else {
                debugPrint(errorMsg)
            }
        }
    }

 

  • To send a push notification state change callback event for the received notification.
func sendReport(state: MessageState, notificationId: String, sdk: SCGPush) {
            sdk.reportStatus(
                withMessageId: notificationId,
                andMessageState: state,
                completionBlock: {
            },
                failureBlock: { (error) in
                    debugPrint("Error: reportStatus  withMessageId: \(notificationId), error: \((error?.localizedDescription)!)")
            })
        }
    }

 

  • The push notification state needs to be updating prior to reporting the status for notification based on the predefined constants.
switch state {
            case SilentMessage.statuses.delivered.rawValue:
                return MessageState.delivered
            case SilentMessage.statuses.read.rawValue:
                return MessageState.read
            case SilentMessage.statuses.clickthrough.rawValue:
                return MessageState.clicked
            default:
                return MessageState.delivered
        }

 

  • To reset the badge count.
func resetBadgeButtonTapped(_ sender: Any) {
        var sdk: SCGPush = SCGPush.sharedInstance()
        sdk.resetBadge(forPushToken: token) { (success, error) in
            if (success) {
              
            }

            if let error = error as NSError? {
                if error.code == self.UnauthoruzedStatusCode {
                    debugPrint("Warning: Access token has expired")
                } else {
                    debugPrint("Unable to reset badge: \(error.localizedDescription)")
                }
            }
        }
    }

 

  • To load attachments using the Omni-channel API.
func downloadFileData(attachmentId: String, sdk: SCGPush, messageId: String,completionBlock: @escaping ((_ fileUrl: URL, _ contentType: String) -> Void),
                            failureBlock: @escaping (_ error: DemoError) -> Void) {
        sdk.loadAttachment(withMessageId: messageId,andAttachmentId: attachmentId,completionBlock: 
         { (contentUrl, contentType) in completionBlock(contentUrl, contentType)
         }) 
         { (error) in
            print("Error: unable to load attachment \(attachmentId); \(error?.localizedDescription ?? "unknown")")
            failureBlock(DemoError.unableToDownloadAttachment)
         }
    }

Syniverse Android Mobile SDK for Push Notification.

The SDK is available via MavenCentral.

Syniverse Android SDK for Push Notifications

How to integrate the SDK into your mobile application

To integrate the SCG messaging-android SDK you need to add it to you project in dependencies tree

<dependency>
    <groupId>com.syniverse.sdk</groupId>
    <artifactId>scg-messaging-android-api</artifactId>
    <version>1.0.2.950</version>
 </dependency>

How to use the SDK

After successful installation SCG messaging-android SDK will be ready to use. Onwards will be explained an example how to manipulate SDK

  • Public interface of the SDK with Session.class
public interface Session {
  Observable<Result> open();
  Observable<Result> close();
  Observable<Result> confirmationFor(String messageId, ConfirmationType type);
  Observable<ResponseBody> getAttachment(String messageId, String attachmentId);
}

 

  • Import the SDK into your source code
import com.syniverse.sdk.SyniverseSession;
import com.syniverse.sdk.Session;

 

  • To create a new instance of the SDK
class TestSDK {  private static final String firebaseToken = "firebaseToken";
  private static final String accessToken = "accessToken";
  private static final String applicationId = "applicationId";
  public void test() {      final Session session = new SyniverseSession(url, applicationId, accessToken, firebaseToken); // where url could be https://gateway1-scg-api.syniverse.com/scg-dra-core-service/proxy/  }
}

 

  • To register your mobile application in Omni-channel API you need to call next method
public void expect_to_register_successfully() {
    final SyniverseSession session = new SyniverseSession(url(), applicationId, accessToken, firebaseToken);
    final Observable<Result> result = session.open();
}

 

  • To unregister your mobile application with the Omni-Channel API
public void expect_to_register_successfully() {
    final SyniverseSession session = new SyniverseSession(url(), applicationId, accessToken, firebaseToken);
    final Observable<Result> result = session.close();
}

 

  • To send callback for received message
public void expect_to_confirm_delivery(Session session) {
    final Observable<Result> result = session.confirmationFor("message-id", ConfirmationType.DELIVERED); //
}

    Notification state needs to be updated prior to reporting status for notification based on the predefined constants.

public enum ConfirmationType {
  DELIVERED,
  READ,
  CLICKTHRU,
  RESET_BADGE
}

 

  • To load attachment with SCG API
public void expect_to_load_attachment(Session session) throws IOException {
    Observable<ResponseBody> result = session.getAttachment("some-message-id", "some-attachment-id");
}