Skip to content

Instantly share code, notes, and snippets.

View jgsamudio's full-sized avatar

Jonathan Samudio jgsamudio

View GitHub Profile
@jgsamudio
jgsamudio / LocationNotificationInfo.swift
Created May 13, 2019 13:29
LocationNotificationInfo object for the LocationNotificationScheduler
import CoreLocation
struct LocationNotificationInfo {
// Identifiers
let notificationId: String
let locationId: String
// Location
let radius: Double
@jgsamudio
jgsamudio / LocationNotificationScheduler.swift
Created May 10, 2019 01:06
Schedules a location triggered notification
//
// LocationNotificationScheduler.swift
// LocationNotifier
//
// Created by Jonathan Samudio on 5/8/19.
// Copyright © 2019 Jonathan Samudio. All rights reserved.
//
import CoreLocation
import UserNotifications
// Setup request and add request to the Notification Center.
let request = UNNotificationRequest(identifier: "destination_notif_id",
content: notification,
trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
if error == nil {
print("Successfully Added")
print(request)
} else {
let notification = UNMutableNotificationContent()
notification.title = "Welcome!"
notification.body = "You are in a custom circular region"
notification.sound = UNNotificationSound.default
notification.userInfo = ["destinationId": 1234]
let center = CLLocationCoordinate2D(latitude: 40.700212, longitude: -73.987238)
let region = CLCircularRegion(center: center, radius: 2000.0, identifier: "unique_location_id")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let notificationCenter = UNUserNotificationCenter.current()
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
notificationCenter.requestAuthorization(options: options, completionHandler: { (granted, error) in
// Check if user granted location permissions here.
})
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location description</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Location description</string>
<key>NSLocationUsageDescription</key>
<string>Location description</string>
@jgsamudio
jgsamudio / GeoLocationPush.swift
Last active November 9, 2019 07:27
Location based push notification
import CoreLocation
import UserNotifications
final class GeoLocationNotificationProvider: NSObject {
// MARK: - Private Properties
// Made By We's coordinates center
private let officeCenterLocation = CLLocationCoordinate2D(latitude: 40.739357, longitude: -73.989711)
private let locationManager = CLLocationManager()
//
// CredentialValidator.swift
// UnitTesting
//
// Created by Jonathan Samudio on 1/21/19.
// Copyright © 2019 Jonathan Samudio. All rights reserved.
//
import Foundation
//
// SampleEdgeCase.swift
// UnitTesting
//
// Created by Jonathan Samudio on 1/21/19.
// Copyright © 2019 Jonathan Samudio. All rights reserved.
//
import Foundation