Swift Admob does not show Ad - swift

I am trying to implement an Google AdMob banner ad in my swift application and it simply doesn't show up. I extended the plist to the following.
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-???</string>
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
...
</array>
Edited AppDelegate.swift...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GADMobileAds.sharedInstance().start(completionHandler: nil)
return true
}
And implemented the banner in my ViewController...
import UIKit
import GoogleMobileAds
class ViewController: UIViewController {
...
private let banner: GADBannerView = {
let banner = GADBannerView()
banner.adUnitID = "ca-app-pub-???/???"
banner.load(GADRequest())
banner.backgroundColor = .secondarySystemBackground
return banner
}()
override func viewDidLoad() {
super.viewDidLoad()
banner.rootViewController = self
view.addSubview(banner)
...
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
banner.frame = CGRect(x: 0, y: view.frame.size.height-50, width: view.frame.size.width, height: 50)
}
...
}
This code causes the following error and the banner doesn't show up:
2022-02-18 19:12:45.453836+0100 TestApp[70970:5163578] <Google> To get test ads on this device, set:
Objective-C
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = #[ GADSimulatorID ];
Swift
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ GADSimulatorID ]
2022-02-18 19:12:45.464778+0100 TestApp[70970:5163713] - <Google>[I-ACS025031] AdMob App ID changed. Original, new: (nil), ca-app-pub-???
2022-02-18 19:12:45.520401+0100 TestApp[70970:5163714] [Client] Synchronous remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.520411+0100 TestApp[70970:5163713] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.520643+0100 TestApp[70970:5163714] [Client] Synchronous remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.520657+0100 TestApp[70970:5163718] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.520824+0100 TestApp[70970:5163714] [Client] Synchronous remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.520939+0100 TestApp[70970:5163718] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.522075+0100 TestApp[70970:5163718] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.522129+0100 TestApp[70970:5163718] [Client] Updating selectors after delegate addition failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}
2022-02-18 19:12:45.522084+0100 TestApp[70970:5163714] - <Google>[I-ACS023007] Analytics v.81200000 started
2022-02-18 19:12:45.522389+0100 TestApp[70970:5163714] - <Google>[I-ACS023008] To enable debug logging set the following application argument: -APMAnalyticsDebugEnabled (see xxx)
2022-02-18 19:12:45.552092+0100 TestApp[70970:5163578] Writing analzed variants.
2022-02-18 19:12:45.588346+0100 TestApp[70970:5163718] - <Google>[I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-02-18 19:12:45.616229+0100 TestApp[70970:5163578] Writing analzed variants.
2022-02-18 19:12:45.636629+0100 TestApp[70970:5163578] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000178d2c0> F8BB1C28-BAE8-???
2022-02-18 19:12:45.692429+0100 TestApp[70970:5163721] - <Google>[I-ACS023012] Analytics collection enabled
2022-02-18 19:12:45.912031+0100 TestApp[70970:5163717] [boringssl] boringssl_metrics_log_metric_block_invoke(144) Failed to log metrics

Initialisation of GADBannerView is might be wrong in your project as they need adSize as frame
this working fine on my application , I have working production ads,
class HomePageViewController: UIViewController {
private var adMobBannerView1: GADBannerView!
private var adMobBannerView2: GADBannerView!
override func viewDidLoad() {
setupAdMobBannerAD()
}
private func setupAdMobBannerAD() {
let sizeForBanner = GADAdSizeFromCGSize(.init(width: view.frame.width, height: 50))
// here you need to intilise GADBannerView with adSize of GADAdSizeFromCGSize
adMobBannerView1 = GADBannerView(adSize: sizeForBanner)
adMobBannerView2 = GADBannerView(adSize: sizeForBanner)
adMobBannerView1.translatesAutoresizingMaskIntoConstraints = false
adMobBannerView2.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adMobBannerView1)
view.addSubview(adMobBannerView2)
adMobBannerView1.delegate = self
adMobBannerView2.delegate = self
NSLayoutConstraint.activate([
adMobBannerView1.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
adMobBannerView1.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
adMobBannerView2.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor , constant: 20 ),
adMobBannerView2.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
])
adMobBannerView2.adUnitID = Constants.secondAdBannerString
// I have saved my bannerID String in another class don't worry about this
adMobBannerView2.rootViewController = self
adMobBannerView1.adUnitID = Constants.firstAdBannerString
// I have saved my bannerID String in another class don't worry about this
adMobBannerView1.rootViewController = self
adMobBannerView2.load(GADRequest())
adMobBannerView1.load(GADRequest())
}
}
you want to add some delegate to get informed by admob if there is any problem with your ad account or something
extension HomePageViewController : GADBannerViewDelegate {
func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
print("admob banner ad failecd to show going to represent adolony \n")
if DataModel.shared.showAdmobAd {
self.requestAdColonyBanners()
// any alternative method can be performed here as we this function will be called by admob incase you didn't get banner ad , in my case I m launching ads form another ad service called adcolony
}
}
}

