Post not yet marked as solved
NetServiceBrowser service always fails on iPhone if we create build from xcode 12.
// We are using following line in to start searching for sevices available on network
//
self.serviceBrowser.searchForServices(ofType: "_http._tcp.", inDomain: "local.")
It return following error dicitonary : ["NSNetServicesErrorCode": -72008, "NSNetServicesErrorDomain": 10]
I did not find -72008 in error codes for NSNetServicesErrorDomain.
It works as exepcted with previous vesions of Xcode. With Xcode 12 it works only on Simulator.
Post not yet marked as solved
Hi,
I'm trying to convert the following code snippet to Swift:
NSURL* pathURL = [NSURL fileURLWithPath:path];
BOOL success = [pathURL setResourceValue:tags forKey:NSURLTagNamesKey error:&outError];
However, it looks like the equivalent is now blocked in the API definition - in the Xcode 12 Swift API declaration .tagNames (and allValues) are get-only properties of URLResourceValues (according to StackOverflow, they were mutable in the past).
extension URL {
func setTagNames(_ tags: [String] ) {
var values = URLResourceValues()
values.tagNames = tags // Error here: Cannot assign to property: tagNames is get-only
try self.setResourceValues( values )
}
}
How can I set the tagNames?
Thanks,
Thomas
Post not yet marked as solved
My app user sometimes lost data in UserDefaults when our app launched.
All or part of the data is lost.
A device that has happened once is likely to happen again.
This bug seems to have been around since October 2020.
Not depend on any OS or hardware, and we haven’t been able to reproduce it yet.
Does anyone face the same bug?
Post not yet marked as solved
We upload videos form our application, the video upload starts in the foreground but the requirement is to support upload in the background as well. Followed the all steps that I gathered and understood reading in various article to support the upload in background as well. We have video content as data in the request - create an upload task which is delegate based. Then we write the whole request content into a file and pass to the upload task to upload.
Use background session configuration.
Now, my problem is sometimes I see the progress of upload going upto 100% then re-starting. On debugging further found that the timeout was happening on the server. And based on default timeout 60s it tries to re-start. How do I change the timeout value, setting the timeout interval on session does not seem to work. It works only it set to less than 60, trying to set to great than 60 doesn’t work.
I tried setting both timeoutIntervalForRequest
And timeoutIntervalForResource
Hello,
I am facing an issue with NSTask (Process), NSPipe (Pipe) and NSFileHandle (FileHandle).
I have an app that executes a child process (command line utility) and gets its output via Pipe instances set as standardI/O of Process instance.
I can observe two logic flows: Once the child process exits, -[Process readabilityHandler] gets called where I gather the $0.availableData.
Once the child process generates output (i.e. print() is executed by the child process), -[Process readabilityHandler] also gets called which makes sense. This is the case when exit() is not called by the child process (i.e. continuous execution).
However, when LLDB is detached, #2 is false, i.e. -[Process readabilityHandler] is not called.
Wrong behaviour also happens if I don't rely on readabilityHandler, but instead use Notification to receive changes in data availability. In such case, notification gets called continuously with empty data (even though child process does generate the output).
If I don't create Pipe instance for standardI/O of the Process, then readabilityHandler does get called, but with an empty data continuously.
I have created a DTS #756462540, since this doesn't make any sense.
Prerequisites*
app is not sandboxed
Big Sur 11.0.1 (20B29)
Xcode 12.3 (12C33)
Post not yet marked as solved
I have this basic get request when I call it in app I receive the error below. When I run it in playgrounds I get the same error
let url = DevAPI.BaseURL.submitted
guard let requestUrl = url else { fatalError() }
var request = URLRequest(url: requestUrl)
request.httpMethod = "GET"
let tokenString = UserDefaults.standard.string(forKey: "name") ?? ""
request.setValue(tokenString, forHTTPHeaderField: "x-access-token")
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if error != nil {
	 print("error :::", error)
	 } else {
print("no error", response)
}
}.resume()
This request is never making it to the server as in the logs I don't see anything show up when its made.
2020-12-23 12:29:37.817028-0500 Hammoq[63627:1122236] Task <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1> finished with error [303] Error Domain=kCFErrorDomainCFNetwork Code=303 "(null)" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey=<CFData 0x600003820f50 [0x7fff8002e8c0]>{length = 16, capacity = 16, bytes = 0x100201bb23b852d00000000000000000}, _kCFStreamErrorCodeKey=-2205, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>"
)}
error ::: Optional(Error Domain=kCFErrorDomainCFNetwork Code=303 "(null)" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey=<CFData 0x600003820f50 [0x7fff8002e8c0]>{length = 16, capacity = 16, bytes = 0x100201bb23b852d00000000000000000}, _kCFStreamErrorCodeKey=-2205, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>"
)})
If I use a different url from the same db I don't receive any errors. Another strange thing is that if I remove the header "x-access-token" I do not get the error and instead get response 403 which makes sense.
Post not yet marked as solved
Hi,
I'm trying to display a string containing the number of the largest given time unit for the time since as given date - i.e. "2 Months Ago" or "1 Week Ago".
DateComponentsFormatter appears to be a useful tool for this (the app targets iOS 10.2), however it doesn't seem to be formatting the number of weeks consistently.
This is how I'm setting up the formatter:
import Foundation
let day = 60*60*24
let formatter = DateComponentsFormatter()
formatter.calendar = Calendar.current
formatter.allowedUnits = [.hour, .day, .weekOfMonth, .month]
formatter.unitsStyle = .full
formatter.maximumUnitCount = 1
formatter.allowsFractionalUnits = false
formatter.zeroFormattingBehavior = .dropAll
For the given range, I would expect 8-13 to use "1 week", but this doesn't seem to be the case:
(0..40).forEach {
print("\($0): \(formatter.string(from: TimeInterval(day * $0))!)")
}
The actual output of this is:
0: 0 hours
1: 1 day
2: 2 days
3: 3 days
4: 4 days
5: 5 days
6: 6 days
7: 1 week
8: 2 weeks
9: 2 weeks
10: 2 weeks
11: 2 weeks
12: 2 weeks
13: 1 week
14: 2 weeks
15: 2 weeks
16: 2 weeks
17: 2 weeks
18: 2 weeks
19: 2 weeks
20: 2 weeks
21: 3 weeks
22: 3 weeks
23: 3 weeks
24: 3 weeks
25: 3 weeks
26: 3 weeks
27: 3 weeks
28: 4 weeks
29: 4 weeks
30: 4 weeks
31: 1 month
32: 1 month
33: 1 month
34: 1 month
35: 1 month
36: 1 month
37: 1 month
38: 1 month
39: 1 month
Could anyone point me in the right direction?
We define an event handler for OpenURL
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
And we handle it here:
(void)handleGetURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
// Handler type stuff
}
If I'm debugging in Xcode, I see a SIGCONT before the handler is called. When I continue from the SIGCONT, I enter the handler and everything is fine.
This causes automated tests to break, and is generally a pain in the you-know-where. Outside of Xcode it's fine.
How can I make it stop doing this? Is there some Xcode setting I've overlooked?
Post not yet marked as solved
I need the timezone of the device for a registration flow. It get's submitted to a backend server.
I setup a device and adjusted the TimeZone to San Francisco and tried the following.
swift
let identifier = TimeZone.current.identifier
The identifier is US/Pacific - looking nice to me.
But the server developer isn't happy about that. He expects the format America/Los_Angeles
I tried to get that fomat but failed, any solution to the issue?
Hi, thanks for adding markdown support in SwiftUI's Text with Xcode 13 and iOS 15! :)
Even formatting like strikethrough works!
Text("Hello ~~World~~")
So which specification is supported?? This goes apparently beyond Commonmark (as strikethrough is not part of Commonmark specification). Is it GitHub Flavored Markdown or even a different spec?
I'm trying the new markdown functionality in SwiftUI but it seems that trying to render markdown from an Attributed String inside a variable strips away any new lines.
This isn't the case when placing the raw markdown directly in the Text View's initialiser, as shown in the preview below.
Is this a bug or is there a way to retain new lines when using Attributed String? None of the options seem to help.
Thanks!
import SwiftUI
struct markdown_test: View {
let attStr = try! AttributedString(markdown: """
Hello **World** 👋🏻 \n\n\n\n
[This is a test](www.google.co.uk)
""")
var body: some View {
VStack(alignment: .leading) {
Text(attStr)
Text("Hello **World** 👋🏻\n[This is a test](www.google.co.uk)")
}
}
}
Post not yet marked as solved
Hi. I'm looking forward to using the new localization features as shown in 10221.
Is there a version of String(localized: ) that uses a key that is separate from the user-facing string? This is my preferred approach even with short strings but becomes really important for long strings like what you might see for an explanation in a table view footer.
And is there support for multi-line strings? Again, with a key?
Many thanks.
Post not yet marked as solved
Text in iOS 15 Beta 1 (Xcode 13 Beta 1) only handles markdown when string literal was passed to initializer.
struct MarkdownTest: View {
var text: String = "**Hello** *World*"
var body: some View {
VStack {
Text("**Hello** *World*") // will be rendered with markdown formatting
Text(text) // will NOT be rendered according to markdown
}
}
}
struct MarkdownTestPreviews: PreviewProvider {
static var previews: some View {
MarkdownTest()
}
}
Is this a known bug or do I have to create an entry in Feedback Assistant?
Post not yet marked as solved
private func applySnapshot() {
var snapshot = SnapshotDetails()
inputSections.forEach {
snapshot.appendSections([$0.section])}
inputSections.forEach { section in
snapshot.appendItems(section.items, toSection: section.section)
}
dataSource.apply(snapshot, animatingDifferences: false)
}
Log:
Assertion failure in NSArray<UICollectionViewUpdateItem *> * _Nonnull _UIDiffableDataSourceApplyInsertUpdate(NSObject<_UIDiffableDataSourceUpdate> *__strong _Nonnull, NSMutableOrderedSet *__strong _Nonnull, NSMutableOrderedSet *__strong _Nonnull, _UIDataSourceSnapshotter *__strong _Nonnull, BOOL)(), _UIDiffableDataSourceHelpers.m:654
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Update failed to insert requested items. Please file a bug on UIDiffableDataSource.
Post not yet marked as solved
I'm working on a project that uses URLSession with a client certificate authentication of HTTP requests.
In case of an authentication error, I need to know the exact cause of the SSL error. Unfortunately, the task callback error only returns a "Connection lost" status and does not contain any useful information in the underlying error.
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x1007cc780 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x109c08a50 [0x7fff8066ab70]>{length = 16, capacity = 16, bytes = 0x100201bb3369e6040000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E0F9E193-0CE8-4B42-9E46-72166BA54F2A>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <E0F9E193-0CE8-4B42-9E46-72166BA54F2A>.<1>"
)
In the console logs, I can see what caused the error.
For example, if the certificate is omitted:
Error: 4454414168:error:1000045c:SSL routines:OPENSSL_internal:TLSV1_CERTIFICATE_REQUIRED:/System/Volumes/Data/SWE/macOS/BuildRoots/e90674e518/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-351.100.9/ssl/tls_record.cc:594:SSL
Is there any way to retrieve that information without using a lower-level framework?
Hello, I'm having trouble saving the value of an NSURL object.
The code bellow is used in a c++ project, however, this issue shouldn't be exclusive to this scenario.
I want to use document picker, only to choose a file and get its url, which I would use on c++ side to read/write data. That I've managed to do successfully, by passing the url to c++ side by calling FileWasPicked(std::string) c++ method.
However, since document picker allows us to choose files only from public folders, I need to call start/stopAccessingSecurityScopedResource, and to call them I need to pass an NSURL object, that I get from the document picker. I call startAccessingSecurityScopedResource method before leaving didPickDocumentsAtURLs method, however I can't do that with the stopAccessingSecurityScopedResource.
I've tried to save the NSURL we get from document picker in a class variable @property NSURL *m_LastUsedURL;, however it's value changes after leaving didPickDocumentsAtURLs method. My guess, is that after leaving the before mention method, the value of the object that we save a pointer to gets deinitialized.
Passing the string value back from c++ and converting it to an NSURL object doesn't work either.
Is there any way to save NSURL object value in this case, or call the stopAccessingSecurityScopedResource method in a different manner?
I attach my current code:
@implementation DocumentPicker //In a DocumentPicker.mm file
//We call this method from c++, to open document picker
- (void)openDocumentPicker:(NSString*)pickerType //We pass the picker type from c++
{
//Find the current app window, and its view controller object
UIApplication* app = [UIApplication sharedApplication];
UIWindow* rootWindow = app.windows[0];
UIViewController* rootViewController = rootWindow.rootViewController;
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[pickerType] inMode:UIDocumentPickerModeOpen];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[rootViewController presentViewController:documentPicker animated:YES completion:nil];
}
//Callback, that gets called after user successfully chooses a file
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
{
//Start accessing file, that the user have picked
if ( [urls[0] startAccessingSecurityScopedResource] )
{
_m_LastUsedURL = urls[0];
//Pass the url and exit this method, to do actions in c++
GlobalCppClass->FileWasPicked(urls[0].absoluteString.UTF8String);
}
else
{
NSLog(@"startAccessingSecurityScopedResource failed");
}
}
//This would be called, after we finish reading the file in c++
-(void)stopAccesingFile
{
[_m_LastUsedURL stopAccessingSecurityScopedResource];
}
@end
Post not yet marked as solved
public protocol UploadDelegate: AnyObject {}
class NetworkManager: UploadDelegate {}
class A {
B().abc(uploadDelegate:NetworkManager() )
}
class B {
func abc (uploadDelegate: UploadDelegate) {
C().efg(uploadDelegate:uploadDelegate )
}
}
class C {
func efg (uploadDelegate: UploadDelegate) {
D().hij(uploadDelegate:uploadDelegate )
}
}
class D {
func hij (uploadDelegate: UploadDelegate) {
uploadDelegate.func()
}
}
Can we pass the protocol/delegate as a func parameter? If yes, I believe its a weak property.
Post not yet marked as solved
On a device, If I have a string, say "04:00 PM" and convert it to a date using a dateformatter:
let dateFormatter = DateFormatter()
dateFormatter.format = "h:mm a"
let d = dateFormatter.date(from: "04:00 PM")
If the device is set to a 24 hour time format, then d is nil. On a simulator, the result is a date. What I want to do is to somehow set up the simulator to return a nil under this circumstance. How do I do that?
Things I have tried: setting 24-hour format on the Mac, setting the region on the Mac, setting the region on the simulator, setting the locale in the simulator (maybe there's a locale setting I missed). For the Mac update settings, I reset the simulator afterward for the change to take effect.
So far nothing I've tried works.
The purpose of this is to allow automated tests to be able to detect these nils that will happen on actual devices.
Hello,
tldr; relaunch for background uploads isn't working as expected.
I'm testing my code on iPad OS 14.6 and XCode 12.5.1. Background app refresh is ON on my device for my app.
A background file upload is being setup with URLSession. The URL session is created as soon as the app starts up and not lazily created. See URL session configuration below.
I have followed the test instructions as outlined here: https://developer.apple.com/forums/thread/14855, specifically launching my app not via Xcode but from the home screen and adding an exit() call after the app enters the background in the AppDelegate callback method applicationDidEnterBackground. The file transfer is initiated before the app enters the background.
Here's the configuration code I'm using:
let configuration = URLSessionConfiguration.background(withIdentifier: <unique_identifier>)
configuration.sessionSendsLaunchEvents = true
configuration.sharedContainerIdentifier = <container group identifier>
configuration.isDiscretionary = false
configuration.timeoutIntervalForResource = 3600 * 24 * 2 // wait for 2 days before timing out connections
urlSession = URLSession(configuration: configuration, delegate:self, delegateQueue: nil)
The file in fact finishes uploading but the app isn't relaunched as one would expect. As soon as I re-open the app from the home screen, I get the requisite callbacks about the upload having completed properly.
In the past when I have tested my code, the method AppDelegate:handleEventsForBackgroundURLSession used to be called after the upload finishes. That appears to no longer be the case.
Any guidance/help will be hugely appreciated!
Thanks
Krishna
Hi, I have an app that has been online for a long time, but a very small number of users will respond with "-1009, the internet connection appears to be offline" error, but most users are normal, which may indicate that it is a device problem. The user's network uses 4G, and the user indicates that it is normal to connect to other apps.
In my opinion, if my App uses URLSession to get this Error, other apps should also get it, and all apps cannot make network requests, but it is not.
Currently I always ask users to restart the network or use wifi, but this may not solve this problem. Maybe the device has other network settings that can cause this problem? (The user did not use the flight mode)
Anyone know any solutions or know this problem?