NSWidgetExtensionContext openURL Swift - ios

I have been attempting to implement a button to open my iOS app from its widget. I realize this issue has been beaten to death on the forums but I cannot find explanation with the specific error I am receiving. Perhaps some of you more experienced iOS developers can shed some light on this.
I am developing an update to one of my iOS apps for iOS 10 using XCode 8.1 and Swift 2.
Code for my widget's button:
URL scheme added to the widget's info.plist:
The runtime error I receive when pressing the OpenApp button:
AppWidget[11872:3577323] __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)"
// Note: app name has been substituted with appropriate generics.

I often find the OS Status lookup site pretty useful to infer details from errors. An OS error with code -10814 is a kLSApplicationNotFoundErr, which describes the scenario when:
No application in the Launch Services database matches the input criteria.
It sounds like your application has not been properly registered with the system as a consumer of the URL scheme you are using. Have you double-double (double!) checked that the bundle identifier and URL scheme match? Have you verified that your app can be launched with the URL from Safari?

URL scheme should added to the main app's info.plist, not the widget's.

To open the Containing App from Todays Extension:
let myAppUrl = URL(string: "main-screen:")!
extensionContext?.open(myAppUrl, completionHandler: { (success) in
if (!success) {
print("error: failed to open app from Today Extension")
}
})
You also need to add the following lines to the application's info.plist (open as a source code):
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mikitamanko.bubblewrap</string>
<key>CFBundleURLSchemes</key>
<array>
<string>main-screen</string>
</array>
</dict>
</array>
right after the
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
Here's the complete guide how to open the app or share Users Defaults with Extension and the containing app.

Also you should check if you are using any not allowed character for your url scheme.
Maybe it is not your case but I was using this and it was wrong:
my_AppName
instead this finally worked :)
myAppName
as said here, the scheme must begin with alphanumeric character and it can contain only alphanumeric characters, +, - and .

Related

Facebook app not registering iOS installs

Recently our marketing team tried to set up Facebook Mobile App Ads but ran into the following issue.
I reviewed our Facebook Apps developer page and noticed that while the Android app was tracking installs, the iOS app had not registered any installs for the past year, even though I know the app is getting a couple of hundred installs per month.
Since we have tried a couple of solutions, including:
Updates the iOS Facebook SDK to the latest build
Checking the info.plist to make sure that it has all of the correct information and all of the necessary flags are set to true
We have just pushed a TestFlight build with the updated SDK, but still, nothing is being tracked. Has anyone else had similar problems? I have found a few posts suggesting that the app must show the App Tracking Transparency popup, which the user must agree to, though other users have said that this is not required for the Facebook install events.
Before start, I have to say I am new in iOS development, so expect redundant code or worse...
I faced same issue some time ago, what I did was:
Documentation talks about install Facebook SDK from Cocoapods and by Package Manager, I used first package manager with no result, then switch to cocoapods method, BTW docs also said about add version to your pod, like this
I used those pods but with no version, so it looks like this
Next was adding Facebook's data in info.plist, let's suppose your App ID is 123456789 (you can check in Facebook console) and your client token is 123mytoken456 you info.plist should looks like this (don't forget to open as code)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb123456789</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>123456789</string>
<key>FacebookClientToken</key>
<string>123mytoken456</string>
<key>FacebookDisplayName</key>
<string>CHECK_YOUR_APP_NAME</string>
<key>NSUserTrackingUsageDescription</key>
<string>Some random message for asking permission</string>
<key>FacebookAutoLogAppEventsEnabled</key>
<false/>
.
.
.
In your AppDelegate (my target was iOS 11) import two modules:
import FBSDKCoreKit
import FBAudienceNetwork
Docs tell you to add some code in didFinishLaunchingWithOptions, I added them and also added this two statement:
FBAdSettings.setAdvertiserTrackingEnabled(true)
Settings.shared.isAdvertiserTrackingEnabled = true
I created a function to add customs tags, it looks like this:
import FBSDKCoreKit
import AppTrackingTransparency
import AdSupport
import FBAudienceNetwork
func addTag(tag: String) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
AppEvents.shared.logEvent(AppEvents.Name.init(rawValue: tagName))
//Manage all other status
}
} else {
AppEvents.shared.logEvent(AppEvents.Name.init(rawValue: tagName))
}
}
In your Facebook console, register your bundle id, after all this you should see your custom event in about 20 or 30 minutes after event was triggered. And there was no necessity to publish app, just running in Xcode was enough.
Hope this helps

Xcode Testflight Validate ERROR ITMS-90778 NDEF is disallowed

