NSURLErrorDomain: -1003 - swift

I am getting an NSURLErrorDomain: -1003 while I am running my application in Xcode. I haven't seen this error on StackOverflow, any clue about this?
I am using Alamofire 4
func fetchAllPosts() {
Alamofire.request("http://www.somthing.com/wp-json/wp/v2/posts?categories_exclude=9").responseJSON
{ response in
if let data = response.data {
do {
let newPosts = try JSONDecoder().decode(Posts.self, from: data)
self.posts = newPosts.items
// Success
self.fetchAllPostsDidSucceed()
print("number of posts loaded: \(newPosts.items.count)")
}
[17655:2080758] [] nw_proxy_resolver_create_parsed_array PAC evaluation error: NSURLErrorDomain: -1003

-1003 is NSURLErrorCannotFindHost.
If you ever need to look up a NSURLError code in the future, press shift+command+o (the letter “oh”) in Xcode, search for NSURLError, unselect the “Swift” toggle in the upper right corner of the search box and choose/open NSURLError.h, and you’ll see all the codes that header file.
This particular error can be caused by any of a number of issues. For example, if this is a macOS app, you may want to go to your target settings, click on the “Capabilities” tag and make sure that “Outgoing Connections (Client)” is selected.

Related

SwiftUI Error: Update NavigationAuthority bound path tried to update multiple times per frame

I am getting the following debug message:
"Update NavigationAuthority bound path tried to update multiple times
per frame."
Does anyone know how to resolve the output message?
I can't find anything online about how to resolve this message, and it only started appearing when I added the following NavigationLink:
var body: some View {
getViewFor(state: viewmodel.state)
.navigationTitle("NYC schools")
.toolbar{
NavigationLink("Settings") {
SettingsView()
}
}
}

Shortcut/Action on Siri Watch Face with independent WatchOS app

I'm relatively new to making apps, and even newer to independent watch apps. As training, I'm making a watch app that I can use to log my water intake throughout the day. I've created a new intent definition file (see image 1) on which I've checked the marks for all the target memberships (the app, the WatchKit app, and the WatchKit extension). Furthermore, the target membership class is a public intent for the WatchKit extension.
When logging my water I execute the following code:
let intent = INManager.intent(drink: item)
INManager.donateShortcuts(withIntent: intent)
and my IntentManager looks like this:
import Foundation
import Intents
class IntentManager {
func intent(drink: Drink) -> LogDrinkIntent {
let intent = LogDrinkIntent()
intent.uuid = drink.id.uuidString
intent.name = drink.name
intent.emoji = drink.emoji
return intent
}
func donateShortcuts(withIntent intent:INIntent) {
var relevantShortcuts: [INRelevantShortcut] = []
if let relevantShortcut = defaultRelevantShortcut(withIntent: intent) {
relevantShortcuts.append(relevantShortcut)
}
INRelevantShortcutStore.default.setRelevantShortcuts(relevantShortcuts) { (error) in
if let error = error {
print("Failed to set relevant shortcuts: \(error))")
} else {
print("Relevant shortcuts set.")
}
}
}
private func defaultRelevantShortcut(withIntent intent: INIntent) -> INRelevantShortcut? {
if let shortcut = INShortcut(intent: intent) {
let relevantShortcut = INRelevantShortcut(shortcut: shortcut)
relevantShortcut.shortcutRole = .action
let template = INDefaultCardTemplate(title: "Log Drink")
relevantShortcut.watchTemplate = template
print("Returning relevant shortcut.")
return relevantShortcut
}
return nil
}
}
When logging a drink the confirmation Returning relevant shortcut. and Relevant shortcuts set. are printed. However, the Siri watch face doesn't update to include a link to my action. I got the code for the IntentManager from this Medium article.
I really appreciate your time and help. I've had a hard time trying to find any details about this functionality and Apple's documentation is imo inferior. Thank you! If you need more details or such, feel free to ask.
Image 1
Let's saddle the horse from behind: Generally speaking, you want to make use of Soup Chef. Now you can categorize Siri suggestions into two sub-groups, being donated shortcuts and relevant shortcuts.
In your specific example of a "water intake" logging app, you should work with donating the INIntent to INIteraction. The reason for that is quite simple: Your suggestion is due to an action a user has committed within your application, not based upon plainly relevance, thus your passage about INRelevantShortcutStore isn't necessary and/or should be replaced with INInteraction.
To re-phrase myself: The issue is that you parse INRelevantShortcutStore as a donation, see here:
func donateShortcuts(withIntent intent:INIntent) {
var relevantShortcuts: [INRelevantShortcut] = []
if let relevantShortcut = defaultRelevantShortcut(withIntent: intent) {
relevantShortcuts.append(relevantShortcut)
}
INRelevantShortcutStore.default.setRelevantShortcuts(relevantShortcuts) { (error) in
if let error = error {
print("Failed to set relevant shortcuts: \(error))")
} else {
print("Relevant shortcuts set.")
}
}
}
... as explained above, that is not the correct usage for INIntent in your specific example.
I highly suggest to read through Soup Chef in general as well as specifically donating shortcuts to Siri (what you want to do!). The documentation is very detailed and explanative!

How to reload content blockers while they are active?

I have an app with several content blockers extension. Their configuration is fine and they act as they are supposed to.
However I need to call reloadContentBlocker(withIdentifier:completionHandler:) from SFContentBlockerManager when I've updated the filter lists for example.
Here is a code example (with NSLog for timestamp purposes below):
func reload(_ callback: #escaping((Bool) -> Void)) {
NSLog("Reload start")
let contentBlockersIdentifiers = ["com.aaa.bbb.ContentBlocker.ExampleA", "com.aaa.bbb.ContentBlocker.ExampleB", "com.aaa.bbb.ContentBlocker.ExampleC", "com.aaa.bbb.ContentBlocker.ExampleD", "com.aaa.bbb.ContentBlocker.ExampleE"]
var failures: [String] = [String]()
let dispatchSemaphore = DispatchSemaphore(value: 0)
let dispatchQueue = DispatchQueue(label: "reload-queue", qos: .userInitiated)
dispatchQueue.async {
NSLog("Reloading content blockers")
for aContentBlockerIdentifier in contentBlockersIdentifiers {
NSLog("Reloading '\(aContentBlockerIdentifier)'")
SFContentBlockerManager.reloadContentBlocker(withIdentifier: aContentBlockerIdentifier) { (error) in
if let error = error?.localizedDescription {
NSLog("Failed to reload '\(aContentBlockerIdentifier)': \(error)")
failures.append(aContentBlockerIdentifier)
} else {
NSLog("Successfully reloaded '\(aContentBlockerIdentifier)'")
}
dispatchSemaphore.signal()
}
dispatchSemaphore.wait()
}
callback(failures.isEmpty)
NSLog("Reload end")
}
}
This is what is prints:
16:41:43.391543+0200 Reload start
16:41:43.392003+0200 Reloading content blockers
16:41:43.392125+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleA'
16:41:50.010102+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleA'
16:41:50.010299+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleB'
16:41:50.351554+0200 Failed to reload 'com.aaa.bbb.ContentBlocker.ExampleB': The operation couldn’t be completed. (WKErrorDomain error 2.)
16:41:50.351676+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleC'
16:41:50.493327+0200 Failed to reload 'com.aaa.bbb.ContentBlocker.ExampleC': The operation couldn’t be completed. (WKErrorDomain error 2.)
16:41:50.493429+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleD'
16:41:50.631578+0200 Failed to reload 'com.aaa.bbb.ContentBlocker.ExampleD': The operation couldn’t be completed. (WKErrorDomain error 2.)
16:41:50.631681+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleE'
16:41:50.718466+0200 Failed to reload 'com.aaa.bbb.ContentBlocker.ExampleE': The operation couldn’t be completed. (WKErrorDomain error 2.)
16:41:50.718600+0200 Reload end
It apparently tries to do the reload one content blocker after another (as I wanted to do with the DispatchSemaphore). However after the first one succeeded the following are failures.
Now let's go and disable the Content Blockers in Setting App > Safari > Content Blockers and try again:
16:55:05.699392+0200 Reload start
16:55:05.700171+0200 Reloading content blockers
16:55:05.700564+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleA'
16:55:05.714444+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleB'
16:55:05.714909+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleB'
16:55:05.723056+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleB'
16:55:05.723343+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleC'
16:55:05.730565+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleC'
16:55:05.730775+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleD'
16:55:05.735733+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleD'
16:55:05.735841+0200 Reloading 'com.aaa.bbb.ContentBlocker.ExampleE'
16:55:05.740758+0200 Successfully reloaded 'com.aaa.bbb.ContentBlocker.ExampleE'
16:55:05.740865+0200 Reload end
Surprise... it works. But I would rather not ask my users to :
go manually disable the Content Blockers in the Settings
perform the update manually (while waiting to develop automatic refresh)
go manually re-enable the Content Blockers in the Settings
I'm missing something somewhere (maybe a thread issue). Hopefully someone will be able to help!
Most likely, it means that you have rules that contains incorrect syntax or rules file have more the 50 000 rules.
Also the error can happened when you fill returningItems with nil context.completeRequest(returningItems: nil, completionHandler: nil) in your NSExtensionRequestHandling where context is NSExtensionContext

TWTRComposer() Application crashes when I try to open Composer

I am having an issue with TWTRComposer. I installed TwitterKit using pods followed all other instructions i.e. updated info.Plist , AppDelegate and so on. I am using Swift. When I call the func that handles the code the app crashes here, sample code below. On the line where composer.show(from: self.navigationController!) the error message is Thread 1:EXC_BREAKPOINT(code=1, subcode=0x1024ff1ac) I have no clue what this means. Any explanation and help is appreciated.
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self.navigationController!) { (result) in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}

iOS 10 app crashes when trying to save image to photo library

I'm trying to save an image to the photo library in Swift 3 (I'm working with Xcode 8).
ViewController Code:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
When I run the application, and click on the button to take the screenshot (converting it to image, ..., that's all working perfectly), the app asks for permission to access the photo library, I tap the "OK" button, and then the app crashes. The image is not saved in the photo library.
The only clue I get from Xcode is the following:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access file: 1} with userInfo dictionary {
reason = "Failed to access file: 1";
}
2016-09-28 11:24:27.216433 Ajax Kids[4143:1545362] [Migration] Unexpected error opening persistent store <private>, cannot attempt migration <private>)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store <private>. Requires update via assetsd (256: <private>)
Does anyone have any idea how to fix this?
Thanks in advance!
UPDATE
Sharing the image on Social Media works fine, so the problem is specified to saving the image in the photo library.
Add new records in your new InfoPlist.strings file.
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME)</string>
UPD: iOS 11 key
On iOS 11, there is a new property called NSPhotoLibraryAddUsageDescription, similar to NSPhotoLibraryUsageDescription. See https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
Try to force request permissions like this:
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
//do things
}
}
do not forget import Photos. Hope this helps.
I found the culprit in my particular case. We are using Leanplum for analytics and push notifications. The Leanplum.syncResourcesAsync method was causing the opening of the photo library to crash. It took a couple of days to find as I wasn't aware Leanplum was doing anything to hook into a user's photo library... which in itself is concerning.
We weren't using the functionality this particular method brings, so were able to just remove the method call and the photo library stopped crashing.