{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":"","apiSetting":null},"next":{"description":"","pages":[]},"title":"Customizing In-App Notifications","type":"basic","slug":"customizing-in-app-notifications","excerpt":"","body":"To make in-app notifications more engaging, you might want to implement your own user experience so that your in-app messaging can blend into the look and feel of your UI.\n\nTo do so, override the following callback methods, and return `false`, which ensures that Sailthru Mobile's interface isn't displayed.  At this point you can trigger your own in-app notification interface using the Message object.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//On iOS, using Objective-C\\n\\n- (BOOL)shouldPresentInAppNotificationForMessage:(STMMessage *)message {\\t\\n  // Do something with the message\\n  \\n  // Register an impression *if* you are displaying the notification yourself.\\n  [[STMMessageStream new] registerImpressionWithType:STMImpressionTypeInAppNotificationView forMessage:message];\\n  return NO;\\t\\n}\\n\\n//Be sure to assign your delegate to STMMessageStream\\n[[STMMessageStream new] setDelegate:self]\\n\",\n      \"language\": \"objectivec\",\n      \"name\": \"iOS (Objective-C)\"\n    },\n    {\n      \"code\": \"//On iOS, using Swift\\n\\nfunc shouldPresentInAppNotificationForMessage(message: STMMessage) -> Bool {\\n\\treturn false\\n}\\n\\n//Be sure to assign your delegate to STMMessageStream\\nSTMMessageStream().setDelegate(self)\",\n      \"language\": \"swift\",\n      \"name\": \"iOS (Swift)\"\n    },\n    {\n      \"code\": \"//On Android, using Java\\n\\nnew MessageStream().setOnInAppNotificationDisplayListener(new \\n\\tMessageStream.OnInAppNotificationDisplayListener() {\\n    :::at:::Override\\n    public boolean shouldPresentInAppNotification(Message message) {\\n      return false;\\n    }\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Android (Java)\"\n    },\n    {\n      \"code\": \"//On Android, using Kotlin\\n\\nMessageStream().setOnInAppNotificationDisplayListener(object : MessageStream.OnInAppNotificationDisplayListener {\\n\\toverride fun shouldPresentInAppNotification(message: Message?): Boolean {\\n\\t\\treturn false\\n\\t}\\n})\",\n      \"language\": \"kotlin\",\n      \"name\": \"Android (Kotlin)\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Not available in Unity and React Native\",\n  \"body\": \"Due to limitations of current plugin architecture in Unity and React Native, it is not currently possible to override the stock experience for in-app notifications. Rest assured, you can still deliver these notifications, but you won't be able to customize their UX. We hope to bring customization to these platforms in the near future.\"\n}\n[/block]\n## Registering an impression event\n\nIn order to support impression analytics in your custom in-app notification, you will need to ensure you register an impression event when it is shown.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//On iOS, using Objective-C\\n \\n[[STMMessageStream new] registerImpressionWithType:STMImpressionTypeInAppNotificationView forMessage:message];\",\n      \"language\": \"objectivec\",\n      \"name\": \"iOS (Objective-C)\"\n    },\n    {\n      \"code\": \"//On iOS, using Swift\\n   STMMessageStream().registerImpressionWithType(STMImpressionType.InAppNotificationView, forMessage: message)\\n\",\n      \"language\": \"swift\",\n      \"name\": \"iOS (Swift)\"\n    },\n    {\n      \"code\": \"//On Android, using Java\\n\\nnew MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message);\\n\",\n      \"language\": \"java\",\n      \"name\": \"Android (Java)\"\n    },\n    {\n      \"code\": \"//On Android, using Kotlin\\n\\nMessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message)\",\n      \"language\": \"kotlin\",\n      \"name\": \"Android (Kotlin)\"\n    }\n  ]\n}\n[/block]","updates":[],"order":6,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5e6156bf5e4a51006dcd814b","category":{"sync":{"isSync":false,"url":""},"pages":["5e6156bf5e4a51006dcd812a","5e6156bf5e4a51006dcd812c","5e6156bf5e4a51006dcd812d","5e6156bf5e4a51006dcd812e","55e682b7de6fef23009480dc","5e6156bf5e4a51006dcd812f","5e6156bf5e4a51006dcd8130","5e6156bf5e4a51006dcd8131","5e6156bf5e4a51006dcd8132","5e6156bf5e4a51006dcd8133","5e6156bf5e4a51006dcd8134","5b720760c44b7600034b79bc","5e6156bf5e4a51006dcd8135","5e6156bf5e4a51006dcd8148","5e6156bf5e4a51006dcd8149","5e6156bf5e4a51006dcd814a","5e6156bf5e4a51006dcd814b","5e6156bf5e4a51006dcd814c","5e6156bf5e4a51006dcd814f","5e6156bf5e4a51006dcd8150","5e6156bf5e4a51006dcd8152","561c6ca0be5fb20d00077754","5e6156bf5e4a51006dcd8157","5e6156bf5e4a51006dcd8158","5b720760c44b7600034b79e2","5e6156bf5e4a51006dcd8159","5e6156bf5e4a51006dcd815a","5e6156bf5e4a51006dcd815b","5e6156bf5e4a51006dcd815c","56cfa5386c5d7a13005eec0f","56e73d86555c030e00a52a73","56e7460c9000b120000ffe2e","56e8c19e99c6400e003820cf","56e8c53fc88bf80e00f8bed8","56f06ff4d386ce0e008e9b21"],"title":"Install in your app","slug":"install-in-your-app","order":1,"from_sync":false,"reference":false,"_id":"5e6156bf5e4a51006dcd8121","__v":35,"createdAt":"2015-09-02T04:30:13.305Z","project":"55e67aaa9cc7c62b00c4a1ea","version":"5e6156bf5e4a51006dcd818c"},"parentDoc":null,"project":"55e67aaa9cc7c62b00c4a1ea","__v":14,"user":"55d2bd8e2463351700f67dd7","createdAt":"2015-09-16T23:16:52.601Z","githubsync":"","version":{"version":"1.5","version_clean":"1.5.0","codename":"ST Rebrand","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5e6156bf5e4a51006dcd8120","5e6156bf5e4a51006dcd8121","5e6156bf5e4a51006dcd8122","5e6156bf5e4a51006dcd8123","5e6156bf5e4a51006dcd8124","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5e6156bf5e4a51006dcd8125","5e6156bf5e4a51006dcd8126","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2","5e69868cbd5dcb006b35867b","5e6986ca2c6652006791b6e8"],"_id":"5e6156bf5e4a51006dcd818c","project":"55e67aaa9cc7c62b00c4a1ea","__v":2,"forked_from":"5b720760c44b7600034b7a08","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z"}}

Customizing In-App Notifications


To make in-app notifications more engaging, you might want to implement your own user experience so that your in-app messaging can blend into the look and feel of your UI. To do so, override the following callback methods, and return `false`, which ensures that Sailthru Mobile's interface isn't displayed. At this point you can trigger your own in-app notification interface using the Message object. [block:code] { "codes": [ { "code": "//On iOS, using Objective-C\n\n- (BOOL)shouldPresentInAppNotificationForMessage:(STMMessage *)message {\t\n // Do something with the message\n \n // Register an impression *if* you are displaying the notification yourself.\n [[STMMessageStream new] registerImpressionWithType:STMImpressionTypeInAppNotificationView forMessage:message];\n return NO;\t\n}\n\n//Be sure to assign your delegate to STMMessageStream\n[[STMMessageStream new] setDelegate:self]\n", "language": "objectivec", "name": "iOS (Objective-C)" }, { "code": "//On iOS, using Swift\n\nfunc shouldPresentInAppNotificationForMessage(message: STMMessage) -> Bool {\n\treturn false\n}\n\n//Be sure to assign your delegate to STMMessageStream\nSTMMessageStream().setDelegate(self)", "language": "swift", "name": "iOS (Swift)" }, { "code": "//On Android, using Java\n\nnew MessageStream().setOnInAppNotificationDisplayListener(new \n\tMessageStream.OnInAppNotificationDisplayListener() {\n @Override\n public boolean shouldPresentInAppNotification(Message message) {\n return false;\n }\n});", "language": "java", "name": "Android (Java)" }, { "code": "//On Android, using Kotlin\n\nMessageStream().setOnInAppNotificationDisplayListener(object : MessageStream.OnInAppNotificationDisplayListener {\n\toverride fun shouldPresentInAppNotification(message: Message?): Boolean {\n\t\treturn false\n\t}\n})", "language": "kotlin", "name": "Android (Kotlin)" } ] } [/block] [block:callout] { "type": "warning", "title": "Not available in Unity and React Native", "body": "Due to limitations of current plugin architecture in Unity and React Native, it is not currently possible to override the stock experience for in-app notifications. Rest assured, you can still deliver these notifications, but you won't be able to customize their UX. We hope to bring customization to these platforms in the near future." } [/block] ## Registering an impression event In order to support impression analytics in your custom in-app notification, you will need to ensure you register an impression event when it is shown. [block:code] { "codes": [ { "code": "//On iOS, using Objective-C\n \n[[STMMessageStream new] registerImpressionWithType:STMImpressionTypeInAppNotificationView forMessage:message];", "language": "objectivec", "name": "iOS (Objective-C)" }, { "code": "//On iOS, using Swift\n STMMessageStream().registerImpressionWithType(STMImpressionType.InAppNotificationView, forMessage: message)\n", "language": "swift", "name": "iOS (Swift)" }, { "code": "//On Android, using Java\n\nnew MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message);\n", "language": "java", "name": "Android (Java)" }, { "code": "//On Android, using Kotlin\n\nMessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message)", "language": "kotlin", "name": "Android (Kotlin)" } ] } [/block]