Related

How do I connect TypeORM to MongoDB? I receive errors while trying to connect

I have a NestJS and TypeORM project going. I am trying to connect it to my MongoDB database.
Here is the list of my MongoDB projects from the https://cloud.mongodb.com/ website:
The only name I can see for these is "cluster0" like here:
And then in my .env file I have:
MONGODB_CONNECTION_STRING=mongodb+srv://roland:<myActualPassword>#cluster0.7llne.mongodb.net/?retryWrites=true&w=majority
MONGODB_DATABASE=cluster0
and then the entrypoint to the application:
import { Module } from "#nestjs/common";
import { SchedulingController } from "./scheduling.controller";
import { SchedulingService } from "./scheduling.service";
import { ConfigModule } from "#nestjs/config";
import { TypeOrmModule } from "#nestjs/typeorm";
import { Meeting } from "./db/Meeting.entity";
#Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
type: "mongodb",
url: process.env.MONGODB_CONNECTION_STRING,
database: process.env.MONGODB_DATABASE,
entities: [__dirname + "/**/*.entity{.ts,.js}"],
ssl: true,
useUnifiedTopology: true,
useNewUrlParser: true,
}),
TypeOrmModule.forFeature([Meeting]),
],
controllers: [SchedulingController],
providers: [SchedulingService],
})
export class SchedulingModule {}
But I see these errors:
[Nest] 16760 - 2022-05-16, 10:05:09 p.m. ERROR [TypeOrmModule] Unable to connect to the database. Retrying (5)...
MongoServerSelectionError: read ECONNRESET
at Timeout._onTimeout (C:\Users\jenfr\Documents\Code2022\TakeHomeTests\bluescape\bluescape\node_modules\mongodb\src\sdam\topology.ts:594:30)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
[Nest] 16760 - 2022-05-16, 10:05:42 p.m. ERROR [TypeOrmModule] Unable to connect to the database. Retrying (6)...
MongoServerSelectionError: read ECONNRESET
at Timeout._onTimeout (C:\Users\jenfr\Documents\Code2022\TakeHomeTests\bluescape\bluescape\node_modules\mongodb\src\sdam\topology.ts:594:30)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
[Nest] 16760 - 2022-05-16, 10:06:15 p.m. ERROR [TypeOrmModule] Unable to connect to the database. Retrying (7)...
MongoServerSelectionError: read ECONNRESET
at Timeout._onTimeout (C:\Users\jenfr\Documents\Code2022\TakeHomeTests\bluescape\bluescape\node_modules\mongodb\src\sdam\topology.ts:594:30)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
edit: I'm fairly certain my MONGODB_CONNECTION_STRING and MONGODB_DATABASE are set properly, anyone know what else could be causing these errors?
Try to set useUnifiedTopology=false.

Spring Cloud Gateway 500 when an instance is down

