If your project doesn’t have the CocoaPods setup then start with pod init which will create the Podfile, else do following changes in the pod file to install GenuinSDK.
Copy
platform :ios, '13.0'target 'YourProject' do use_frameworks! # Pods for YourProject pod "GenuinSDK", :git => "https://bitbucket.org/genuindev/genuin_sdk_ios.git", :tag => "1.1.17"endpost_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0' config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES' end endend
If you are using Xcode 16 then kindly refer the below podfile :
Copy
platform :ios, '13.0'target 'YourProject' do use_frameworks!pod "GenuinSDK", :git => "https://bitbucket.org/genuindev/genuin_sdk_ios.git", :tag => "1.1.17"endpost_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'Giphy' `xcrun -sdk iphoneos bitcode_strip -r Pods/Giphy/GiphySDK/GiphyUISDK.xcframework/ios-arm64_armv7/GiphyUISDK.framework/GiphyUISDK -o Pods/Giphy/GiphySDK/GiphyUISDK.xcframework/ios-arm64_armv7/GiphyUISDK.framework/GiphyUISDK` end target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0' config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES' end endend
Example
Import the GenuinSDK module in your SceneDelegate/AppDelegate.
Copy
import GenuinSDKfunc scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Optional configuration and attaching the UIWindow to UIWindowScene guard let _ = (scene as? UIWindowScene) else { return } // Initialize the SDK configuration let configuration = GenuinConfiguration.shared // For Production environment (Default) configuration.setCustomLoader("YOUR_LOADER", bundle: .main) // For QA Environment configuration.environment = .qa // Initialize the SDK with your API key and configuration GenuinSDK.shared.initialize(apiKey: "YOUR_API_KEY", configuration: configuration) // Notify the SDK that the scene will connect GenuinSDK.shared.scene(scene, willConnectTo: session, options: connectionOptions)}
To load your lottie animation accross the Genuin SDK, you can add it here configuration.setCustomLoader("YOUR_LOADER", bundle: .main)
To present feed from your UIViewController by clicking on UIButton:
ViewController.swift
Copy
import UIKitimport GenuinSDKclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func openFeed() { if let vc = GenuinSDK.shared.getHomeScreen() { vc.navigationBar.isTranslucent = false vc.modalPresentationStyle = .fullScreen self.present(vc, animated: true) } }}
Note: Our SDK is well optimized for iOS version 15.0 and above, but if you are using iOS version 13 or 14 then put this if #available(iOS 15.0, *) condition while importing the GenuinSDK. Refer to the below code block
Copy
// Below is an Example Codeif #available(iOS 15.0, *) { // Initialize the SDK with your API key and configuration GenuinSDK.shared.initialize(apiKey: "YOUR_API_KEY", configuration: configuration) if let vc = GenuinSDK.shared.getHomeScreen() { vc.tabBarItem = UITabBarItem(title: "Community", image: UIImage(systemName: "person.3"), tag: 3) self.viewControllers = [vc] self.selectedIndex = 0 }}
To enable Monetization use following code snippet to get advertisingIdentifier by AppTrackingTranspancy. You need to add NSUserTrackingUsageDescription in Info.plist as described here.
Copy
import AppTrackingTransparencyimport AdSupport //Import only if you want to use advertisingIdentifierclass SceneDelegate: UIResponder, UIWindowSceneDelegate { func sceneDidBecomeActive(_ scene: UIScene) { // Called when the scene has moved from an inactive state to an active state. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. DispatchQueue.main.async { ATTrackingManager.requestTrackingAuthorization { status in switch status { case .notDetermined: break case .restricted: break case .denied: break case .authorized: // If you want to check the current advertisingIdentifier print("advertisingIdentifier: ", ASIdentifierManager.shared().advertisingIdentifier.uuidString) break @unknown default: break } } } }}
Also if you enable monetization then you need to update App Privacy in AppStoreConnect
Need to declare in App Store Connect that your app is using Advertising Data
Steps:
Log in to your App Store Connect.
Select the app you are working on.
Go to App Privacy > Data Collection.
Find the Usage Data section and select the Advertising Data.
Click on Save/Publish.
Now Setup Advertising Data by selecting (Third-Party Advertising, Analytics, Product Personalization, App Functionality, Other Purposes)
Note: To fetch the Embed you need to add YOUR_EMBED_ID, YOUR_CONTAINER_VIEW in which you want the embed, and YOUR_VIEW_CONTROLLER containing your container view, while calling the below function. For auto login in the SDK, you shall pass “YOUR_SSO_TOKEN” in order to implement Embed with SSO in your app.
In EmbedConfiguration there is new option called genuinCarouselConfiguration by using it we can change the configs of carousel design.
Copy
// Below is an Example Codelet genuinCarouselConfiguration = GenuinCarouselConfiguration()genuinCarouselConfiguration.interTileSpacing = 16.0genuinCarouselConfiguration.scrollDirection = .vertical //default value is .horizontal as described above.genuinCarouselConfiguration.tileCornerRadius = 16.0genuinCarouselConfiguration.aspectRatio = .ratio4x5let embedConfiguration = EmbedConfiguration()embedConfiguration.genuinCarouselConfiguration = genuinCarouselConfiguration //here you can pass the GenuinCarouselConfigurationGenuinSDK.shared.initializeEmbed(embedId: "YOUR_KEY", containerView: <YOUR_CONTAINER_VIEW>, viewConroller: self, embedConfiguration: embedConfiguration)
Note: To fetch the Embed you need to add YOUR_EMBED_ID, YOUR_CONTAINER_VIEW in which you want the embed, and YOUR_VIEW_CONTROLLER containing your container view, while calling the above function. For auto login in the SDK, you shall pass “YOUR_SSO_TOKEN” in order to implement Embed with SSO in your app.
To configure the EmbedConfiguration based on your need you can change the below values.
isShowProfileEnabled = This is an optional boolean parameter. Default value is false. If this parameter is true and also if user is logged in than Profile picture will be visible in full screen view (right side top corner). On clicking the profile picture user will see the account settings and logout options.
isDirectDeepLinkEnabled = This is an optional boolean parameter. Default value is false. If this parameter is true then all the interaction/clicks in the full screen view will redirect to the specific video in white labelled app associated with video and also value of this parameter “interactionDeepLink” will be ignored. If not passed then the regular flow will work.
interactionDeepLink = This is an optional parameter. You can pass a deeplink URL in this parameter. If a deeplink URL is given then all the interaction/clicks in the full screen view will redirect to the deeplink URL given. If not passed then the regular flow will work. It should be a correct URL else user will not be redirected.
genuinCarouselConfiguration = This is an optional parameter. You can pass GenuinCarouselConfiguration object in this parameter. If GenuinCarouselConfiguration is provided then the carousel design will change accordingly. The default values are listed below, which you can pass in GenuinCarouselConfiguration object.
interTileSpacing - spacing between the carousel’s collection view items. It’s default value is 8.0
carouselInset - edge insets for carousel’s collection view. It’s default value is UIEdgeInsets(top: 8.0, left: 16.0, bottom: 0.0, right: 16.0)
scrollDirection - direction of carousel scroll. It’s default value is .horizontal
aspectRatio - define aspect ratio of carousel’s collection view items. It’s default value is .ratio9x16
tileCornerRadius - cornerRadius for the carousel’s collection view items. It’s default value is 8.0
Below are the optional parameters for the params key:
name - This is an optional string parameter. Pass this parameter for ‘signup/login’.
mobile - This is an optional string parameter. Pass this parameter for signup/login.
email - This is an optional string parameter. Pass this parameter for signup/login.
nickname - This is an optional string parameter. If nickname is available in genuin ecosystem it will be used, else genuin will generate of its own.
profile_image: This is an optional string parameter. Pass the profile_image parameter if you want to show the profile image in the SDK.
Below are the optional parameters for the contextualParams key:
page_context - This is an optional string parameter. Pass this parameter for ‘context’, so that feed could load based on that context.
lat - This is an optional float parameter. Pass this parameter in geo so that the feed could load based on the latitude and context.
long - This is an optional float parameter. Pass this parameter in geo so that the feed could load based on the longitude and context.
Note: lat and long both parameters shall be passed in order to implement the contextual feed based on the location.
Once the file is created, host it on the white labeled domain at https://YOUR_WHITE-LABELLED_DOMAIN/.well-known/apple-app-site-association
Add Associated Domains in capabilities if not already,
Add applinks in domains, for Example:
applinks: YOUR_WHITE-LABELLED_DOMAIN
applinks: www.YOUR_WHITE-LABELLED_DOMAIN
To handle deep links in your app use the following methods.
Copy
class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let _ = (scene as? UIWindowScene) else { return } handleGenuinDeeplink(deeplinkURL: connectionOptions.userActivities.first?.webpageURL) } func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { //redirect if genuin SDK handles the deeplink handleGenuinDeeplink(deeplinkURL: userActivity.webpageURL) } func handleGenuinDeeplink(deeplinkURL: URL?) { if let dlURL = deeplinkURL, GenuinSDK.shared.willHandleDeepLink(url: dlURL){ GenuinSDK.initDeeplinkWith(url: dlURL) if let rootVC = window?.rootViewController as? UIViewController{ DispatchQueue.main.async { GenuinSDK.shared.handleDeeplink(viewController: rootVC) } } } }}
Note: GenuinSDK.shared.willHandleDeepLink(url: dlURL) function will check whether GenuinSDK will handle the given deeplink or not. You can use it according to your deeplink redirection flow.
Create an app in your firebase console by following these steps
Download the GoogleService-Info.plist file and add it in xcode project
Add pod in pod file
Copy
pod 'FirebaseMessaging', '~> 10.24.0'
To enable the push notifications functionality then enable the Push Notifications in your target. To do so, Select the target > Signing & Capabilities > Add Capability of Push Notification
Note: Pass true value in isFCMIntegrated parameter, as we are using the Firebase.
Initialize
SceneDelegate
Copy
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let _ = (scene as? UIWindowScene) else { return } //Register the notification registerForNotification() //configure firebase FirebaseApp.configure() //set delegate , extend current class with MessagingDelegate Messaging.messaging().delegate = self }
Place this code to take the user permission for Push Notification
Copy
func registerForNotification(){ //Take permission and register remote notification let current = UNUserNotificationCenter.current() current.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined{ self.requestForNotificationPermission() }else if settings.authorizationStatus == .authorized { UNUserNotificationCenter.current().delegate = self DispatchQueue.main.async{ UIApplication.shared.registerForRemoteNotifications() } } }) } private func requestForNotificationPermission(){ UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in print(granted) } UIApplication.shared.registerForRemoteNotifications() }
Extend MessagingDelegate and Add follwing method:
Copy
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { if let token = fcmToken { //fetch and register token getInstanceID() } } func getInstanceID(){ Messaging.messaging().token { token, error in // Check for error. Otherwise do what you will with token here if let error = error { print("Error fetching remote instance ID: \(error)") } else if let result = token { print("Remote instance ID token: \(result)") GenuinSDK.shared.registerFCMToken(token: result) } } }
To Handle the Push Notification Redirection whenever the user taps, follow the below code
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if let userInfo = response.notification.request.content.userInfo as? [String: AnyObject]{ //notify firebase Messaging.messaging().appDidReceiveMessage(userInfo) //check if genuin will handle notification if GenuinSDK.shared.willHandleNotification(userInfo: userInfo){ //notify to redirect GenuinSDK.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler) //notification notification if let rootVC = window?.rootViewController as? UIViewController{ GenuinSDK.shared.handleNotifications(viewController: rootVC) } } } }
Note: GenuinSDK.shared.willHandleNotification(userInfo: userInfo) function will check whether GenuinSDK will handle the given notification or not. You can use it according to your notification redirection flow.
To configure notification UI
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){ let userInfo = notification.request.content.userInfo print("\(userInfo)") //mention design type for notification completionHandler([.list, .badge, .sound]) }
If you want to handle the notification when app is opened then follow the below code
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){ let userInfo = notification.request.content.userInfo GenuinSDK.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler) if let rootVC = window?.rootViewController as? UIViewController{ GenuinSDK.shared.handleNotifications(viewController: rootVC) } //mention design type for notification completionHandler([.list, .badge, .sound]) }
Note: To handle the notification from another controller call the GenuinSDK.shared.handleNotifications(viewController: YOUR_VIEW_CONTROLLER) function
To enable the push notifications functionality then enable the Push Notifications in your target. To do so, Select the target > Signing & Capabilities > Add Capability of Push Notification
Place this code to take the user permission for Push Notification
Copy
func registerForNotification(){ //Take permission and register remote notification let current = UNUserNotificationCenter.current() current.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined{ self.requestForNotificationPermission() }else if settings.authorizationStatus == .authorized { UNUserNotificationCenter.current().delegate = self DispatchQueue.main.async{ UIApplication.shared.registerForRemoteNotifications() } } }) } private func requestForNotificationPermission(){ UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in print(granted) } UIApplication.shared.registerForRemoteNotifications() }
To Handle the Push Notification Redirection whenever the user taps, follow the below code
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if let userInfo = response.notification.request.content.userInfo as? [String: AnyObject]{ //check if genuin will handle notification if GenuinSDK.shared.willHandleNotification(userInfo: userInfo){ //notify to redirect GenuinSDK.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler) //notification notification if let rootVC = window?.rootViewController as? UIViewController{ GenuinSDK.shared.handleNotifications(viewController: rootVC) } } } }
Note: GenuinSDK.shared.willHandleNotification(userInfo: userInfo) function will check whether GenuinSDK will handle the given notification or not. You can use it according to your notification redirection flow.
To configure notification UI
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){ let userInfo = notification.request.content.userInfo print("\(userInfo)") //mention design type for notification completionHandler([.list, .badge, .sound]) }
If you want to handle the notification when app is opened then follow the below code
Copy
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){ let userInfo = notification.request.content.userInfo GenuinSDK.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler) if let rootVC = window?.rootViewController as? UIViewController{ GenuinSDK.shared.handleNotifications(viewController: rootVC) } //mention design type for notification completionHandler([.list, .badge, .sound]) }
Note: To handle the notification from another controller call the GenuinSDK.shared.handleNotifications(viewController: YOUR_VIEW_CONTROLLER) function.