I am using Sirikit to integrate with my payment domain app where I need to interact with the app. I read Apple documentation, they asked to use common frameworks.
Is it possible to use handoff? if yes then how?
How can I call the other viewController which is in parent app from sirikit?
I will really appreciate for any help. Thanks
Every user activity object needs a type and we need to define those types in the
info.plist of the application
For Eg.
let userActivity = NSUserActivity(activityType: "uaType")
userActivity.title = "uaTitle"
userActivity.userInfo = ["uaKey": "uaValue"]
You can now access this activity object in AppDelegate as follows
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
switch userActivity.activityType {
case "uaType":
//Write your logic to access uaKey & uaValue here
return true
default: return false
}
}
Check SiriKit Programming Guide,
To use handoff, You can create intent response object with NSUserActivity object. While creating NSUserActivity object assign userInfo property to appropriate object that you want,
let userActivity = NSUserActivity()
userActivity.userInfo = ["myKey": myAnyObject]
You will get this NSUserActivity object in parent application AppDelegate,
optional public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Swift.Void) -> Bool
Here you can get userInfo object which you can compare as per your requirement and call appropriate viewController.
Related
I've meet a strange issue when dropping the support for iOS 12. When handle the user activity from AppDelegate continue userActivity, Although we drop INStartAudioCallIntent and INStartVideoCallIntent for it is deprecated in iOS 13, we still receive the above 2 intents from native contact card. But actually we want to handle INStartCallIntent instead.
Anyone knows why this happens for my debug version is 14.6, thanks.
Adding Intent as an app extension to handle INStartCallIntentHandling made my AppDelegate receive INStartCallIntent!
It can be implemented like this:
File > New -> Target -> Intent
Add INStartCallIntent to Supported Intents
Implement the IntentHandler (In the intent extension) like this:
class IntentHandler: INExtension, INStartCallIntentHandling {
override func handler(for intent: INIntent) -> Any {
return self
}
func handle(intent: INStartCallIntent, completion: #escaping (INStartCallIntentResponse) -> Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartCallIntent.self))
let response = INStartCallIntentResponse(code: .continueInApp, userActivity: userActivity)
completion(response)
}
}
The INStartCallIntent will now be called in the AppDelegate:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let intent = userActivity.interaction?.intent {
if let intent = intent as? INStartCallIntent {
// The correct INStartCallIntent
}
}
}
Behold. I am trying to create an IOS app with swift 4.2, which, according to my client, has to sound an alarm, but it can only be stopped with a QR code. Therefore, what I will need will be a timer that works in the background, checking the time every second, because something else, the user could stop it, without the QR code. The only thing I've found for that is the Background Fetch, but can it work with 1 second checks every time?
Does anyone have a better idea?
Cheers
This is my source code for now
App delegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.setMinimumBackgroundFetchInterval(2.0)
}
//ini----------------------------background task
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
// fetch data from internet now
let time:TimerNow = TimerNow();
let hours = preferences.string(forKey: "hours");
let minutes = preferences.string(forKey: "minutes");
if((hours == time.getHours())&&(minutes == time.getMinutes())){
lem.onPlayCommand();
}
completionHandler(.newData)
}
//fin ---------------------------background task
I think you should use local notifications instead. It will be fired when you want to notify about the elapsed time. You could cancel it whenever and with any condition you want.
IMO timer and background fetching is not suitable for that situation.
I am trying to implement Apple CallKit in my VoIP application. I am using Xcode 9.2, Swift 4.0.3, iOS 10.3. Problem is I do not know how exactly to do this. I have tried to search for tutorial in Web, but I failed to find tutorial based on real system. They all using fake systems, only simulate calls! I have a class which rules with someone third person library which is responsible for the calls. So, if I have incoming call happens, some event goes through observer. Like this:
NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: Notifications.Name.transMessage.rawValue), object: nil, queue: nil) { notification in
self.handleLibtransEvents()
}
where self.handleLibtransEvents is private function calling calls.
Plus, I have installed working PUSH Notification system in AppDelegate.swift. Like this:
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("NOTIFICATION ERROR: \(error)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let pushToken = deviceToken.reduce("", {$0 + String(format: "%02X", $1)}).lowercased()
print("pushToken: \(pushToken)")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
if UIApplication.shared.applicationState != UIApplicationState.active {
// PUSH: Incoming call event!
}
}
So there are two places, I can catch incoming call but I have not any idea how to catch real call through Apple CallKit. I will be thankful for any help, advice, call example. Thanks!
P. S. I have installed all settings correctly.
CallKit is basically a framework to show up a Call UI when ever you receive a voip call or make a new call, So it will do nothing if you pass it a number n assume it will make call, Keep it in mind its only to show a UI for receive call & make call.
To make calls n receive calls you will need 3rd party services like Sinch and many other.
I have an app that uses Corebluetooth and uses its Background services. I need also long-term CoreBluetooth action so I need to implement State preservation and restoration. I followed Apple document the link at the below https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html also watched WWDC 2013 presentation video link below,
https://developer.apple.com/videos/play/wwdc2013/703/
First of all, the sources are in Objective C and I am not familiar with that, I tried to convert them in swift3.
Then, I defined CBCentralManager with restoration identifier shown below,
self.myCentralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: "myCentralManager"])
Then, added delegate method something in the below,
func centralManager( willRestoreState dict: [String : AnyObject]) {
let peripherals: [CBPeripheral] = dict[CBCentralManagerRestoredStatePeripheralsKey] as! [CBPeripheral]
for peripheral in peripherals {
self.peripherals.append(peripheral)
peripheral.delegate = self
}
}
Finally did didFinishLaunchingWithOptions method in AppDelegate,
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
if let peripheralManagerIdentifiers: [String] = launchOptions?[UIApplicationLaunchOptionsKey.bluetoothCentrals] as? [String]{
for identifier in peripheralManagerIdentifiers{
if (identifier == "myCentralManager"){
}
}
}
return true
}
When I debug, didFinishLaunchingWithOptions method called, the parameter launchOptions?[UIApplicationLaunchOptionsKey.bluetoothCentrals] is nil I think because of first time I created the app, then got error when defining CBCentralManager with restoration identifier the error is "reason: ' has provided a restore identifier but the delegate doesn't implement the centralManager:willRestoreState: method'"
I'm totally confused, thank you for any help,
Best regards,
I am trying to use handoff to make an iphone app do something when the user does something in the watchkit app. In the watch app (in InterfaceController.swift), I have this code that gets run when the user taps a button:
self.updateUserActivity("com.test", userInfo: ["one":"two"], webpageURL: nil)
Then in the AppDelegate.swift file of the phone app, I have this code:
func application(application: UIApplication!,
continueUserActivity userActivity: NSUserActivity!,
restorationHandler: (([AnyObject]!) -> Void)!)
-> Bool {
let userInfo = userActivity.userInfo
println("testing: \(userInfo)")
return true
}
In theory this should print the userInfo (in this case ["one":"two"]) to the console, but I think I'm missing something here.