iOS Application crashing on use of CMPedometer functions - ios

I have a Xamarin.iOS application where I am using this guide to make use of the CMPedometer floors ascended property. Here is some relevant code on my single view app:
CMPedometer pedometer;
...
public override async void ViewDidLoad(){
base.ViewDidLoad();
if (CMPedometer.IsFloorCountingAvailable)
{
pedometer = new CMPedometer();
//app crashes here:
pedometer.StartPedometerUpdates(new NSDate(), UpdatePedometerData);
var data = await pedometer.QueryPedometerDataAsync((NSDate)DateTime.SpecifyKind(DateTime.Now.AddHours(-24), DateTimeKind.Utc), (NSDate)DateTime.Now);
UpdatePedometerData(data, null);
}
}
My very basic app crashes when I try to get updates from my CMPedometer with little error output. This is what I get:
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
which may be an issue with my app permissions? If that's the case I am not sure how to grant/ask permissions on using the CDPedometer. Thanks for any help

Got this link. You have to add privacy setting for motion in your plist
https://blog.xamarin.com/new-ios-10-privacy-permission-settings/

Thanks to #panthor314 for getting me pointed in the right direction. Unfortunately the blog link above is dead, but this seems to be the new location for this information:
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/security-privacy?tabs=windows
This link explains:
Apps that fail to provide the required keys will be silently terminated by the system when they attempt to access one of the restricted features or user information, without error! If an app starts unexpectedly failing on iOS 10, ensure that all of the required Info.plist have been specified.
The relevant privacy key is NSMotionUsageDescription:
Motion Usage Description (NSMotionUsageDescription) - Allows the developer to describe why the app wants to access the device's accelerometer.
To add the property:
Right-click on Info.plist in your Solution Explorer (double click seems to open a different window)
Select Open With...
Select Generic PList Editor and click OK
At the end of the plist, click the + icon to add a new entry
Change Custom Property to Privacy - Motion Usage Description
Enter text to display to the user about accessing steps such as "This application would like to access your steps data"
Save the file and run the application again

Related

iOS 13 Image Capture API for accessing external camera's filesystem?

