Skip to content

Instantly share code, notes, and snippets.

@youvalv
youvalv / embed gist in iframe.md
Last active March 3, 2021 19:24 — forked from Albert-W/embed gist.md
embed gist in iframe

Embed gist in an iframe

Used to embed gist to an asynchronously-loaded web pages.

<iframe 
    width="100%"
    height="350"    
    src="data:text/html;charset=utf-8,
 
// value: some information about the action - type of subscription plan, type of segment, A/B test ID. etc. Can be nil
// instanceId: the moment ID used to trigger the desired action. Can be nil
// action: definition of the action. Can be one of: http://docs.theneura.com/ios/Constants/NEngagementFeatureAction.html
[NeuraSDK.shared tagEngagementAttempt:"featureName" value:"ABTestId" instanceId:nil error:&err];
[NeuraSDK.shared tagEngagementFeature:"featureName" action:NEngagementFeatureActionSuccess value:valueField.text instanceId:instanceIdField.text error:&err];
// When error validation is not needed, the error parameter can be nil
@youvalv
youvalv / DisplayingNotification.swift
Last active April 5, 2017 14:37
Displaying Notification
private func setupNotificationsSettings(alertTitle: String, alertBody: String, identifier: String, fireDate: Date, repeatInterval: NSCalendar.Unit) {
if #available(iOS 10.0, *) {
let specificDate = fireDate
//convert dateComponents() to Date()
let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second, .timeZone], from: specificDate)
var trigger: UNNotificationTrigger
if (repeatInterval.rawValue > 0) {
@youvalv
youvalv / NewCaegory.swift
Last active April 5, 2017 14:35
New iOS notifications category
@available(iOS 10.0, *)
private func getNewCategoryByIdentifier(identifier: String) -> UNNotificationCategory {
let tookAction = UNNotificationAction(identifier: kTookActionIdentifier, title: NSLocalizedString("Took", comment: "Took"), options: [])
let laterAction = UNNotificationAction(identifier: kLaterActionIdentifier, title: NSLocalizedString("Later", comment: "Took"), options: [])
return UNNotificationCategory(identifier: identifier, actions: [tookAction, laterAction], intentIdentifiers: [], options: [])
}
// For comparison, here is the old category usage
private func getCategoryByIdentifier(identifier: String) -> UIUserNotificationCategory {
@youvalv
youvalv / RegisterForNotification.swift
Last active April 5, 2017 14:25
Register for remote notifications
private func registerForRemoteNotifications () {
if #available(iOS 10.0, *) {
let userNotificationType: UNAuthorizationOptions = [UNAuthorizationOptions.alert, UNAuthorizationOptions.badge, UNAuthorizationOptions.sound]
UNUserNotificationCenter.current().setNotificationCategories([self.getNewCategoryByIdentifier(identifier: kMorningEventIdentifier),
self.getNewCategoryByIdentifier(identifier: kEveningEventIdentifier),
self.getNewCategoryByIdentifier(identifier: kTakePillboxEventIdentifier)])
UNUserNotificationCenter.current().requestAuthorization(options: userNotificationType, completionHandler: { (success:Bool, error:Error?) in
})