I am trying to upload my app to TestFlight, which using CoreNFC (NDEF).
Unfortunately, I got the error message on Testflight Validate part in (SDK version 13 and 13.1).
I already tried this: Xcode 11 beta can't upload app to TestFlight
but it will Lose NDEF function this: https://stackoverflow.com/a/58128365/5588637
Error messages: Invalid entitlement for core nfc framework The sdk version 13.0 and min OS version 13.0 are not compatible for the entitlement 'com. Apple developer nfc. Readersession formats because NDEF is disallowed
The following worked for me.
Go to your application entitlement file (Which will be mostly .entitlement if you don´t have any environmental setup or changes done to entitlement file name)
Remove all entitlement for NFC other than "NFC tag-specific data protocol"
Finally your entitlement file should have something like this
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
Clean your project and then try uploading to app store again.
Hope it helps :)
I have solved the for iOS 13 TAG entitlment and NDEF is disallowed by:
Remove remove "NFC Data Exchange Format" row from the Entitlement.
Add to the info.plist "ISO7816 application identifiers for NFC Tag Reader Session" and the value for item 0 is should be "com.apple.developer.nfc.readersession.iso7816.select-identifiers"
Attached are a few pictures.
Ok after lots of fooling around, this worked for me (my use case is that i'm scanning NDEF tags):
And yes this is counterintuitive, but the sad fact is: If you want to scan NDEF tags, you MUST remove the 'NDEF' from the entitlements (this may be an apple bug that is resolved later, this is accurate as of Xcode 12.5)
Remove NDEF from the .entitlements file, so it only contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
</dict>
</plist>
Add the following to the info.plist:
<key>NFCReaderUsageDescription</key>
<string>This app would like to use NFC for some reason.</string>
No need to add "ISO7816 application identifiers for NFC Tag Reader Session" to the info.plist
Read the NDEF tag using code like this:
session = NFCNDEFReaderSession(delegate: self, queue: .main, invalidateAfterFirstRead: true)
session?.alertMessage = "Please hold your tag up against the the rear side of your iPhone, next to the camera."
session?.begin()
my two cents about.
1) workaround of Josean works
2) my app fails the first time, I can confirm this weird behaviour as CH Wing wrote
3) some hints in "https://forums.developer.apple.com/thread/117329"
4) I added these keys to plist and seems working, not to entitlements.
(but at apple dev forum seems it's the way... in PLIST..)

How to add a credential provider app extension for iOS 12 in xamarin

I’m trying to leverage the new extension to work with a password management app, and I’m running into a road block setting it up. It could be my googling skills but there is almost no documentation on how to do this with xamarin.
What I have so far:
Added com.apple.developer.authentication-services.autofill-credential-provider as a custom property into my iOS project Entitlements.plist
Created an ActivionView extension since there is no credential provider option when creating a iOS extension project.
Changed the ActionViewController to a CredentialProviderViewController
Updated the MainInterface.storyboard to use the CredentialProviderViewController
Added com.apple.developer.authentication-services.autofill-credential-provider as a custom property to the autofill Entitlements.plist
I don’t see the option under Settings>Passwords & Accounts to use my app for the autofill. I must be missing some key pieces. Does anyone know what I should be doing instead?
Here is my Entitlements.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.orginization.appname</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.orginization.appname</string>
</array>
<key>com.apple.developer.authentication-services.autofill-credential-provider</key>
<true/>
</dict>
</plist>
I have confirmed that this is a bug with Xamarin.iOS. Specifically, there is an enumeration of and validation against a list of known Extension Points. The credential provider point introduced in iOS 12, and any others after iOS 10 are not present.
I've forked the Xamarin.iOS code and made the necessary patches and confirmed that I am now able to successfully deploy a credential provider that shows up in the AutoFill Passwords provider list in iOS settings. I will file a bug and submit a pull request as soon as I can, but I may go through and make sure all the other extension points are present first.
Edit: All of my pull requests have been merged into the main development branch and will hopefully be part of an official release soon.

HKHealthStore preferred units not supported for universal apps?

I have a universal iOS app that references HealthKit. When the app is installed on an iPhone the app uses HKHealthStore to retrieve health data and when it is on an iPad I skip the HealthKit queries by checking if HKHealthStore.isHealthDataAvailable is false. This all works well but in order to have the app run on an iPad I have to remove the "healthkit" entry from my app's .plist under "Required device capabilities". This makes sence because the iPad doesn't have healthkit on it so requiring it makes it so the app won't install on the iPad. All of this has already been done in an app I have submitted to the app store and has been approved.
Now I am making an app update and I want to show unit preferences that a user may have manually adjusted in the Health App. The documentation for HKHeathStore says you can do this using the preferredUnitsForQuantityTypes method. However, calling this method from my iPhone app gives me the following error:
Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}
Except I have the healthkit entitlement in my app id already. If I add the "healthkit" entery under the "Required device capabilities" section of my .plist, then this error goes away and I get the desired results. But this is not a solution for me because then I can't install the app on an iPad.
My question is, how can I support a universal app where the iPhone version can make a successful call to HKHealthStore.preferredUnitsForQuantityTypes?
EDIT
Here is what my .entitlements file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.mycompany.myapp</string>
</array>
</dict>
</plist>
I found out what was happening here. There was a threading issue between when the HKHealthStore was requesting access to health types and requesting the preferred units. I'm not sure why the .plist entry fixes this issue... but moving the preferred units request into the completion block of the HKHealthStore's requesting access method fixed the issue.

iOS Enterprise OTA distribution Unable to Download Application

I created an iOS app and want to distribute it Over-The-Air. I followed this guide:
http://help.apple.com/iosdeployment-apps/mac/1.1/?lang=en-us#app43ad77ea
The App is signed with the enterprise certificate and contains the distribution provisioning profile.
When I try to download the App onto the ipad (using the technique described in this guide), a square icon with my download icon appears on the screen with the name "Waiting...", then a second later the name changes to my actual application name and then again a second later i receive the error message:
Unable to Download Application
"Your Application" could not be downloaded at this time.
in the guide, there are three troubleshooting tips:
if wireless app distribution fails with an “unable to download”
message, check the following:
Make sure the app is signed correctly. Test it by installing it on a
device using iPhone Configuration Utility or Apple Configurator, and
see if any errors occur.
Make sure the link to the manifest file is correct and the manifest
file is accessible to web users.
Make sure the URL to the .ipa file (in the manifest file) is correct
and the .ipa file is accessible to web users.
I checked all three things and they are fine.
What else could cause my download problems?
As alexey mentioned, too many reasons can cause that message. Apple use it as a "catch all errors".
You can diagnose it through the Console. Connect the device to your desktop and access it either from XCode's Organizer (mac only) or iPhone Configuration Utility (mac and windows). But...
It just ain't that simple! :-(
Console may be far from enough. Sometimes there is no relevant message there.
Then, the last resort is following a checklist. Doing all over from zero again. There are many out there... But following there's my generic and non-detailed checklist for Over The Air distribution, at the moment.
Have a Distribution build - This is the most complicated part, done always on the web, and Apple changes the steps all the time. In general, you need a certificate, an identifier and the provisioning profile. Listing devices is almost always required. My current choice is "Distribution -> In House".
P.S.: If you do want to list the devices, make sure the UDIDs are correct. Many issues reported here.
Set the profile under Project -> Build Settings - Since XCode 5, things changed. Instead of code signing with an identity you can clear all that up and set it under *Code Signing -> *Provisioning Profile. The Identity should automatically change to "Automatic". There's also no more need to manually download files from step 1 and install them. XCode manages that now.
Archive - In Xcode 5, there's no need any more to "Build for Archive". Just archive it. It should show up next on Organizer, and it will take some time if it's a big project. Many errors can come up on this step, but they're almost always related to code compilation and not to OTA.
Deploy - Now in Organizer -> Archives, select the proper archive (should be already selected as the most recent one) click on "Distribute", then Save for Enterprise or Ad Hoc Deployment. May be big wait now. When saving the file, there is an option to "Save for Enterprise Distribution". That is a completely misleading name. What it really does is create the plist file. If you have one already, it's fine. You can even manually edit it, which is generally better. The plist be needed for step (5). Here's a good one:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>http://example.com/app.ipa</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>http://example.com/FullSizeImage.png</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>http://example.com/Icon.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.example.app</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>for iOS</string>
<key>title</key>
<string>My App</string>
</dict>
</dict>
</array>
</dict>
</plist>
Distribute - Skip this step if you want to install it using XCode or iPhone Configuration Utility. You're done. This is putting on the file on a web site. "Simply" add a HTML page with a href link such as this:
itms-services://?action=download-manifest&url=http://example.com/app.plist
Unfortunately dealing with web servers is never simple. So also check the server mime-type! I've made a couple PHP files to deal with them, if your server supports php. Just keep your files as they are (the plist, html and ipa) and link to app.plist.php instead:
app.plist.php
$file = fopen("app.plist", "r");
while(!feof($file)){
$line = fgets($file);
print str_replace(".ipa", ".ipa.php", $line);
}
fclose($file);
?>
app.ipa.php
<?php
header('Content-type: application/octet-stream');
$file = fopen("app.ipa", "r");
while(!feof($file)){
$line = fgets($file);
print $line;
}
fclose($file);
?>
Verify - Ensure that all files listed in the assets array are available to download. If any of these files return 404 or such (including the icons) the entire install will fail. You must either (A) make those files available or (B) delete those missing entries from the plist. The icon entries are not required for the download to work.
Here is an example plist with no icons:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>http://example.com/app.ipa</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.example.app</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>for iOS</string>
<key>title</key>
<string>My App</string>
</dict>
</dict>
</array>
</dict>
</plist>
The file examples are a very important part of the checklist. They have to be 100% correct.
Double check the plist and html files!
P.S.: I'm writing this answer because, in my case, it was a "simple" matter of wrong link on the .plist file. And, as such, it's hard as hell to diagnose. Well, only doing this checklist could I find the error! It was pointing to "another-app.ipa" rather than "app.ipa"!
There are a plenty of reasons to cause this message.
The best way to diagnose it is to connect a device to Mac and look Console for the device in Organizer.
In my case, for example, it was:
verify_bundle_metadata: This app was not build to support this device family
Answering my own question:
The problem was that one of the thumbnails did not have the correct path set in the manifest.plist - so not only the ipa needs the correct path, but also the temporary download icons, otherwise the installation will fail with the mentioned error message.
Another Issue that it could be is that both the .plist AND the .ipa need to be hosted with HTTPS and not just regular HTTP. The software package string should look like below:
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>https://example.com/app.ipa</string>
Stupid little oversight but it was tripping me up for awhile.
We did experience the very same error message when trying to install an iOS 5+ app to an iOS4.3.5 phone.
Did you also check deployment/build targets and target architecture to match the device(s) showing that issue?
Make sure the casing is matching in all the files. They tend to be case insensitive.
In my case the issue was on my device an older version of same app was installed with same bundle identifier (downloaded from applstore) so now when I was trying to download its new version via enterprise distribution it was doing nothing, no error at all. Delete existing version from the device solved my issue.
I found in console.
installcoordinationd(MobileInstallation)[99] :
****bundleID****:5:11:1:1:Updating PlaceholderMetadata for
****bundleID**** with failure 1 _LSInstallType 1, underlyingError
(Error Domain=MIInstallerErrorDomain Code=13 "Failed to verify code
signature of
/private/var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.IoCSM9/extracted/Payload/App.app
: 0xe8008016 (The executable was signed with invalid entitlements.)"
UserInfo={LibMISErrorNumber=-402620394,
LegacyErrorString=ApplicationVerificationFailed, SourceFileLine=147,
FunctionName=+[MICodeSigningVerifier
_validateSignatureAndCopyInfoForURL:withOptions:error:], NSLocalizedDescription=Failed to verify code signature of
/private/var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.IoCSM9/extracted/Payload/App.app
: 0xe8008016 (The executable was signed with invalid entitlements.)}),
source 17>
Here we should look at:
Failed to verify code signature of App.app
The executable was signed with invalid entitlements.
In my case it was because i downloaded enterprise build from amazon. But the provisioning profile, which it was builded with, was expired (figured out in developer console).
Another one with the other purpose:
"This app could not be installed at this time."
UserInfo={NSLocalizedDescription=This app could not be installed at
this time., NSUnderlyingError=0x100cbd3c0 {Error
Domain=MIInstallerErrorDomain Code=64 "Upgrade's
application-identifier entitlement string (BBBUUUU.com.bundle.www)
does not match installed application's application-identifier string
(CCCEEEE.com.bundle.www); rejecting upgrade."
UserInfo={LegacyErrorString=MismatchedApplicationIdentifierEntitlement,
FunctionName=-[MIInstallableBundle
_validateApplicationIdentifierForNewBundleSigningInfo:error:], SourceFileLine=878, NSLocalizedDescription=Upgrade's
application-identifier entitlement string (BBBUUUU.com.bundle.www)
does not match installed application's application-identifier string
(CCCEEEE.com.bundle.www); rejected
Here i just removed the previous version of the app. The error was, because i changed the team for the bundle ID and it was installed the app with previous bundle ID.
Open console with:
Xcode > Window > Devices
Select the device
Expand a console with with a box with an arrow inside of it in the bottom left corner.
Try checking bundle identifier in your XCode and .plist file
In my case I did following to get rid off "cannot connect to dl.dropboxusercontent" message after providing ipa shared link.
1. Removed md5 section from plist
2. Uploaded 512*512 and 57*57 images to drop box, and provided shared link in fill_size_image and display_image in plist.
The first thing to check here is that the device you are installing on has the correct OS for the app your are installing. For instance, if the app is built for iOS 11, and your device has iOS 10 on it, then the app will install but you will see this error "Unable to Download Application".
In my case, there was a problem with incorrect file permissions of the FTP folder and the files inside (manifest, ipa, images). Check that they have 775 (rwx) and that Owner/Group is your owner.
The error in the device console was like "Cannot connect to iTunes Store" or "Failed artwork for bundleID" or "Failed to load placeholder artwork for bundleID". But it's just about the files.

Resources