Xcode Version 11.5 CloudKit not working on simulator - swift

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.

Related

XCode 5 hangs with a timeout error when validating/uploading a "ready to be uploaded" app

I've been developing and uploading apps for some months. Whenever they needed being uploaded to the app store, I could do it without problem, but now, I'm stuck with one that doesn't want to be validated/uploaded. XCode says "the request timed out" after MANY minutes with a spinwheel on screen.
The differences between my old updates to the app store and the one I'm trying right now are:
-Xcode 4.X before, Xcode 5 now.
-I had to recreate the app store certificate/provisioning profiles, because they just expired.
-I inherited this project from other coworker (not here anymore) and maybe my "developer profile" is somewhat conflicting with some certificates, etc... (Still many dark areas for me).
I've kind of tried "everything". Erasing provisioning/profiles, closing Xcode, resetting, cleaning my project. But no luck. My current Xcode 5 is able to compile my app perfectly, I'm even able to select the distribute option before uploading (the app is ready to be uploaded onto itunes connect), I even login with my client credentials onto itunes connect, I can even select the correct provisioning profile (app store profile, not a developer one), but no luck:
If I choose to upload or validate, Xcode just complains with some kind of "dull" timeout error.
Any hints? Any way to debug what happens behind the curtains?
Greetings, I'm at a loss.
EDIT: Apparently, the timeout failing event appears in the validation process. If I try to upload, the status log says "Failed Validation". If I try to validate, obviously there's also a "Failed validation" error. Where can I find some log to see what part of the validating process is failing?
Well, apparently: "Problem solved".
After 2 boring days trying to upload my app (via Xcode 5, and via Application Loader), I've discovered that Apple upload servers seem to be overloaded (unless a better explanation arises).
I'm in Europe, and from 9 to 14 h my app was ALWAYS rejected. But once I tried it after 16h, the upload and validation processes worked like a charm (both with Xcode 5 and with Application Loader).
Why this? No idea, but I didn't change anything in my upload process, so it's sad, but the solution is:
"Have patience, and wait to upload your app on a time slot where Apple upload servers are not overloaded". The sad part is: No one knows WHEN is that time :)
I solved it by switching Internet provider.
I simply connected my laptop to my iPhone via Personal Hotspot and used LTE network to upload the app.
It worked for me twice.
for Xcode 13 and Mac OS Big Sure
Install the "Transporter" app from the MacOS app store.
From Xcode's organizer, select your archive and press "Distribute App"
Instead of "Upload", select "Export" and proceed as usual.
Drop the exported .ipa into the transporter and press "Deliver".
In my case I changed the dns server from my provider to the google dns server (8.8.8. and 8.8.4.4).
I think you can try any other, if your providers dns or what ever doesn't work
Faced the error many times, not sure why.
Try this
Export the ipa after the archive
Add and upload in Transporter
I get 100% success in uploading and feel a little quicker than Xcode's upload.
I actually called Apple Developer Support about this and they solved the problem!
It turned out that my recovery email address in my Apple ID (not the main email address but the recovery one) was not verified. They had me go to http://appleid.apple.com, login with my Apple ID, and then go to the 'Password and Security' section (on the left).
After answering my security questions I was able to resend the verification email, and once verified I was able to log in on Xcode straight away!
I have the observation that with Mavericks and App Nap enabled, a hidden Organizer window within XCODE will cause the network connection to be dropped.
Even if the window is occulated (hidden) for just a second).
Make sure the window is always visible and the problem does NOT occur.

Any application crashes on ios 5.1.1 whith xcode 4.3.3

Every application that works on simulator crashes on my device at the very beginning. Even if it's just a blank app. And the xcode doesn't stop debugging and doesn't show any log. I dont have a developer id so i just bypassed the code signature but i don't think it's caused by that. Tried out different build settings but nothing helped...
You can't just bypass the code signature, It won't run.
What you're seeing is not a crash, but the device closing the app.
You need a valid Developer ID, and the necessary certificates to be able to test on a device.
You however do not need a valid Developer ID to test/run in the simulator.

Finished Running on iPhone

