Sudden error with Xcode 14 RC: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement - cloudkit

I just downloaded the Xcode 14 release candidate and I started getting the following crashing error on startup (didn't try the other betas). I made no changes in the codebase. CloudKit was working fine before:
[CK] BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement.
Under Certificates, Identifiers & Profiles in the Developer portal, I've verified that push notifications are enabled.
To fix, I tried removing and re-adding the push-notifications entitlement.
I verified that the APS Environment value is in the entitlements .plist.
I switched off automatic signing and then turned it back on again. I cleaned the build and deleted derived data. I also tried switching back to Xcode 13.4.1 and everything started working again - unfortunately, not a solution.
The error occurs right as container.loadPersistentStores is called.
lazy var persistentContainer: NSPersistentCloudKitContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentCloudKitContainer(name: "not_real_name")
guard let description = container.persistentStoreDescriptions.first else {
fatalError("No descriptions found (AppDelegate.persistentContainer)")
}
description.setOption(true as NSObject, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.loadPersistentStores(completionHandler: {
(storeDescription, error) in
if let error = error as NSError? {
Is this just an Xcode beta bug (in the release candidate)? Is there a way to work around it?

I also just ran into this error today, on the Xcode 14.0 RC. It was on a basically brand new project so I figured it must be something odd with the new version.
To fix, I just did what the error said:
<key>aps-connection-initiate</key>
<true/>
Added that to the app's Info.plist, then it ran again just fine. Also SwiftUI previews started working again.

If you are facing this in simulator. Go to Device -> Erase all content ad settings.. And reinstall the app.

open .entitlements file
and then add "aps-connection-initiate" key and set the value to true
That worked for me

Related

Xcode Version 11.5 CloudKit not working on simulator

before the last update, I was able to manage data with CloudKit on simulator, with the last updating, it's not working, also if I add a file in iCloud Drive, in simulator the folder is not updated.
in my func, I receive couldNotComplete status:
defaultContainer.requestApplicationPermission(.userDiscoverability, completionHandler: {status, error in
switch status {
case .denied:
DispatchQueue.main.async {//necessario perchè lo fa in background e potrebbe crashare senza questo
completionHandler(status)
self.showSettingsAlert()
}
case .initialState:
DispatchQueue.main.async {
completionHandler(status)
self.showSettingsAlert()
}
case .couldNotComplete:
DispatchQueue.main.async {
completionHandler(status)
self.showSettingsAlert()
}
print("#couldNotComplete requestApplicationPermission (func getUserPermission) - probabilmente non ha un account icloud")
case .granted:
completionHandler(status)
#unknown default:
print("#unknown requestApplicationPermission (func getUserPermission)")
}
})
but the problem is in the token:
Optional("Couldn\'t get an authentication token")
Do you have the same problem?
Sorry that I can't help with an answer, but I can say that it isn't just you; this started happening to me too. Some things I know:
Everything works initially, and then at some point I'm asked to re-enter my iCloud password ("Apple ID Verification").
The simulator accepts the password, but past that point CloudKit (and more) stop working.
Here's the error CloudKit returns: Optional(<CKError 0x600002b08b10: "Not Authenticated" (9/2011); "Couldn't get an authentication token">)
I tried using "Features | Trigger iCloud Sync" to see if that would kick iCloud into working, but it didn't.
Signing out on the iPhone simulators never seems to end; so far I've always had to use "Erase All Content and Settings". After that things work again, but not for long.
Signing out on an iPad simulator worked once. After signing back in, everything started working again. Well, so far. :-)
I'm using a test account. I wondered if Apple thought it was a spam account, so I logged into https://appleid.apple.com with it and turned on two-factor authentication, etc. None of that made a difference.
Here are some things I'm planning to try, roughly in order:
new simulator using iOS 13.4 (I'm currently using 13.5)
new test account
Xcode 12 beta
===
So far I've tried:
New simulator using iOS 13.4
Xcode 12 beta
Rebooting my Mac
Ultimately, none of those things have worked; once I start getting the "Couldn't get an authentication token" error--and I typically get it within 24 hours--the only thing that makes the simulator work again is erasing it.
One thing I'm not sure of is whether, once a simulator is in that state, anything can recover it. For example, when I first launched the Xcode 12 beta, and first ran the simulator, it immediately asked for the password. Did the beta start from an already corrupted simulator? More to the point, would Xcode 12 beta corrupt a simulator on its own, or was it just picking up on an error that was actually created by Xcode 11.5? I don't know.
I'll try a few more things...
===
Creating a new test account didn't work, but I may have found something that does: resetting the keychain. Here's how to do it from the command-line:
xcrun simctl keychain reset <device>
After running that command the simulator once again asks for the iCloud password, but the password now produces the expected result: iCloud starts working again.
(If your app was running when you reset the keychain you'll probably have to restart it, or somehow otherwise give it a kick so that it notices the change.)
Simone Pistecchia's comment helped me the most. In the simulator menus select Device > Erase All Content and Settings for each simulator that is having the problem. Then resign into iCloud.

Firebase/Crashlytics Version 4.0.0-beta.1 - ForceCrash?

How do you force a crash on the new version of Firebase Crashlytics 4.0.0-beta.1?
I have tried to crash the app with fatalError(), but the Crashlytics doesn't record the crash in Dashboard.
Also tried to unplug my device, run the app and force crash with fatalError() but still no report in Dashboard.
Also tried Crashlytics.sharedInstance().crash(), but getting error message Type 'Crashlytics' has no member 'sharedInstance()'.
Any ideas?
Thank you
As the documentation says, use
Crashlytics.sharedInstance().crash()
Crash reports are sent to the server when you start the app again.
Option2: If nothing works, just declare an optional and force unwrap it. :) CRASH
var v : Int!
// then in your viewDidLoad() or in button action
let a = v!
You can use fatalError() instead of Crashlytics.sharedInstance().crash()
For new SDK
import FirebaseCrashlytics
fatalError()
Take a look into your Info.plist, rename the following key and set it TRUE
firebase_crashlytics_collection_enabled -> FirebaseCrashlyticsCollectionEnabled
Or you can also try this
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(true)
Use pod version in your file pod 'Crashlytics', '~> 3.14.0' .
This code is working in my case.
Crashlytics.sharedInstance().crash()
Firebase (Google) recommends to use just
// Force a test crash
fatalError()
Old API was deprecated and there is no more crash() method or throwException()
Check this
https://firebase.google.com/docs/crashlytics/upgrade-sdk

Xcode FIREBASE crashes

I have recently upgraded to Swift 4.2 and I am not able to run my project anymore since then.
I had hundreds of mistakes which I all fixed, the app starts but crashes as soon as it tries to access data from my database
example code
guard let currentUser = API.User.CURRENT_USER?.uid else {return}
crash: Thread 1: signal SIGABRT
I had my app working for over a year now and thousands of users so the code worked previously quit fine.
I have updated my cocoa pods to the newest point, as my terminal said that firebaseauth requires at least 1.4 cocoa pods.
I have updated and newly installed all pods, I deleted my plist and downloaded it again and put it into the project, all to no avail.
My app is working if you download the old version from the App Store, but I want to update some things and need it to run again
Any advice? I have tried everything I found
For Firebase 4/5 and Swift 4, here's the function call to get the currently authenticated users uid
guard let currentUser = Auth.auth().currentUser?.uid else { return }

HealthKit error: Missing com.apple.developer.healthkit entitlement

I'm adding code for HealthKit in my iOS Swift app, but I'm getting an error:
/* Ask for permission to access the health store */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if HKHealthStore.isHealthDataAvailable(){
healthStore.requestAuthorizationToShareTypes(typesToShare,
readTypes: typesToRead,
completion: {(succeeded: Bool, error: NSError!) in
if succeeded && error == nil{
println("Successfully received authorization")
} else {
if let theError = error{
println("Error occurred = \(theError)")
}
}
})
} else {
println("Health data is not available")
}
}
Error occurred = Error Domain=com.apple.healthkit Code=4 "Missing
com.apple.developer.healthkit entitlement." UserInfo=0x7fa748534b00
{NSLocalizedDescription=Missing com.apple.developer.healthkit
entitlement.}
How can solve this?
I spent 3 days trying to figure out what was the problem. I found the solution with those steps:
First go to the project (As I show in the image)
Open projects and target lists
Select nameApp WatchKit Extension
Go to Capabilities tab, press on in Health Kit and voila... it is working for me.
I am using iOS 9.3.2 and Xcode 7.3.1
Both of the above answers should be tried first. If however
You're sure the capability has been activated
You're confident your app id associated with your provisioning profile has healthkit turned on and matches the app's bundle id
Then try and force the build to use that specific provisioning profile by selecting your target and going to
build settings -> code signing -> provisioning profile
and selecting it manually.
I've run into cases where get the above error in debug if 'automatic selection' is being used
That error is due to the fact that you have not added the HealthKit Entitlement to your target.
Go to your project settings in Xcode.
From there, navigate to the "Capabilities" Tab.
Scroll down until you see "HealthKit" and flip the switch to on.
Xcode will now add the HealthKit Entitlement to you Info.plist, your {ProjectName}.entitlements file, and your App ID on iTunes Connect
After following these steps, try to run your app again. This time around it should work.
Activate Health kit in Capabilities
If still not worked
check:
Does your provisioning profile includes support for HealthKit?
Does your bundle identifier use the same ID referenced in the provisioning profile with support for HealthKit?
Some additional info that might help. If, under the HealthKit Capabilities the first step "add health kit entitlement to your app id" shows an error, and you have a "Fix This" button which does not do the job... read on...
Many times after working on multiple HealthKit test projects, you may find you have a Bundle ID that matches another Bundle ID used with another HealthKit project (say you duplicated the one project to spin off another test). This contention will show up as an error under the first checkmark in "iOS dev"s picture "add health kit entitlement to your app id". The error listed in the capabilities section unfortunately calls it an "app id" when you need to change the "Bundle ID". Add a number (or some character) in your bundle id string to make it unique. Then the "Fix" button in the HealthKit capabilities settings will work.
The Bundle ID (aka "App ID") is found under the "General" tab to the left of the "Capabilities" tab.
This is bcz you have not Open the Capabilities tab in the target editor, and turn on the HealthKit switch.
and to resolve permission issues , add the following keys in info.plist and write causes.. according to your project requirements.
1.Health Update Usage Description
2.Health Records Usage Description
3.Health Share Usage Description
You can go ahead with free developer account also for authorisation purpose.
good luck
I did add both
NSHealthShareUsageDescription and NSHealthUpdateUsageDescription (make sure the values to be greater than 12 characters - read it somewhere) in Info.plist
Next, similar to Jorge Luis Jiménez screenshot
First go to the project (As I show in the image)
Open projects and target lists
Click on the Apps target (no need for watchkit extension)
Now click on the + sign (Add Library) at the top right
Add HealthKit.
I had a similar error when trying to start a workout on my AppleWatch from the iOS device, using this method:
healthStore.startWatchApp(with: configuration, completion) { } method.
Interestingly enough, I had this error only in the Release mode when the HealthKit entitlement was added only to the WatchKit Extension target. Everything was working well in Debug.
Adding HealthKit entitlement also to the iOS target fixed the issue, but you won't be aware of this requirement until you run your app in Release or through the TestFlight.
Hope, this info will help someone

Unable to run app in Simulator : An error was encountered while running (Domain = LaunchServicesError, Code = 0)

I am unable to run my app in simulator after having trouble with the provisioning profile. I'm doing swift coding in Xcode 6 - beta 4. This was fine before the trouble in the certificate's profile.
I have tried cleaning the build.
Checked the command line to xCode6-beta4 for running.
Checked the build deployment, set to 7.0 so swift won't complain for compatibility
Fixed the error in provisioning.
I fixed it by resetting the simulator:
iOS Simulator > Reset Contents and Settings...
This happens if your extension's bundle ID isn't prefixed with your app's bundle ID. For example if you app is com.mycompany.appname, your extension should be something like com.mycompany.appname.today.
Something else to note, if you're using Swift and are setting a principal class with NSExtensionPrincipalClass, you'll want to make sure your extension target sets "Defines Module" to "Yes" and make the value of NSExtensionPrincipalClass equal to "YourModuleName.YourClassName".
It seems that there are multiple reasons for "domain = LaunchServicesError code = 0" error. I also encountered it, while I try to reinstall app on iOS8 simulator. I cannot reinstall but have to delete the old app first.
The problem was solved by:
In Xcode, fill empty Version or Build field with appropriate value in your Target->General->Identity
In Simulator, reset Content and settings...
After that, everything works fine.
This also happens when you remove the default StoryBoard from template created project of a Today widget. To fix this, I added the NSExtensionPrincipalClass under NSExtension and pointed it to the class containing the Today Widget View Controller, which is by template default TodayViewController.
This looks like this in the Info.plist of the extension:
NSExtension
NSExtensionPointIdentifier String com.apple.widget-extension
NSExtensionPrincipalClass String TodayViewController
Product -> Clean
iOS Simulator > Reset Contents and Settings
Restart XCode
None of the above worked for me, however deleting the Derived Data fixed the issue.
To delete the Derived Data, go to Window > Projects, select the current project, and press the appropriate delete button.
"Reset Content and Settings" from iOS Simutalor menu options and launching simulator after Quitting solved my issue.
The solution for me was not to embed a framework that hadn't been built as an embeddable framework.
Found the cause of the problem for me.
I am using ShareKit via pods. This issue is related to the GooglePlus SDK which ShareKit uses and this has to be updated due to a policy change by Apple.
http://googledevelopers.blogspot.com.br/2014/09/an-important-announcement-for-ios.html
So i replaced my pod "ShareKit" with:
pod "ShareKit/Twitter"
pod "ShareKit/Facebook"
pod "ShareKit/Pocket"
pod "ShareKit/Evernote"
Leaving out the GooglePlus sub project and the application has deployed and runs fine under 8.0 simulators now.
Hope this helps somebody else.
I have resolve this issue. thanks for the advices. :)
This issue always happens when you build your keyboard extension app with same identifier as your main bundle. like this.
If you have this "com.codemagnus.ExAppMain" in your main bundle, your extension should also have this identifier "com.codemagnus.ExAppMain" .. This will result in launch service error if you are going to run in simulator. But you can create a build. However, the issue I have found was annoying. This app can't be install in your device. :/
If you want to run in simulator. You should have this "com.codemagnus.ExAppMain.ExApp" in your extension keyboard where ExApp was you extension name. And your main bundle should be "com.codemagnus.ExAppMain".. This will run perfectly with the simulator. However will result in "Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier."
Embedded Binary Bundle Identifier: com.codemagnus.ExAppMain.ExApp
Parent App Bundle Identifier: com.codemagnus.ExAppMain
I'm still thinking and looking for a solution to solve this issue for ipa build.
This drove me crazy. I checked everything suggested here, reinstalled Xcode, restarted my computer and nothing worked. After checking some previous commits, I found out the issue.
For context, I am working on a custom keyboard extension in Objective C. Adding a new custom keyboard extension target gives you a KeyboardViewController stub class with the "next keyboard" button. I changed the NSExtensionPrincipalClass value in the Info.plist of the extension to be a class name different from KeyboardViewController and started work on it. Eventually I decided to get rid of the the stub KeyboardViewController since it was dead code.
Deleting the KeyboardViewController files and removing them from Xcode caused this problem to happen. Putting them back made the app work again.
In my case, this has resolved the issue.
Bundle Identifier should not be empty. You can find the field with the below reference:
I got this error because I mistakenly changed the value of NSExtensionPointIdentifier. I thought it was supposed to be an ID for my extension, but it has to be one of these values indicating the kind of extension it is.
I started getting this error when I changed my Deployment Target from 6.0 to 7.0. I found that resetting the simulator did solve the issue, and I needed to do this for ALL the simulators that were relevant to the app. But if I went back to 6.0 and recompiled for any particular simulator, then it worked immediately, but going again to 7.0 broke the simulator and I had to clear the settings again.
Obviously the Deployment Target affects the coding in the simulator, and the coding is downward compatible, but not upward. Plus, the log message isn't extremely helpful, saying the app couldn't be hardlinked to a cache file using a manifest (giving the pathnames to the app, cache, and manifest, of course).
Make sure you check build settings; scroll down to the very bottom and make sure your User-Defined Bundle prefix is correct. Usually com.whatever.
Just setting it at the top doesn't always change this bottom setting. This finally worked for me after resetting simulator, frying the derived folder, etc.
I'm under IOS 9.3, xCode 7.3
Xcode 7.3
This could simply happened because your target name is too long. Try change your target name to something shorter ( remember to change your bundleIdentifier to match ).
If you are using apple watch besides the bundle identifier you also have to make sure that in info.plist the key WKAppBundleIdentifier contains the right watch app bundle identifier.
I was getting the similar error while launching the app, thru xCode, "The parent bundle has the same identifier as sub-bundle..."
I shortened the Bundle Identifier in the "Project -> General" for xCode8. Initially, my bundle id was com.companyname..
The application name was more than 20 characters. Once I shortened it 12 characters, it worked for me.
To understand what is causing this error you need to go look at the simulator log files first. These are typically located in ~/Library/Logs/CoreSimulator/CoreSimulator.log or a similar location. So I'd strongly recommend you first look at the log to idenify the root cause and then research that further. (You can take a look at this thread to see where logs are located.)
For example if you get an error such as ErrorDescription=Failed to chmod /Users/username/Library/Developer/CoreSimulator/Devices/then it's probably easiest to reset your simulator. For errors such as ErrorDescription=WatchKit 2 app's bundle ID com.mydomain.AppName.watchapp is not prefixed by the parent app's bundle then there is probably an error with how you have set up the main bundle ID of your project.