{"id":20340199,"url":"https://github.com/webengage/xamarin-ios-sample","last_synced_at":"2026-05-09T08:08:48.578Z","repository":{"id":82265263,"uuid":"150120421","full_name":"WebEngage/xamarin-ios-sample","owner":"WebEngage","description":"Sample Xamarin iOS project.","archived":false,"fork":false,"pushed_at":"2020-01-17T10:26:20.000Z","size":12237,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-14T18:10:14.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebEngage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-24T14:58:43.000Z","updated_at":"2020-01-17T10:26:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a882f4e-0273-4cc8-9d98-998a205e07db","html_url":"https://github.com/WebEngage/xamarin-ios-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-ios-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-ios-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-ios-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-ios-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebEngage","download_url":"https://codeload.github.com/WebEngage/xamarin-ios-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241867649,"owners_count":20033815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T21:20:12.639Z","updated_at":"2026-05-09T08:08:43.533Z","avatar_url":"https://github.com/WebEngage.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebEngage Xamarin iOS Sample\n\nThis is Xamarin.iOS sample application to demonstrate usage of Xamarin binding library of WebEngage iOS SDK.\n\n\n## Installation\n\n1. Download [WebEngage Xamarin iOS Library (v0.3.0.0)](https://s3-us-west-2.amazonaws.com/webengage-sdk/xamarin/ios/base/0.3.0.0/WebEngageXamariniOS.dll).\n\n2. To consume this downloaded .DLL in your Xamarin.iOS app, you must first add a reference to your Xamarin.iOS project by right-clicking on the References node of your project and select Add Reference.\n\n\n## Initialization\n\n\n1. Add the following entries in info.plist file of your application.\n\n```\n\tWEGLicenseCode: YOUR-WEBENGAGE-LICENSE-CODE\n\tWEGLogLevel: VERBOSE\n```\n\n\n2. Initialize WebEngage SDK from FinishedLaunching callback of your AppDelegate class as shown below.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    [Register(\"AppDelegate\")]\n    public class AppDelegate : UIApplicationDelegate\n    {\n    \t...\n    \tpublic override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)\n        {\n            ...\n            WebEngage.SharedInstance().Application(application, launchOptions);\n            return true;\n        }\n        ...\n    }\n}\n```\n\n\n## Tracking Users\n\n1. Login and logout users as shown in below example.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    ...\n    public partial class YourViewController : UIViewController\n    {\n    \t...\n    \t// Login\n    \tWebEngage.SharedInstance().User.Login(\"user-id\");\n\n        // Logout\n        WebEngage.SharedInstance().User.Logout();\n    \t...\n    }\n    ...\n}\n```\n\n2. Set system user attributes as shown below.\n\n```csharp\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    ...\n    public partial class YourViewController : UIViewController\n    {\n        ...\n        // First name\n        WebEngage.SharedInstance().User.SetFirstName(\"John\");\n\n        // Last name\n        WebEngage.SharedInstance().User.SetLastName(\"Doe\");\n\n        // Email\n        WebEngage.SharedInstance().User.SetEmail(\"john.doe@gmail.com\");\n\n        // Hashed email\n        WebEngage.SharedInstance().User.SetHashedEmail(\"144e0424883546e07dcd727057fd3b62\");\n\n        // Phone    \n        WebEngage.SharedInstance().User.SetPhone(\"john.doe@gmail.com\");\n\n        // Hashed phone    \n        WebEngage.SharedInstance().User.SetHashedPhone(\"e0ec043b3f9e198ec09041687e4d4e8d\");\n\n        // Gender    \n        WebEngage.SharedInstance().User.SetGender(\"male\");\n\n        // Birthdate\n        WebEngage.SharedInstance().User.SetBirthDateString(\"1994-04-29\");\n\n        // Company    \n        WebEngage.SharedInstance().User.SetCompany(\"Alphabet Inc.\");\n\n        // Opt-in    \n        WebEngage.SharedInstance().User.SetOptInStatusForChannel(WEGEngagementChannel.Push, true);\n        WebEngage.SharedInstance().User.SetOptInStatusForChannel(WEGEngagementChannel.InApp, true);\n        WebEngage.SharedInstance().User.SetOptInStatusForChannel(WEGEngagementChannel.Sms, true);\n        WebEngage.SharedInstance().User.SetOptInStatusForChannel(WEGEngagementChannel.Email, true);\n\n        // Location    \n        NSNumber latitude = 72.5;\n        NSNumber longitude = 120.5;\n        WebEngage.SharedInstance().User.SetUserLocation(latitude, longitude);\n        ...\n    }\n    ...\n}\n```\n\n3. Set custom user attributes as shown below.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    ...\n    public partial class YourViewController : UIViewController\n    {\n        ...\n        // String custom user attribute\n        WebEngage.SharedInstance().User.SetAttribute(\"Twitter username\", \"johndoe86@orig\");\n\n        // Number custom user attribute\n        WebEngage.SharedInstance().User.SetAttribute(\"age\", 24);\n\n        // Date custom user attribute\n        NSDateComponents dateComponents = new NSDateComponents\n        {\n            Day = 29,\n            Month = 4,\n            Year = 2001\n        };\n        NSCalendar calendar = NSCalendar.CurrentCalendar;\n        NSDate date = calendar.DateFromComponents(dateComponents);\n        WebEngage.SharedInstance().User.SetAttribute(\"Last order date\", date);\n\n        // Complex custom user attributes\n        NSDictionary\u003cNSString, NSObject\u003e dict = new NSDictionary\u003cNSString, NSObject\u003e();\n        dict.SetValueForKey(new NSString(\"Z-62\"), new NSString(\"Flat\"));\n        dict.SetValueForKey(new NSString(\"Pennant Court\"), new NSString(\"Building\"));\n        dict.SetValueForKey(new NSString(\"Penn Road\"), new NSString(\"Locality\"));\n        dict.SetValueForKey(new NSString(\"West Midlands\"), new NSString(\"State\"));\n        dict.SetValueForKey(new NSString(\"WV30DT\"), new NSString(\"PIN\"));\n        WebEngage.SharedInstance().User.SetAttribute(\"Address\", dict);\n        ...\n    }\n    ...\n}\n```\n\n**Note:** WebEngage Xamarin.iOS SDK only supports the following data-types: string, NSString, NSNumber, Boolean, NSDate, NSMutableArray and NSDictionary.\n\n4. Delete custom user attributes as shown below.\n\n```csharp\nusing WebEngageXamariniOS;\n\n    ...\n    WebEngage.SharedInstance().User.DeleteAttribute(\"age\");\n```\n\n\n## Tracking Events\n\nTrack custom events as shown below.\n\n```csharp\nusing WebEngageXamariniOS;\n\n    ...\n    // Simple event\n    WebEngage.SharedInstance().Analytics.TrackEventWithName(\"Product Viewed\");\n\n    // Event with attributes\n    var addedToCartAttributes = new NSDictionary(\"Product ID\", 1337, \n                                                 \"Price\", 39.80, \n                                                 \"Quantity\", 1, \n                                                 \"Product\", \"Givenchy Pour Homme Cologne\",\n                                                 \"Category\", \"Fragrance\",\n                                                 \"Currency\", \"USD\",\n                                                 \"Is Premium\", true\n                                                );\n    WebEngage.SharedInstance().Analytics.TrackEventWithName(\"Added to Cart\", addedToCartAttributes);\n\n    // Complex event\n    var detailsProduct1 = new NSDictionary(\"Size\", \"L\");\n\n    var product1 = new NSDictionary(\"SKU Code\", \"UHUH799\",\n                                    \"Product Name\", \"Armani Jeans\",\n                                    \"Price\", 300.49,\n                                    \"Details\", detailsProduct1\n                                   );\n    var detailsProduct2 = new NSDictionary(\"Size\", \"L\");\n\n    var product2 = new NSDictionary(\"SKU Code\", \"UHUH799\",\n                                    \"Product Name\", \"Armani Jeans\",\n                                    \"Price\", 300.49,\n                                    \"Details\", detailsProduct1\n                                   );\n    var deliveryAddress = new NSDictionary(\"City\", \"San Francisco\", \n                                       \"ZIP\", \"94121\"\n                                      );\n    var products = new NSMutableArray\u003cNSDictionary\u003e(product1, product2);\n\n    var orderPlacedAttributes = new NSDictionary(\"Products\", products,\n                                                 \"Delivery Address\", deliveryAddress,\n                                                 \"Coupons Applied\", new NSMutableArray\u003cNSString\u003e(new NSString(\"BOGO17\"), new NSString(\"BGH025\"))\n                                                );\n    WebEngage.SharedInstance().Analytics.TrackEventWithName(\"Order Placed\", orderPlacedAttributes);\n```\n\n**Note:** WebEngage Xamarin.iOS SDK only supports the following data-types: string, NSString, NSNumber, Boolean, NSDate, NSMutableArray and NSDictionary.\n\n\n## Push Notifications\n\n1. In order to receive push notifications from WebEngage, Log in to your WebEngage dashboard and navigate to Integrations \u003e Channels \u003e Push, under iOS section upload your push certificate and enter your push password.\n\n2. Now in your Xamarin.iOS app's Entitlements.plist check Enable Push Notifications.\n\n3. Add remote-notifications as type string under App Background Modes in your app's info.plist.\n\n4. Set autoregister to true while initialising WebEngage SDK as shown below.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    ...\n    [Register(\"AppDelegate\")]\n    public class AppDelegate : UIApplicationDelegate\n    {\n        ...\n        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)\n        {\n            ...\n            WebEngage.SharedInstance().Application(application, launchOptions, true);\n            return true;\n        }\n        ...\n    }\n    ...\n}\n```\n\nFor detailed instructions see our [documentation for integrating Push Notifications in iOS](https://docs.webengage.com/docs/ios-push-messaging).\n\n\n### Rich Push Notifications\n\n1. For Banner Push Notifications\n\n    1. Add a new project named `NotificationService` with Notification Service Extension as target in your main app.\n\n    2. Download [WebEngage Banner Push Notification Extension SDK](https://s3-us-west-2.amazonaws.com/webengage-sdk/xamarin/ios/banner-push/0.1.0.0/WebEngageBannerPushXamariniOS.dll)\n\n    3. Add WebEngageBannerPushXamariniOS.dll to References in your NotificationService project.\n\n    4. Replace `NotificationService.cs` with the below code.\n\n        ```csharp\n        using Foundation;\n        using WebEngageBannerPushXamariniOS;\n\n        namespace NotificationService\n        {\n            [Register(\"NotificationService\")]\n            public class NotificationService : WEXPushNotificationService\n            {\n\n            }\n        }\n        ```\n\n2. For Rating and Carousel Push Notifications\n\n    1. Add a new project named `NotificationViewController` with Notification Content Extension as target in your main app.\n\n    2. Download [WebEngage Notification App Extension SDK](https://s3-us-west-2.amazonaws.com/webengage-sdk/xamarin/ios/app-extension/0.1.0.0/WebEngageAppExXamariniOS.dll)\n\n    3. Add WebEngageAppExXamariniOS.dll to References in your NotificationViewController project.\n\n    4. Open the `Info.plist` file for NotificationViewController. Expand NSExetnsion \u003e NSExtensionAttributes. Look for UNNotificationExtensionCategory under NSExtensionAttributes. Add it if it is not present and set the type as Array. In its items, add the following values:\n\n        a. `WEG_CAROUSEL_V1` for Carousel Push Notifications\n\n        b. `WEG_RATING_V1` for Rating Push Notifications\n\n    5. Replace `NotificationViewController.cs` with the below code.\n\n        ```csharp\n        using System;\n        using Foundation;\n        using UserNotifications;\n        using WebEngageAppExXamariniOS;\n\n        namespace NotificationViewController\n        {\n            public partial class NotificationViewController : WEXRichPushNotificationViewController\n            {\n                protected NotificationViewController(IntPtr handle) : base(handle)\n                {\n                    \n                }\n\n                public override void ViewDidLoad()\n                {\n                    base.ViewDidLoad();\n                }\n\n                [Export(\"didReceiveNotification:\")]\n                public override void DidReceiveNotification(UNNotification notification)\n                {\n                    base.DidReceiveNotification(notification);\n                }\n            }\n        }\n        ```\n\n3. Set App Groups as group.[app-bundle-id].WEGNotificationGroup in `Entitlements.plist` of all three projects (your Xamarin.iOS app, NotificationService and NotificationViewController).\n\nFor detailed explanation see our [documentation for integrating Rich Push Notification in iOS](https://docs.webengage.com/docs/ios-push-messaging#section-5-rich-push-notifications-optional).\n\n\n### Push Notification Callbacks\n\nIn order to receive push notification callbacks, implement IWEGAppDelegate in your AppDelegate class as shown below.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    [Register(\"AppDelegate\")]\n    public class AppDelegate : UIApplicationDelegate, IWEGAppDelegate\n    {\n        ...\n        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)\n        {\n            ...\n            WebEngage.SharedInstance().Application(application, launchOptions, true);\n            return true;\n        }\n\n        // Push notification callbacks\n        [Export(\"application:didReceiveRemoteNotification:\")]\n        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)\n        {\n            ...\n        }\n\n        [Export(\"application:didReceiveRemoteNotification:fetchCompletionHandler:\")]\n        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action\u003cUIBackgroundFetchResult\u003e completionHandler)\n        {\n            ...\n        }\n\n        [Export(\"WEGHandleDeeplink:userData:\")]\n        public void WEGHandleDeeplink(string deeplink, NSDictionary data)\n        {\n            ...\n        }\n\n        // Anonymous ID callback\n        [Export(\"didReceiveAnonymousID:forReason:\")]\n        public void DidReceiveAnonymousID(string anonymousID, WEGReason reason)\n        {\n            ...\n        }\n\n        ...\n    }\n}\n```\n\n\n## In-app Notifications\n\nNo additional steps are required to receive in-app notifications.\n\n### Tracking Screens\n\nScreens can be tracked to set rules for showing in-app notifications. For example, you can create a rule in WebEngage dashboard to show in-app notification on a particular screen.\n\n```csharp\nusing WebEngageXamariniOS;\n\n    ...\n    // Simple screen\n    WebEngage.SharedInstance().Analytics.NavigatingToScreenWithName(\"Purchase Screen\");\n\n    // Setting screen data\n    var screenData = new NSDictionary(\"productId\", \"~hs7674\",\n                                     \"price\", 1200);\n    WebEngage.SharedInstance().Analytics.UpdateCurrentScreenData(screenData);\n```\n\n### In-app Notification Callbacks\n\n1. Create WebEngage in-app notification callback delegate class as shown below.\n\n```csharp\nusing System;\nusing Foundation;\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    public class InAppNotificationDelegate : WEGInAppNotificationProtocol\n    {\n        public override NSMutableDictionary NotificationPrepared(NSMutableDictionary inAppNotificationData, bool stopRendering)\n        {\n            ...\n            return inAppNotificationData;\n        }\n\n        public override void NotificationShown(NSMutableDictionary inAppNotificationData)\n        {\n            ...\n        }\n\n        public override void Notification(NSMutableDictionary inAppNotificationData, string actionId)\n        {\n            ...\n        }\n\n        public override void NotificationDismissed(NSMutableDictionary inAppNotificationData)\n        {\n            ...\n        }\n    }\n}\n```\n\n2. Register the in-app notification callback delegate in your AppDelegate while initializing WebEngage SDK as shown below.\n\n```csharp\n...\nusing WebEngageXamariniOS;\n\nnamespace YourNamespace\n{\n    ...\n    [Register(\"AppDelegate\")]\n    public class AppDelegate : UIApplicationDelegate\n    {\n        ...\n\n        private static InAppNotificationDelegate inAppNotificationDelegate;\n\n        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)\n        {\n            ...\n\n            inAppNotificationDelegate = new InAppNotificationDelegate();\n\n            WebEngage.SharedInstance().Application(application, launchOptions, inAppNotificationDelegate, true);\n\n            return true;\n        }\n        ...\n    }\n    ...\n}\n```\n\n\n## Troubleshooting\n\n### Banner push notification Images not shown in iOS 11 Debug mode\n\nDo not panic, this is a bug in iOS itself. However, rich push notifications would work fine in iOS 11 Release mode.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebengage%2Fxamarin-ios-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebengage%2Fxamarin-ios-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebengage%2Fxamarin-ios-sample/lists"}