Skip to content

Instantly share code, notes, and snippets.

View WildStudio's full-sized avatar
Get shit done!

Christian Aranda WildStudio

Get shit done!
  • WildStudio
  • Barcelona
View GitHub Profile
fileprivate var isLoggedIn:Bool {
get {
return (accessToken(forUserDefaults: storage) != nil)
}
}
func handleStartup() {
if isCurrentUserActivity { // if the app is opened by URL it must wait the deeplink compltetion and deeplink data stored.
if isDeeplinkStored {
deeplinkAction()
}
} else if isDeeplinkStored {
deeplinkAction()
} else if isLoggedIn {
loggedInAction()
} else {
import UIKit
let userActivity = NSUserActivity(activityType: "com.sirishorutsapp.wamf")
userActivity.isEligibleForSearch = true
userActivity.isElegibleForPrediction = true
userActivity.title = "Activity"
userActivity.userInfo = ["key": "Value"]
userActivity.suggestedInvocationPhrase = "Play Star Wars Movie"
let attributes = CSSearchableItemsAttributeSet(intemContentType: kUTTypeItem as String)
// Once resolution is completed, perform validation on the intent and provide confirmation (optional).
func confirm(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Verify user is authenticated and your app is ready to send a message.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .ready, userActivity: userActivity)
completion(response)
}
@WildStudio
WildStudio / gist:fadf3cef55216ef04b55efb7ab637905
Last active September 18, 2018 10:32
Handle intents on continueuserActivity:NSUserActivity
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let type = userActivity.activityType
if let name = userActivity.userInfo?["name"] as? String where type == NSStringFromClass(INSendMessageIntent.self) {
let alert = UIAlertController(title: "User Activity", message: "Continue Activity: \(name)", preferredStyle: .alert)
window?.rootViewController?.present(alert, animated: true, completion: nil)
}
return true
}
@WildStudio
WildStudio / Vision + ML
Last active December 12, 2018 11:32
Image Vision Request
let handler = VNImageRequestHandler(ciImage: ciImage, orientation: orientation)
do {
try handler.perform([self.classificationRequest])
} catch {
print("Failed to perform classification.\n\(error.localizedDescription)")
}
@WildStudio
WildStudio / VISION+ML
Created December 12, 2018 11:25
Handle classification request
lazy var classificationRequest: VNCoreMLRequest = {
// Load the ML model through its generated class and create a Vision request for it.
do {
let model = try VNCoreMLModel(for: MobileNet().model)
return VNCoreMLRequest(model: model, completionHandler: self.handleClassification)
} catch {
fatalError("can't load Vision ML model: \(error)")
}
}()