-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ open class SearchBarContainerView: UIView { | |
fatalError() | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import UIKit | ||
|
||
public class OpenInSafariActivity: UIActivity { | ||
fileprivate var url: URL? | ||
|
||
public override var activityType: UIActivityType? { | ||
return UIActivityType(String(describing: classForCoder)) | ||
} | ||
|
||
public override var activityTitle: String? { | ||
let defaultTitle = Bundle(for: classForCoder).localizedString(forKey: "Open in Safari", value: "Open in Safari Default", table: "OpenInSafariActivity") | ||
let title = Bundle.main.localizedString(forKey: "Open in Safari", value: defaultTitle, table: nil) | ||
|
||
return title | ||
} | ||
|
||
public override var activityImage: UIImage? { | ||
return UIImage(named: "Safari", in: Bundle(for: classForCoder), compatibleWith: nil) | ||
} | ||
|
||
public override func canPerform(withActivityItems activityItems: [Any]) -> Bool { | ||
for item in activityItems { | ||
if let item = item as? URL { | ||
return UIApplication.shared.canOpenURL(item) | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
public override func prepare(withActivityItems activityItems: [Any]) { | ||
for item in activityItems { | ||
if let item = item as? URL { | ||
url = item | ||
break | ||
} | ||
} | ||
} | ||
|
||
public override func perform() { | ||
if let url = self.url { | ||
if #available(iOS 10.0, *) { | ||
UIApplication.shared.open(url, options: [:]) { completed in | ||
self.activityDidFinish(completed) | ||
} | ||
} else { | ||
let completed = UIApplication.shared.openURL(url) | ||
activityDidFinish(completed) | ||
} | ||
} else { | ||
activityDidFinish(false) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import UIKit | ||
|
||
public extension UILocalNotification { | ||
static let idKey = "idKey" | ||
static let fireDateKey = "fireDateKey" | ||
|
||
/// Schedules a local notification. | ||
/// | ||
/// - Parameters: | ||
/// - id: The id used to represent a local notification in your app. | ||
/// - date: The date when the notification will trigger | ||
/// - soundName: The name of the sound to be used when the notification is received. | ||
/// - message: The message that the app will use for your local notification. | ||
/// - actionTitle: The title of the action to be displayed by your notification, it's optional, though, since Apple provides a good default for this. | ||
public static func schedule(_ id: String, at date: Date, soundName: String? = nil, message: String, actionTitle: String? = nil) { | ||
let notification = UILocalNotification() | ||
notification.soundName = soundName | ||
|
||
notification.fireDate = date | ||
notification.timeZone = TimeZone.current | ||
notification.alertBody = message | ||
notification.alertAction = actionTitle | ||
notification.hasAction = actionTitle != nil | ||
|
||
var userInfo = [AnyHashable: Any]() | ||
userInfo[idKey] = id | ||
userInfo[fireDateKey] = date | ||
notification.userInfo = userInfo | ||
|
||
UIApplication.shared.scheduleLocalNotification(notification) | ||
} | ||
|
||
/// Finds a local notification for certain id. | ||
/// | ||
/// - Parameter id: The id used to store the notification. | ||
/// - Returns: A local notification that matches the provided id. | ||
public static func find(_ id: String) -> UILocalNotification? { | ||
let notifications = UIApplication.shared.scheduledLocalNotifications ?? [UILocalNotification]() | ||
let filteredNotifications = notifications.filter { notification in | ||
let filteredNotificationID = notification.userInfo?[idKey] as? String | ||
return filteredNotificationID == id | ||
} | ||
|
||
return filteredNotifications.first | ||
} | ||
|
||
/// Cancels a local notification. | ||
/// | ||
/// - Parameter id: The id used to store the notification. | ||
public static func cancel(_ id: String) { | ||
if let notification = self.find(id) { | ||
UIApplication.shared.cancelLocalNotification(notification) | ||
} | ||
} | ||
|
||
/// Cancels all the local notifications for the current app. | ||
public static func cancelAll() { | ||
let notifications = UIApplication.shared.scheduledLocalNotifications ?? [UILocalNotification]() | ||
notifications.forEach { notification in | ||
UIApplication.shared.cancelLocalNotification(notification) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters