Siri shortcuts work on iPhone, but not on HomePod - ios

I’m working on app that uses Siri Shortcuts, and I’ve met one strange issue:
If I run a shortcut on iPhone, it works well. If I do the same with HomePod, connected to the same iPhone, I get “There is a problem with your app” from Siri. My shortcuts are created within the app.
if #available(iOS 12.0, *) {
let activity = NSUserActivity(activityType: command.rawValue)
activity.title = selectTitle(activityType: command)
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(command.rawValue)
responder.userActivity = activity
activity.becomeCurrent()
}
Any ideas how to make them work via HomePod?
Thanks in advance!

Related

presentCodeRedemptionSheet() is not working

I am creating offer codes with auto-renewable In-app purchases in swift. But when i use presentCodeRedemptionSheet(), it does not show any redemption page to redeem offer code. I am using below code, but nothing is happening on tapping the button.
let paymentQueue = SKPaymentQueue.default()
if #available(iOS 14.0, *) {
DispatchQueue.main.async {
paymentQueue.presentCodeRedemptionSheet()
}
}
Are you trying on the simulator?
This command only works on a real device not in the simulator.

MFMailComposeViewController behaves differently in iOS 13 simulator and device

I'm trying to display MFMailComposeViewController in an app.
if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = .white
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["support#gmail.com"])
mailComposeViewController.setSubject("Feedback")
present(mailComposeViewController, animated: true)
} else {
print("This device is not configured to send email. Please set up an email account.")
}
In iOS 12, it shows up without an issue. In both simulator and device.
But when I run the same project on a device running iOS 13, it looks like this.
The navigation bar color is gone. Also the send button is also invisible.
So I added mailComposeViewController.navigationBar.backgroundColor = .mv_primary but it still doesn't show on the device. Strangely the background color shows in the simulator.
However there's a strange behavior. The MFMailComposeViewController immediately dismisses by itself when I run it in the simulator.
The following error also shows up in the Xcode console.
[Common] [FBSSystemService][0x5f27] Error handling open request for
com.apple.MailCompositionService: {
userInfo = {
FBSOpenApplicationRequestID = 0x5f27;
}
underlyingError = ; } 2019-11-01
14:40:05.214158+0530 MailCompose[11289:262267] [Assert] Connection
request invalidated without resuming our _serviceSessionConnection.
This is an error. 2019-11-01 14:40:05.216901+0530
MailCompose[11289:262054] [General] #CompositionServices
_serviceViewControllerReady: NSError Domain=_UIViewServiceInterfaceErrorDomain Code=0
I guess the weird dismiss error is a Xcode bug. But how do I fix the background color and the send button not showing up in the device?
This is how I set all the navigationbar related styles.
UINavigationBar.appearance().barTintColor = .mv_primary
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
Demo project
Add this line of code before present it. It will work normal. This a change in iOS 13
mailController.modalPresentationStyle = .fullScreen
The reason why the Mail composer dismisses immediately is because you can't actually send an email from the simulator. The implementation is different from iOS itself.
What I guess is happening here is that while the simulator implementation uses just some normal UI elements, the MFMailComposeViewController on native iOS is actually hosted like UIDocumentPickerViewController or UIActivityViewController. This means screenshots and trying to traverse the view tree is impossible, because the view is not an actual part of your application. They do that because these controllers contain user private information. Hosted view controller do NOT allow for customization, and do not comply with your global UINavigationBar.appearance(). This would explain why it does show up in the simulator and not on your native device.
This is new UI Style from iOS 13. You can disable it in Storyboard or set manual.
Presenting modal in iOS 13 fullscreen

Apple Watch Notification Actions not working when iPhone companion app is terminated watch OS 5.3.2

I am working on iOS app which is supported watch as well
below is my concerns.
watch os - 5.3.2 and iOS 13.1
I am facing problem with notification actions in watch app. when iPhone app is terminated and if I get a notification in watch , if I tap on action nothing happens.
I am relaying on push notification and for user notification actions I am registering for user notification.
as below
// this I will call in iPhone app code in did finishlaunching with options.
func registerForPushNotifications(withUserInfo userInfo: [AnyHashable: Any]?) {
if #available(iOS 10.0, *) {
self.requestAuthorization(withUserInfo: userInfo)
} else {
registerUserNotificationSettings(withUserInfo: userInfo)
UIApplication.shared.registerForRemoteNotifications()
}
}
func registerUserNotificationSettings() {
let approveAction = UIMutableUserNotificationAction()
approveAction.title = NSLocalizedString("Approve", comment: "Notification approve button title")
approveAction.identifier = "approve"
approveAction.isDestructive = false
approveAction.activationMode = .background
approveAction.isAuthenticationRequired = true
let denyAction = UIMutableUserNotificationAction()
denyAction.title = NSLocalizedString("Deny", comment: "Notification deny button title")
denyAction.identifier = "deny"
denyAction.isDestructive = true
denyAction.activationMode = .background
denyAction.isAuthenticationRequired = true
let signInCategory = UIMutableUserNotificationCategory()
signInCategory.setActions([approveAction, denyAction], for: .default)
signInCategory.identifier = "pushotp"
let categories = NSSet(object: signInCategory) as? Set<UIUserNotificationCategory>
let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: categories)
DispatchQueue.main.async(execute: {
UIApplication.shared.registerUserNotificationSettings(settings)
})
}
Scenarios
When iPhone app is in background and iPhone is locked and watch
is in background. If I push a push notification from server , watch
displays notification banner with two actions, if I tap any one
action , its working fine.
when iPhone app is killed and iPhone locked immmediatly If I send
pushnotification , watch displays notification banner with two
actions, if I tap any one actions its working fine.
When iPhone app is killed and iPhone locked, kept both watch and
iPhone idle for a hour so. then I will activate the watch and push
the notification from server, now watch displays banner with two
actions, now if I tap on the actions it is not working.
It would be great if you guys tell me what is the correct thing I have to do.
To ensure that the actions are taken in the 3rd use case, please ensure that Notification Payload should have contentAvailable property to YES. So that the application will launch in background.
And it will update the notification user actions accordingly.

iOS 13.1 doesn't receive silent CKQuerySubscription notifications

My app uses CloudKit Query subscriptions and notifications as part of a CloudKit-based synchronization solution. This works perfectly with iOS 12, macOS 10.14 and even macOS 10.15 beta, but NOT with iOS 13.0, iOS 13.1, iPadOS 13.1 and tvOS 13.0.
Removing and recreating the subscriptions doesn't solve this.
Is this a known problem?
According to the documentation, nothing has changed with CloudKit subscriptions. Or did I miss something?
To receive silent CKQuerySubscription notifications in iOS 13.x and tvOS 13.x, the soundName and alertBody parameters of the NotificationInfo of your CKQuerySubscription must not be set.
In the past we have learned to use an empty string for said parameters, to make the whole CloudKit subscription thing working, but that's now history. Apparently Apple has fixed an old bug, causing problems with apps that used this 'workaround'.
I have tested this on iOS 12.4.2, iOS 13.1.2, tvOS 13.0, macOS 10.14.6 and macOS 10.15 GM.
let info = CKSubscription.NotificationInfo()
info.shouldSendContentAvailable = true
// info.soundName = "" // Don't set this property
// info.alertBody = "" // And also leave this this property alone
let subscription = CKQuerySubscription(recordType: "yourRecordType", predicate: NSPredicate(value: true), subscriptionID: "yourSubscription", options: [CKQuerySubscription.Options.firesOnRecordUpdate, CKQuerySubscription.Options.firesOnRecordDeletion])
subscription.notificationInfo = info
// You must first delete the old subscription to change the sound name
let deleteOperation = CKModifySubscriptionsOperation(subscriptionsToSave: nil, subscriptionIDsToDelete: ["yourSubscription"])
yourContainer.privateCloudDatabase.add(deleteOperation)
let createOperation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: nil)
createOperation.addDependency(deleteOperation)
yourContainer.privateCloudDatabase.add(createOperation)
Silent Notifications stopped working for my app as well in iOS 13.
On my iOS 12 devices and MacBook, silent notifications kept working correctly.
Recreated subscriptions multiple times without success.
Checked all steps in
https://developer.apple.com/library/archive/qa/qa1917/_index.html
When I saw Ely's answer, I immediately went to check if I had a soundName set for the notification. Though I did not have any, I saw the alertBody empty string and decided to try it without it. After recreating the subscription, silent notifications started working again in iOS 13. When reading the documentation, it seems obvious that you do not want an alert message on a silent notification. However, I do remember adding it at some point to make it work on another iOS version.
In my case, I was creating a RecordZoneSubscription like this:
CKSubscription * subscription = [[CKRecordZoneSubscription alloc] initWithZoneID:self.dataZone.zoneID subscriptionID:[self mainPrivateSubscriptionID]];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.shouldBadge = false;
notificationInfo.alertBody = #""; // THE CULPRIT
notificationInfo.shouldSendContentAvailable = true;
subscription.notificationInfo = notificationInfo;
Solution:
CKSubscription * subscription = [[CKRecordZoneSubscription alloc] initWithZoneID:self.dataZone.zoneID subscriptionID:[self mainPrivateSubscriptionID]];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.shouldBadge = false;
notificationInfo.shouldSendContentAvailable = true;
subscription.notificationInfo = notificationInfo;

How to create multiple shortcuts at application start

So what I am trying is to donate multiple shortcuts (like 20 types of activites) at app delegate...it is weird that it works if I donate in a specific view controller, but if I make a for loop in a app delegate it doesnt work...here is the code:
activity = NSUserActivity(activityType: activityType)
activity?.title = activityTitle
if #available(iOS 12.0, *) {
activity?.suggestedInvocationPhrase = suggestedPhrase
activity?.isEligibleForPrediction = true
activity?.persistentIdentifier = NSUserActivityPersistentIdentifier(activityType)
}
activity?.isEligibleForSearch = true
//self.activities.append(activity!)
if #available(iOS 12.0, *) {
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: [activityType], completionHandler: {[weak self] in
self?.activity?.becomeCurrent()
})
}
Appdelegate is the first thing that's run on app load, this can cause it not to load your shortcuts, consider running them from the first viewcontroller the app opens

Resources