In Apple's iOS 13 feature list page they have the following blurb:
Image Capture API
The Image Capture API allows developers to leverage the Camera
Connection Kit to import photos directly into their apps.
I've been looking but I can't seem to find any actual documentation about this change, and where it exists in the API. I also remember hearing a second or two talk about it in the keynote/state of the union in WWDC 19, but again no details in any session I've found so far.
It seems like you would be able to plug in a camera or it's SD card to the USB-C/Lightning port on the iOS device and be able to access that from within a 3rd party app. I know you can import to the system photo library, but that has been around for years. I also know about ExternalAccessory framework for MiFi hardware, but I don't see any significant changes to that, and it doesn't seem to have the described functionality exposed.
I do see that UIDocumentPicker can be shown and it allows the user to select a location that may be on a connected USB device. While that could work, it's not camera specific and would be quite error prone, if the user doesn't select a valid camera location.
Anybody know where I can find more info about this change or how you can programmatically access the camera's filesystem? The camera will have the standard camera folder structure DCIM and stuff, so it is recognized as a camera filesystem by many Mac apps.
You're looking for the ImageCaptureCore framework. This is the same framework that exists on macOS for importing from SD Cards and Cameras. It is now available in iOS 13.2.
Update:
The ImageCaptureCore API is now working as of iOS 13.2.
However, be warned that as of iOS/iPadOS 13.1 Beta 3 (17A5837a) I have not been able to get it working yet (reported to Apple FB6799036). It is now listed with an asterisk on the iPadOS Features page indicating that it will be "Coming later this year".
I'm able to start an ICDeviceBrowser, but I see permissions errors when a device is connected and don't get any delegate messages. So there may be some permission or entitlement that is needed before it starts working.
Unfortunately there is no documentation or sample code (even for macOS) on Apple's developer site. But the framework does exist in the iOS 13 SDK and you can look at the header files there.
We use this framework in our macOS app and using just the headers to figure things out isn't too bad. You'd start by creating an ICDeviceBrowser (ICDeviceBrowser.h), setting its delegate, and then starting the browser:
#interface CameraManager() : NSObject <ICDeviceBrowserDelegate>
{
ICDeviceBrowser* _deviceBrowser;
}
#end
#implementation CameraManager
- (id) init
{
self = [super init];
_deviceBrowser = [[ICDeviceBrowser alloc] init];
_deviceBrowser.delegate = self;
[_deviceBrowser start];
return self;
}
...
#end
You should then start receiving delegate messages when a camera device is connected:
- (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing;
- (void)deviceBrowser:(ICDeviceBrowser*)browser didRemoveDevice:(ICDevice*)removedDevice moreGoing:(BOOL)moreGoing;
When you get a didAddDevice: message you'll then want to use the ICDevice (ICDevice.h) and ICCameraDevice (ICCameraDevice.h) APIs to set a delegate and start a session. Once the session has started you'll start receiving delegate messages:
- (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing
{
if ((addedDevice.type & ICDeviceTypeMaskCamera) == ICDeviceTypeCamera)
{
ICCameraDevice* camera = (ICCameraDevice *) addedDevice;
camera.delegate = self;
[camera requestOpenSession];
// probably want to save 'camera' to a member variable
}
}
You can use the delegate method:
- (void)cameraDevice:(nonnull ICCameraDevice *)camera
didAddItems:(nonnull NSArray<ICCameraItem *> *)items;
To get a list of items as they are enumerated by the API or wait for:
- (void)deviceDidBecomeReadyWithCompleteContentCatalog:(ICDevice*)device;
And then use the .contents property on the ICCameraDevice to get all of the contents.
From there you can use the ICCameraDevice to request thumbnails, metadata, and to download specific files. I'll leave that as an exercise to the reader.
As I mentioned above this doesn't seem to be working in iOS/iPadOS 13.1 Beta 3. Hopefully this will all start working soon as I'd really like to start testing it myself.
This is now working in iOS 13.2.

Unable to get FBNativeAd Test Ad working in our iOS App

We have an iOS App (SWIFT 4) where we want to integrate Facebook Audience Network for Native Ad. Following the instructions at https://developers.facebook.com/docs/audience-network/ios (EXCEPT for entering "Payment info" in our Facebook Business account as we are in development phase still), https://developers.facebook.com/docs/audience-network/ios-native and https://developers.facebook.com/docs/audience-network/testing#testing-testAd our code (in ViewController viewDidLoad()) to load a TEST AD is as follows:
let nativeAd = FBNativeAd(placementID: "IMG_16_9_LINK#" + "OUR_PLACEMENT_ID" )
nativeAd.delegate = self
nativeAd.mediaCachePolicy = FBNativeAdsCachePolicy.all
nativeAd.load()
But FBNativeAdDelegate callback does not fire.
func nativeAdDidLoad(_ nativeAd: FBNativeAd) {
...
}
Using Facebook -> Manage Property -> Property Settings -> Ad Request Debugger, there is no request reaching the Server for reasons unknown. In our App "info.plist" file "App Transport Security" has property "Allow Arbitrary Loads" enabled (YES) just in case.
We have tried both Simulator on Mac as well as iPhone/iPad where Facebook App was logged in as the SAME user with the Business Account matching OUR_PLACEMENT_ID.
Any help to resolve the mystery will be highly appreciated.
Thanks!
It started working after set Key NSAllowsArbitraryLoadsForMedia to YES under App Transport Security in Info.plist! Note that this key will have to be manually added as it is not available as a default in XCode editor.
How I wish Facebook had clear documentation on this which would've saved 2 days of wasted effort!

Open HomeKits X-HM:// URL sheme

I'm creating an App with the HomeKit SDK and I'd like to add an uncertified accessory programmatically. My goal is to build a user-friendly and convenient pairing process without having a printed QR-code or NFC ready accessory. I'd like to hand on the pairing pin / pairing URL programmatically, so the user doesn't need to worry about any codes.
I've already set up the HMAccessoryBrowser and it finds the accessory fast and reliable. So far I've the HMAccessory object as well as a valid pairing link (example: X-HM://123456789ABC) and I've tried three ways, in order to add the accessory:
Generate a QR-Code with the Url and scan it with the native Camera or Home App, which works very well. - Problem: You need a second device / print the QR code to scan the QR code.
Use HMHome's addAccessory function to add the HMAccessory directly. - Problem: After accepting the prompt asking to add the device, the Home App opens and asks to scan the QR code or to choose the device manually and enter the code. This doesn't make sense for me, unless I've just told HomeKit which accessory it should add but it's also doing this behavior with accessories of the HomeKit Accessory Simulator and also mentioned in this post.
Open the X-HM URL with UIApplication.open(). - Problem: Also with HomeKit permissions, the function fails with the error message:
-canOpenURL: failed for URL: "X-HM://123456789ABC" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
Before granting access to my Home Data, the error message was something like, you do not have the permission to open this url.
In my opinion the direct opening of the pairing URL seems to be the best solution unless it's the same process for the user like adding any other HomeKit device without the need to scan a QR code, but I'm running out of ideas.
I'd appreciate any idea, workaround or other process, to get this thing paired, thanks in advance!

How to accept the google permission prompt by default while using appium

I'm trying to automate the app , but suddenly in middle the google permissions window for permission like phone , location etc pops up , is there any way that I can make sure always permission pop ups are allowed
Try to set desired capabilities:
autoAcceptAlerts = true
Since you said google permissions, I am assuming you are dealing in Android. Also since there is no language tag, I am sticking to Java, you can frame the logic in any language you are using.
Well, its sad to inform you that currently there seems to be no such capability added for android. Though iOS has few similar capabilities.
So, for android what you can do is logically -
If these pop-ups are device dependent, change the device settings that these pop-ups are not allowed.
If these pop-ups are relevant to application permissions, then you must know when they would occur. Just keep a check -
List<WebElement> popUp = driver.findElement(<find the pop up using your locator strategy>);
if(popUp.size()!=0) {
WebElement accept/dismiss = driver.findElement(<find the button accordingly>);
accept/dismiss.click();
}

Sdk xamarin blank map loading app from background

We've been using the latest version (unified API) of the iOS Google Maps component from xamarin in our app with great success. We of course have the proper API key in place and can render maps all day with custom markers and other features.
Our problem is that when the app "sometimes" comes back from being in the background (home button pressed), the map no longer draws any data on it. The map is blank but the Google logo is still in the bottom left corner so I know the control hasn't been unloaded. Once in this blank map state we have to kill the app and restart it to start getting map data drawn again. There are no exceptions thrown and no errors in the iOS logs. I have done a lot of research and this issue also presents it self when the maps do not have a proper API key but that clearly isn't our scenario unless somehow the maps component is losing that API key connection?
what could be the cause of this and how can we fix it Please? can we pay for support from xamarin for this issue if there is no 'quick fix'?
Here is the screenshot of the issue:
No worry I also had the same problem when I'm working with this Component
try not to save API Key on any constants. Directly pass the value. If it is not working try regenerating the API Key. Map should
I thing currently you are following this code pattern like how they provide
using Google.Maps;
...
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
const string MapsApiKey = "<Get your ID at https://code.google.com/apis/console/>";
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
MapServices.ProvideAPIKey (MapsApiKey);
...
}
}
Instead of this code you can directly pass the API Key like below or you might be forgot to remove the angle brackets.
MapServices.ProvideAPIKey ("AIzaSyAnxfhuAwEqdVhQpoUkGFZpsBukOSXVFr0");
Happy coding:)

Resources