I have a Spring Cloud Gateway (eureka client) app that uses Spring Cloud Load Balancer (Spring Cloud version: Hoxton.SR6) and I have an instance of a spring boot app (spring boot 2.3 with enabled graceful shutdown, (eureka client).
When I shutdown a spring boot service and perform a request through the gateway then the gateway throws 500 error (connection refused), instead of 503. 503 appears after a 1-2 minutes.
Can anyone clarify if it is an expected behavior?
It seems that the problem comes from eureka-client (1.9.21 version in my case)
AtomicReference<Applications> localRegionApps isn't frequently updated
Thanks!
UPDATE:
I decided to check deeper this 500 error. The result is that my system (ubuntu) gives this error if the port is not used:
curl -v localhost:9722
Rebuilt URL to: localhost:9722/
Trying 127.0.0.1...
TCP_NODELAY set
connect to 127.0.0.1 port 9722 failed: Connection refused
Failed to connect to localhost port 9722: Connection refused
Closing connection 0
So I put in my application.yml:
spring:
cloud:
gateway:
routes:
- id: my_route
uri: http://localhost:9722/
Then when my request is routed to my_route and none of apps uses 9722 then I get an error:
io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:9722
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP GET "/internal/mail/internal/health-check" [ExceptionHandlingWebHandler]
Stack trace:
Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124)
at io.netty.channel.unix.Socket.finishConnect(Socket.java:251)
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:672)
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:649)
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:529)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:465)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
It seems to be an unexpected exception, since it isn't possible to handle it using a circuit breaker or any gateway filter.
Is it possible to handle this error correctly? I would like to return 503 in this case
One of the easiest ways to map particular exception to particular HTTP status code is providing a custom bean of type org.springframework.boot.web.reactive.error.ErrorAttributes. Here is an example:
#Bean
public ErrorAttributes errorAttributes() {
return new CustomErrorAttributes(httpStatusExceptionTypeMapper);
}
public class CustomErrorAttributes extends DefaultErrorAttributes {
#Override
public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
Map<String, Object> attributes = super.getErrorAttributes(request, options);
Throwable error = getError(request);
MergedAnnotation<ResponseStatus> responseStatusAnnotation = MergedAnnotations
.from(error.getClass(), MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).get(ResponseStatus.class);
HttpStatus errorStatus = determineHttpStatus(error, responseStatusAnnotation);
attributes.put("status", errorStatus.value());
return attributes;
}
private HttpStatus determineHttpStatus(Throwable error, MergedAnnotation<ResponseStatus> responseStatusAnnotation) {
if (error instanceof ResponseStatusException) {
return ((ResponseStatusException) error).getStatus();
}
return responseStatusAnnotation.getValue("code", HttpStatus.class).orElseGet(() -> {
if (error instanceof java.net.ConnectException) {
return HttpStatus.SERVICE_UNAVAILABLE;
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
}
}
hava a try to define your custom ErrorWebExceptionHandler.
see:
org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler
org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler
You should use Cloud Circuit Breaker.
For that:
Declare corresponding starter in your pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
Declare circuit breaker in application.yaml
spring:
cloud:
gateway:
routes:
- id: my_route
uri: http://localhost:9722/
filters:
- name: CircuitBreaker
args:
name: myCircuitBreaker
fallbackUri: forward:/inCaseOfFailureUseThis
Declare the endpoint which will be called in the case of failure (a connection error, for example)
#RequestMapping("/inCaseOfFailureUseThis")
public Mono<ResponseEntity<String>> inCaseOfFailureUseThis() {
return Mono.just(ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("body for service failure case"));
}

WKWebView turns black when "Open Link" pressed after long press a link

I'm programming in swift and run into an error that my WKWebView turns black after "open link" or "add to photos" in safari.
So I got my WebView and everything works fine. But when I long press on (e.g. an image) the apple-dropdown-menu opens with "open link", "add to reading list", ..., "add to photos". Now when I just close the dropdown menu again and go to home screen and open the app again, the webview turns black. The console says it's loading and didFinish, but I can't see anything. Anyone knows possible issues?
When I pressed "open link" on the dropdown-menu safari opens with that link. But when I move back to my app, the screen turns black. Here is the code of the console after opening my app again.
--------------------- SCENEDELEGATE sceneWillEnterForeground ---------------------
2020-08-13 13:48:38.560642+0200 GMP[1817:418564] [ProcessSuspension] 0x282f2aa00 - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because the application is already in the background
2020-08-13 13:48:38.561286+0200 GMP[1817:418564] [ProcessSuspension] 0x282f2aa00 - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because the application is already in the background
--------------------- SCENEDELEGATE sceneDidBecomeActive ---------------------
currentUrl: https://myWebPage.com/
loadUrl(link: https://myWebPage.com/)
didStartProvisionalNavigation webView(_:didStartProvisionalNavigation:)
didCommit webView(_:didCommit:)
2020-08-13 13:48:39.341814+0200 GMP[1817:418614] [assertion] Error acquiring assertion: <NSError: 0x282ff4db0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x102c8f640; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.341902+0200 GMP[1817:418614] [ProcessSuspension] 0x1094e0438 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1819
2020-08-13 13:48:39.342137+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e0438 - ProcessAssertion::processAssertionWasInvalidated()
2020-08-13 13:48:39.342917+0200 GMP[1817:418614] [assertion] Error acquiring assertion: <NSError: 0x282ff4de0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x1040ae040; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.342998+0200 GMP[1817:418614] [ProcessSuspension] 0x1094e0460 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1817
2020-08-13 13:48:39.343085+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e0460 - ProcessAssertion::processAssertionWasInvalidated()
2020-08-13 13:48:39.343851+0200 GMP[1817:418614] [assertion] Error acquiring assertion: <NSError: 0x282ffcea0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x10415ddb0; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.343954+0200 GMP[1817:418614] [ProcessSuspension] 0x1094e0488 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1818
2020-08-13 13:48:39.344028+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e0488 - ProcessAssertion::processAssertionWasInvalidated()
2020-08-13 13:48:39.905526+0200 GMP[1817:418815] [assertion] Error acquiring assertion: <NSError: 0x282f3b690; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x10414ea00; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.905574+0200 GMP[1817:418815] [ProcessSuspension] 0x1094e20a8 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1819
2020-08-13 13:48:39.905602+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e20a8 - ProcessAssertion::processAssertionWasInvalidated()
2020-08-13 13:48:39.906163+0200 GMP[1817:418815] [assertion] Error acquiring assertion: <NSError: 0x282f39590; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x102d4d0c0; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.906196+0200 GMP[1817:418815] [ProcessSuspension] 0x1094e20d0 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1817
2020-08-13 13:48:39.906218+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e20d0 - ProcessAssertion::processAssertionWasInvalidated()
2020-08-13 13:48:39.906769+0200 GMP[1817:418815] [assertion] Error acquiring assertion: <NSError: 0x282f391d0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x102c66420; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
}
}
2020-08-13 13:48:39.906803+0200 GMP[1817:418815] [ProcessSuspension] 0x1094e20f8 - ProcessAssertion() PID 1817 Unable to acquire assertion for process with PID 1818
2020-08-13 13:48:39.906828+0200 GMP[1817:418564] [ProcessSuspension] 0x1094e20f8 - ProcessAssertion::processAssertionWasInvalidated()
didFinish webView(_:didFinish:)
didSet currentUrl = https://myWebPage.com/

URLSession GET request fails on eduroam

I am running into a strange error with Swift 3.
I am trying to request a URL in a Swift application but the request always fails. I have tried opening different URLs and opening the URLs in my browser, where the requests work.
I am using the following code snippet I found online:
let url = URL(string: "https://httpbin.org/ip")
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard error == nil else {
print(error!)
return
}
guard let data = data else {
print("Data is empty")
return
}
let json = try! JSONSerialization.jsonObject(with: data, options: [])
print(json)
}
task.resume()
This is the error my program is producing
2018-04-30 11:11:08.318299+0200 TokenList[2765:48745] PAC result block not invoked
2018-04-30 11:11:08.318361+0200 TokenList[2765:48745] [] nw_proxy_resolver_create_parsed_array PAC evaluation error: kCFErrorDomainCFNetwork: 308
2018-04-30 11:11:08.318380+0200 TokenList[2765:48737] Received XPC error Connection invalid for message type 3 kCFNetworkAgentXPCMessageTypePACQuery
2018-04-30 11:11:08.318880+0200 TokenList[2765:48745] dnssd_clientstub ConnectToServer: connect()-> No of tries: 1
2018-04-30 11:11:09.319675+0200 TokenList[2765:48745] dnssd_clientstub ConnectToServer: connect()-> No of tries: 2
2018-04-30 11:11:10.322336+0200 TokenList[2765:48745] dnssd_clientstub ConnectToServer: connect()-> No of tries: 3
2018-04-30 11:11:11.323967+0200 TokenList[2765:48745] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:10 Err:-1 Errno:1 Operation not permitted
2018-04-30 11:11:11.324569+0200 TokenList[2765:48745] [] nw_resolver_create_dns_service_locked DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)
2018-04-30 11:11:11.325512+0200 TokenList[2765:48745] TIC TCP Conn Failed [1:0x6000001630c0]: 10:-72000 Err(-65563)
2018-04-30 11:11:11.326603+0200 TokenList[2765:48737] Task <F194834F-65B5-4E6D-B088-B4947A029818>.<1> HTTP load failed (error code: -1003 [10:-72000])
2018-04-30 11:11:11.326897+0200 TokenList[2765:48737] Task <F194834F-65B5-4E6D-B088-B4947A029818>.<1> finished with error - code: -1003
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={NSUnderlyingError=0x600000442250 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, NSErrorFailingURLStringKey=https://httpbin.org/ip, NSErrorFailingURLKey=https://httpbin.org/ip, _kCFStreamErrorDomainKey=10, _kCFStreamErrorCodeKey=-72000, NSLocalizedDescription=A server with the specified hostname could not be found.}
I am suspecting this issue could be caused by me being on eduroam, the heavily gated university wifi. On the other hand other requests (from other macOS) applications are working fine.
Additionally there should be no issues with misconfiguration on the Mac is it is brand new and only homebrew and a few programs have been installed.
I am looking forward to any pointers you might have and would like to thank you in advance.

Acra doesn't send JSON request to my own server

I'm trying to implement ACRA into my Android Application. I'm trying to send crash report with JSON via POST. To do that I have configured ACRA and created the following class:
import android.app.Application;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.*;
import org.acra.sender.HttpSender;
#ReportsCrashes(
formUri = "https://mySite/myFolder/report.php",
reportType = HttpSender.Type.JSON,
httpMethod = HttpSender.Method.POST,
formUriBasicAuthLogin = "username",
formUriBasicAuthPassword = "password",
formKey = "", // This is required for backward compatibility but not used
customReportContent = {
ReportField.APP_VERSION_CODE,
ReportField.APP_VERSION_NAME,
ReportField.ANDROID_VERSION,
ReportField.PACKAGE_NAME,
ReportField.REPORT_ID,
ReportField.BUILD,
ReportField.STACK_TRACE
},
mode = ReportingInteractionMode.SILENT)
public class Crazy extends Application {
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
I am currently doing my application crash voluntarily, to test ACRA. When the app crash, the logcat show me that error:
09-18 14:25:53.943 20309-20324/myPackage I/ACRA﹕ Sending file 1411042794000-approved.stacktrace
09-18 14:25:53.958 20309-20309/myPackage D/OpenGLRenderer﹕ Enabling debug mode 0
09-18 14:25:53.968 20309-20324/myPackage D/ACRA﹕ Connect to https://mySite/myFolder/report.php
09-18 14:25:53.983 20309-20312/myPackage D/dalvikvm﹕ GC_CONCURRENT freed 414K, 15% free 9757K/11399K, paused 13ms+13ms, total 58ms
09-18 14:25:54.008 20309-20324/myPackage D/ACRA﹕ Sending request to https://mySite/myFolder/report.php
09-18 14:25:54.153 20309-20324/myPackage E/ACRA﹕ Failed to send crash report for 1411042794000-approved.stacktrace
org.acra.sender.ReportSenderException: Error while sending JSON report via Http POST
at org.acra.sender.HttpSender.send(HttpSender.java:228)
at org.acra.SendWorker.sendCrashReport(SendWorker.java:179)
at org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)
at org.acra.SendWorker.run(SendWorker.java:77)
Caused by: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
at org.acra.util.HttpRequest.send(HttpRequest.java:152)
at org.acra.sender.HttpSender.send(HttpSender.java:225)
            at org.acra.SendWorker.sendCrashReport(SendWorker.java:179)
            at org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)
            at org.acra.SendWorker.run(SendWorker.java:77)
09-18 14:25:54.153 20309-20324/myPackage D/ACRA﹕ #checkAndSendReports - finish
How can I solve that problem?
Tanks!
The simple solution is to send via HTTP instead of HTTPS.
But I think the real issue is that you have not installed the SSL cert of your server correctly. It looks like it is missing some of it's intermediate certificates. See Android SSL - No Peer Certificate