I am trying to test my app on an iPhone 4S. When I build and run from Xcode, the project is successfully compiled but after that Xcode says:
Finished running MyApp.app on MyiPhone
The app perfectly work on the simulator and the provisioning profile works correctly (I tried to load an empty app and it works).
If I try to manually load the app I get this message:
The Info.plist for application at
/Users/*/Documents/App/AppName/DerivedData/AppName/Build/Products/Release-iphoneos/AppName.app
specifies a CFBundleExecutable of AppName, which does not exist.
Where is the problem?
The connection that XCode creates with the device is rather fragile, and can easily be corrupted if anything goes amiss in the debugging test, most commonly if the developer stops a build, while it is being moved to the device.
I have a routine of things I go through, when this occurs. If one doesn't work, I go further down the list.
Check your signing certificates
: This error can occur if you mess around with the certificates too much. Make sure your current scheme uses the Debug signing when making a debug build, and check in your application settings if the current debug signing certificate is a debug certificate. (Not AppStore, AdHoc or Enterprise).
Reestablish connection with the device
: Look under devices in your Organizer. Check if the device you are using is present and marked with a green bullet. If orange or grey, reconnect the device with the USB. For precaution, wait a couple of seconds from taking the cable out before you insert it. It should make no difference if you eject the cable from your mac, or the part connecting your iDevice.
Reactivate development on the iDevice
: Being unaware why this happends, some devices revert to a non-development stage from time to time. Clicking the "Enable development" under Organizer > Devices seems to clear this off.
Flushing XCode device connections
: Something that often is needed, you can simply shut down XCode (and to be safe, close the iPhone simulator as well) and start it up anew. Deleting the debug application present on the iDevice is also a good idea.
Restart your iDevice
: Tedious as it might seem, restarting your iDevice is sometimes needed, since the pipe held on the device might be corrupted.
Restarting your developer machine
: If everything else fails, a restart of your mac is often required. I have never experienced this error without having it fixed by now.
I hope this checklist will help you through.
Try cleaning the project.
SHIFT+CMD+K
Found the same bug in XCode 9 while running the project on iPhone 5s. Clean the project and it will work.
Clean.
Build.
Run.
It's work for me.
I had similar issue. When I run program on iPad2 it compiles and installs app on device, wait for some time, and display an alert. Then I followed steps below
1) Removed that application from device.
2) Disconnected iPad and tried again.
Then it successfully run in device. If this not resolved your issue, do
Rename your application to some thing else and try to run. It will run. Lastly you can make an "ipa" file with Ad Hod distribution and can test on device.
Looks like you are trying to run a release product on the device. You are probably signing it with production key. Run it as debug.
Maybe I'm totally off with this guess but the last time I got the same message was when I had some required hardware capabilities set in the Info.plist which the target device didn't comply with. (E.g. requiring a camera and trying to run the app on an iPad1.)
I've just finished chasing down a similar problem.
An app that worked on the device (iPad 1) and on the simulator stopped loading on the iPad but continued to function as before on the simulator. When "run" with the device as target, it compiles and then goes immediately to "Finished Running...".
I did all the usual bits - removed the app from the device, ran Product/Clean, removed derived data, shut computer and device down cold, but with no luck. Other development apps loaded and ran fine.
This app uses GameKit. When I removed the gameKit requirement from Info.plist, the app loaded and ran correctly on the device again - including the GameKit functionality (no kidding). When I added gameKit back in, it failed again. When I added the gameKit requirement to other apps, they failed to load to the device as well. It appears that something has happened to the gameKit setting on the device, although gameKit is there and functions as always. I'm suspicious that this one has to do with the state of the sandbox.
I've got to make a few changes to get the app running on the iPhone and I'll test that as well. I'll repost if I sort it out.
Si it seems that XCode build, ran and finished but the app failed to be deployed and was not even copied to the device.
In fact, there should be something in the XCode project that is broken. This is easily corrupted. The best move is to build a new project from scratch. Don't forget to add armv6 support if needed.
It works well for me!
Check the device log
It may occur, that you are using a provisioning profile, which does not allow one of the entitlements, listed for your target.
For example
entitlement 'entitlement-name' has value not permitted by provisioning profile 'Your Profile Name'
For me, the usual culprit is that I have an app store build already on my device.
Different/same version numbers might make things worse. I haven't looked into it too deeply since deleting the version that is already on my device usually fixes the issue.

XCode 3.2.5: Deploy Debug Build to iPhone iOS 4.2.1 is FAILING

I am having one of those horrible days where absolutely everything is broken.
I'm trying to deploy my application to my iPhone. I have done a full system restore to 4.2.1 on both devices. The iPhone is simply having none of it: http://cl.ly/3O1C242k210T2I0w253Q -- What's going wrong?
Organiser picks the iPhone up no problem, gives it the green light, but XCode won't deploy the app: 'No provisioned iOS device is connected'
I have tried:
rebooting the computer, restarting X code, plugging in the iPhone, attempting to deploy. pretty much every combination thereof.
organiser -> deleting and recreating Xcode's default provisioning profile
target settings -> making sure the correct provisioning profile is selected which it is
going onto developer.apple.com -> provisioning portal, and making sure X code automatic provisioning profile is there as it should be, which it is
putting the iPhone in to restore mode, and reinstalling the latest iOS
The only thing I can think of is that it is a UK locked phone, with a UK SIM inside, and when I turn it on it gives me some ' waiting for activation ' message: http://cl.ly/0I390x2Z3E3A040V2J2h so maybe it is possible that it never activates and this is somehow a barrier. can anyone confirm?
( I doubt it is this; I'm pretty sure the phone is capable of activating itself even tho I'm not in the UK, seeing as I have the correct SIM card in. I remember one time reinstalling iOS or something similar, and it needed the activation. so I think it does successfully activate. However, I don't know how to check whether activation has completed or not. )
But I have successfully deployed a load of apps to this device in the past. I can't understand why XCode is digging its heels in today?!
PS the only other thing I can think of Short of buying new hardware is reinstalling Xcode, which I guess I will have to try at some point. maybe even reinstalling my MacBook's OSX. but really I can't see how this would help...
I'd suggest checking your code-sign parameters. Maybe it's signed with app profile that doesn't have your device's UDID added through provisioning profile?
Someone on IRC got me to try deploying a default template app, and that worked.
I subsequently removed and reinstalled the SDK, and the problem has gone away.

Reset push notification settings for app

I am developing an app with push notifications. To check all possible ways of user interaction, I'd like to test my app when a user declines to have push notifications enabled for my app during the first start.
The dialog (initiated by registerForRemoteNotificationTypes), however, appears only once per app. How do I reset the iPhone OS's memory of my app. Deleting the app and reinstalling doesn't help.
Technical Note TN2265: Troubleshooting Push Notifications
The first time a push-enabled app
registers for push notifications, iOS
asks the user if they wish to receive
notifications for that app. Once the
user has responded to this alert it is
not presented again unless the device
is restored or the app has been
uninstalled for at least a day.
If you want to simulate a first-time
run of your app, you can leave the app
uninstalled for a day. You can achieve
the latter without actually waiting a
day by setting the system clock
forward a day or more, turning the
device off completely, then turning
the device back on.
Update: As noted in the comments below, this solution stopped working since iOS 5.1. I would encourage filing a bug with Apple so they can update their documentation. The current solution seems to be resetting the device's content and settings.
Update: The tech note has been updated with new steps that work correctly as of iOS 7.
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
UPDATE as of iOS 9
Simply deleting and reinstalling the app will reset the notification status to notDetermined (meaning prompts will appear).
Thanks to the answer by Gomfucius below:
https://stackoverflow.com/a/33247900/704803
Another just for testing solution to this is by simply changing your bundle id. Just don't forget to change it back once you're done!
On iOS 9.0.2, I'm getting the "register push notification alert" every time I delete the app and reinstall it. This is true for both AppStore production downloads and adhoc mode.
UPDATE: It is confirmed this is working for iOS 9.x
As already noted the approach for resetting the notification state for an app on a device is changed for iOS5 an newer.
This works for me on iOS6:
Remove the app from the device
Set the device datetime two days or more ahead
Restart the device
Set the device datetime two days or more ahead
Restart the device
Install and run the app again
However this will only make the initial prompt appear again - it will not remove any other push state related stuff.
The plist:
/private/var/mobile/Library/RemoteNotification/Clients.plist
... contains the registered clients for push notifications. Removing your app's entry will cause the prompt to re-appear
Doing it programmatically seems to work for me everytime.
I have a build with the following line uncommented:
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
I run it every time I want to unregister from PN. You might have to end the app explicitly from the recents list and play around with the Notification Center in Settings app to get it right.
Also, the UI prompt asking the user to register for PN may not show up. Not sure if has been disabled in any of the recent iOS versions.
I agree with micmdk.. I had a development environment setup with Push Notifications and needed a way to reset my phone to look like an initial install… and only these precise steps worked for me… requires TWO reboots of Device:
From APPLE TECH DOC:
Resetting the Push Notifications Permissions Alert on iOS
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
As ianolito said, setting the date should work:
You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.
I noticed on my device (iPhone 4, iOS 6.1.2) setting the system clock a day forward or even a few days did not work for me. So I set the date forward a month and then it did work and my application showed the notifications prompt again.
Hope this helps for anyone, it can be kind of head aching!
I have wondered about this in the past and came to the conclusion that it was not actually a valid test case for my code. I don't think your application code can actually tell the difference between somebody declining notifications the first time or later disabling it from the iPhone notification settings. It is true that the user experience is different but that is hidden inside the call to registerForRemoteNotificationTypes.
Calling unregisterForRemoteNotifications does not completely remove the application from the notifications settings - though it does remove the contents of the settings for that application. So this still will not cause the dialog to be presented a second time to the user the next time the app runs (at least not on v3.1.3 that I am currently testing with). But as I say above you probably should not be worrying about that.
The same tech note as refered to in the accepted answer (TN2265 - Troubleshooting Push Notifications) has since been updated with a solution for iOS 5 and above.
In short: create a backup and restore from it every time.
On iOS 5 and later, reset the push notifications permissions alert by restoring the device from a backup (r. 11450187). Here are the steps to do this efficiently:
Use the Xcode Organizer to install your app on the device. The key is to install the app for the first time without running it.
Use iTunes to back up the device.
Run the app. The push notifications permissions alert will be presented.
When you want to reset the push notifications permissions alert, restore the device from the backup you created in the first step.
The Apple Tech Note also described you can restore the device to reset the Push Notification dialog.
It does not say that you can also use the option "General -> Reset -> Erase All Content And Settings" on the device itself (iOS 5.x).
I recently ran into the similar issue with react-native application. iPhone OS version was 13.1 I uninstalled the application and tried to install the app and noticed both location and notification permissions were not prompted.
On checking the settings, I could see my application was enabled for location(from previous installation) however there was no corresponding entry against the notification Tried uninstalling and rebooting without setting the time, it didn't work. Btw, I also tried to download the Appstore app, still same behavior.
The issue was resolved only after setting the device time.
In addition to the answer of ianolito.
Had the same issue with an app I downloaded a year ago and denying push notification initially. Now wanting push notifications back, these steps worked for me on iOS 7 beta. Not sure which point(s) triggered it exactly.
Close and delete the app.
Go to your iCloud settings and delete the app from the iCloud. Do this on all other devices where you have iCloud backup for apps enabled. After deactivating and deleting make a fresh backup. The app should not be listed any more under the backups. (This is maybe why the Technical Note from Apple described by ianolito stopped working in iOS 5, since iCloud was introduced in iOS 5 and many have iCloud backup for apps enabled.)
Go to your time settings and set the time more than 1 month ahead.
Switch the iPhone off (no reset).
Wait a minute, switch it on again and download the app again.
Start the app and I was presented the dialog again.
Enable app backup again, since it is still deactivated. Correct the time.
Thank god I did not have to "Erase All Content And Settings". Maybe it will help someone.
After hours of searching, and no luck with the suggestions above, this worked like to a charm for 3.x+
override func viewDidLoad() {
super.viewDidLoad()
requestAuthorization()
}
func requestAuthorization() {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
print("Access granted: \(granted.description)")
}
} else {
// Fallback on earlier versions
}
}