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 GMSGoogleCloudMessagingDelegate.swift
file to your project
Disable bitcode (set ENABLE_BITCODE
to false
) in build settings for your target. See Google Cloud Messaging issue
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)
Configure push-notifications in Certificates, Identifiers & Profiles section of Apple Developer Member Center (manual)
Register your application to receive remote push-notifications (manual)
To start using GlobalMessageService framework you should provide correct subscriber e-mail & phone (optionally)
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
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)
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
}
Contact Global Message Services
Enable Google Cloud Messaging API for you project
Enable Google services for your app
Google Cloud Messaging Sender ID is your Project number that you can get in Google Developer Console
[MIT][LICENSE] [LICENSE]: LICENSE