Added an identifier to the HTTP requests.
To use this library you must have Firebase configured in your app. Don't know how to do it? Read this article.
Note: Since the main objective of this library is to handle push notifications, the only Pod that is required for it to work is pod 'Firebase/Messaging'
.
You must have an APNs key inserted on the Firebase App. Read more here.
You must have an E-goi account with a Push application configured.
You must have the following properties inserted in your Info.plist:
- Required background modes
- App registers for location updates
- App processes data in the background
- App downloads content in response to push notifications
- Privacy - Location Always and When In Use Usage Description
- Privacy - Location When In Use Usage Description
EgoiPushLibrary is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EgoiPushLibrary'
After installing, you can initialize the library in the AppDelegate.swift with following instruction:
Note: Your AppDelegate should extend our EgoiAppDelegate instead of the UIResponder, UIApplicationDelegate. If you are using a SceneDelegate, you must also extend ou EgoiSceneDelegate. This is a way for us to process logic, so you don't have to, like processing the received remote notifications, and it allows us to display Alerts in your app.
Note: If you want to be the one handling the notifications, you should extend our EgoiAppDelegateViewOnly, so we do not take control of the UNUserNotificationCenter.
import EgoiPushLibrary
class AppDelegate: EgoiAppDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
EgoiPushLibrary.shared.config(
appId: "abc",
apiKey: "abc",
dialogCallBack: { message in
print(message)
},
deepLinkCallBack: { message in
print(message)
}
)
return true
}
}
Still in the AppDelegate.swift, you can send the Firebase token to the library with the following code:
extension AppDelegate : MessagingDelegate {
public func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
) {
guard let token = fcmToken else {
return
}
EgoiPushLibrary.shared.addFCMToken(token: token)
}
}
To display the images and actions defined in your E-goi campaign in the notification, you will need to generate a NotificationServiceExtension to process the logic before the OS displays it in the device. To do that you can follow the instructions in this link. After generating the file, you can copy and past the content of our NotificationService (make sure the class name is the one you generated and not the one of our file).
In your Podfile, you will need to add 'Firebase/Messaging' as a dependency of your NotificationServiceExtension.
Responsible for initializing the library. The call of this method is required.
Property | Type | Description | Required | Default |
---|---|---|---|---|
appId | String | The ID of the app created on the E-goi account. | true | --- |
apiKey | String | The API key of your E-goi account. | true | --- |
geoEnabled | Bool | Flag that enables or disabled location related functionalities. | false | true |
dialogCallBack | EGoiMessage -> Void | Callback to be called in the place of the dialog. | false | nil |
deepLinkCallBack | EGoiMessage -> Void | Callback to be called when the link of the message is a deeplink | false | nil |
You should call this method everytime a new Firebase token is generated. The token is saved on the library and, if the user is already registered on your E-goi list, updates the token automatically.
Property | Type | Description | Required | Default |
---|---|---|---|---|
token | String | The token generated by Firebase. | true | --- |
This method processes the received remote notification. If the remote notification is a geopush, creates a geofence that triggers a local notification when the user enters the region. If it is a normal notification, shows the notification and opens a dialog with the actions defined in E-goi when the user opens the notification banner.
This method is already called inside the didReceiveRemoteNotification implemented in EgoiAppDelegate.swift but you can call it if you are the one processing the notification.
Property | Type | Description | Required | Default |
---|---|---|---|---|
userInfo | [AnyHashable : Any] | The data of the notification. | true | --- |
callback | @escaping (UIBackgroundFetchResult) -> Void | The callback that will be called when the processing of the notification is finished. | true | --- |
This method handles the interaction of the user with the notification. If the user clicks the notification, open the app and launch a dialog with actions defined. If the user clicks on the "see" action, open the url defined on the notification in the default browser or tries to call the deeplinkCallback defined in the SDK configs. It also sends the event "open" or "canceled" to E-goi depending on the interaction of the user.
If you are the one handling the notifications, you should invoke this method inside the didReceive method of the UNUserNotificationCenterDelegate.
Property | Type | Description | Required | Default |
---|---|---|---|---|
response | UNNotificationResponse | The interaction the user made with the notification | true | --- |
userNotificationCenter | UNUserNotificationCenter | The current UNUserNotificationCenter instance. It is used to manage the notification categories created by E-goi. | false | nil |
completionHandler | () -> Void | The callback to invoke after processing the interaction. | false | nil |
Requests the user permission to access the location when the app is in the foreground (displaying on screen).
Requests the user permission to access the location when the app is in background (minimized or closed).
Requests the user permission to send push notifications.
Registers the Firebase token on the E-goi list. You only need to call this method once, after that, the library automatically updates the E-goi's list contact with the new tokens.
Property | Type | Description | Required | Default |
---|---|---|---|---|
field | String | The field on the list that will be used to register the token. | false | nil |
value | String | The value that will be used to register on the field defined above. | false | nil |
callback | @escaping (_ success: Bool, _ message: String?) -> Void | The callback that will be called when the E-goi's server finishes processing the request | true | --- |
Register an event related to a notification in E-goi.
Property | Type | Description | Required | Default |
---|---|---|---|---|
event | String | The event to register in E-goi. | true | --- |
message | EGoiMessage | The message associated to the event | true | --- |
E-goi, [email protected]
EgoiPushLibrary is available under the MIT license. See the LICENSE file for more info.