Skip to content

nekrich/GlobalMessageService-iOS

Repository files navigation

Swift 2.2 Platforms iOS Build Status

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate GlobalMessageService into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '8.0'
use_frameworks!

pre_install do |installer|
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  def installer.verify_no_static_framework_transitive_dependencies; end
end

pod 'GlobalMessageService', :git => 'https://github.com/GlobalMessageServicesAG/GlobalMessageService-iOS.git', :tag => '0.0.4'

Then, run the following command:

$ pod install

Add files

Add GMSGoogleCloudMessagingDelegate.swift file to your project

Configure target

Disable bitcode (set ENABLE_BITCODE to false) in build settings for your target. See Google Cloud Messaging issue

Modify AppDelegate

Add import statement
import GlobalMessageService

In func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool add following

  GlobalMessageService.register(
    applicationKey: "Your Global Message Service Key",
    googleCloudMessagingHelper: GMSGoogleCloudMessagingDelegate.sharedInstance,
    andGoogleCloudMessagingSenderID: "Your Google Cloud Messaging Sender ID")

In func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) add following

  GlobalMessageService.applicationDidRegisterForRemoteNotificationsWithDeviceToken(deviceToken)

In func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) add following

  GlobalMessageService.applicationDidReceiveRemoteNotification(userInfo)

  completionHandler(.NewData)

Register your application for Remote Notification

Certificates

Configure push-notifications in Certificates, Identifiers & Profiles section of Apple Developer Member Center (manual)

Registering for Remote Notifications

Register your application to receive remote push-notifications (manual)

Usage

To start using GlobalMessageService framework you should provide correct subscriber e-mail & phone (optionally)

Subscriber information

Add

To add new subscriber you should call

GlobalMessageService.addSubscriber(
  email: String,
  phone: Int64?,
  completionHandler: ((GlobalMessageServiceResult<UInt>) -> Void)? = .None)

In completion handler result you will get GlobalMessageService subscriber ID if success

Edit

To edit subscriber information you should call

GlobalMessageService.updateSubscriberInfo(
  email: String,
  phone: Int64?,
  completionHandler: ((GlobalMessageServiceResult<Void>) -> Void)? = .None)

In completion handler result you will get success Bool flag

Update subscriber's location

GlobalMessageService.updateSubscriberLocation(
  location: CLLocation?,
  completionHandler: ((GlobalMessageServiceResult<Void>) -> Void)? = .None)

Update subscriber's changed Google cloud messages token

GlobalMessageService.updateGCMToken(
  token: String?,
  completionHandler: ((GlobalMessageServiceResult<Void>) -> Void)? = .None)

Update subscriber can receive push-notifications flag

GlobalMessageService.allowRecievePush(
  allowPush: Bool,
  completionHandler: ((GlobalMessageServiceResult<Void>) -> Void)? = .None)

Get delivered messages

To fetch delivered messages call

GlobalMessageService.fetchMessages(
  forDate: NSDate,
  completionHandler: ((GlobalMessageServiceResult<[GlobalMessageServiceMessage]>) -> Void)? = .None)

Example

let someDate = NSDate()
GlobalMessageService.fetchMessages(forDate: someDate) { result in
  guard let messages = result.value else { return }
  // you code goes here
}

How to get keys, push-notifications, IDs

GlobalMessageService application key

Contact Global Message Services

Google Cloud Messaging (push-notifications)

Enable Google Cloud Messaging API for you project

Enable Google services for your app

Google Cloud Messaging Sender ID

Google Cloud Messaging Sender ID is your Project number that you can get in Google Developer Console

License

[MIT][LICENSE] [LICENSE]: LICENSE

3rdparties

XCGLogger by Dave Wood. MIT license

Google Cloud Messaging

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages