i create a simple browser that can load a local file using UIWebview. At first,when i try to preview a html file, the uiwebview can load the source file and preview it. But after i minimize the app (the app enter background), and then open the app again, i've got this error :
Error Dict: {
NSNetServicesErrorCode = "-72000";
NSNetServicesErrorDomain = 10;
}
and after that, the uiwebview can not load the source file, when i log the error in (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error, it shows this message :
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x53d610 {NSErrorFailingURLStringKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSErrorFailingURLKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSLocalizedDescription=Could not connect to the server., NSUnderlyingError=0x5ccaa0 "Could not connect to the server."}
the app isn't crash, but the spinning indicator is never stop.
could somebody tell me what cause this case? and how to solved it?
Thank you :)
If you look inside the NSNetServices header, you'll see the following enum that explains each error:
typedef NS_ENUM(NSInteger, NSNetServicesError) {
/* An unknown error occured during resolution or publication.
*/
NSNetServicesUnknownError = -72000L,
/* An NSNetService with the same domain, type and name was already present when the publication request was made.
*/
NSNetServicesCollisionError = -72001L,
/* The NSNetService was not found when a resolution request was made.
*/
NSNetServicesNotFoundError = -72002L,
/* A publication or resolution request was sent to an NSNetService instance which was already published or a search request was made of an NSNetServiceBrowser instance which was already searching.
*/
NSNetServicesActivityInProgress = -72003L,
/* An required argument was not provided when initializing the NSNetService instance.
*/
NSNetServicesBadArgumentError = -72004L,
/* The operation being performed by the NSNetService or NSNetServiceBrowser instance was cancelled.
*/
NSNetServicesCancelledError = -72005L,
/* An invalid argument was provided when initializing the NSNetService instance or starting a search with an NSNetServiceBrowser instance.
*/
NSNetServicesInvalidError = -72006L,
/* Resolution of an NSNetService instance failed because the timeout was reached.
*/
NSNetServicesTimeoutError = -72007L,
};
You're getting a service collision error, which means that a net service with the same domain, type, and name are already publishing their service on your network.
In general, I always consult the header file for error codes. They're nearly always assigned by an enum value, and the enum usually has a much more descriptive name than the number used.
The problem seems to be the host you are trying to connect to: http://localhost:9898/local/[..]
Localhost on your computer is your computer, localhost on your ipad is your ipad - for testing use resolvable domain name or ip address.
Sergiu Todirascu's comment in the question solved it for me. The Mac Sandbox was causing this, I had to turn on Networking, in my case Incoming and Outgoing network checkboxes, in the entitlements tab. Creating an answer so it is more easy to see.
Related
I need to get the device IP of the WiFi interface.
According to several StackOverflow threads, we could assume that "en0" corresponds to the Wi-Fi interface name :
https://stackoverflow.com/a/30754194/12866797
However, this feels like some kind of convention, not a standard.
Is there any consistent/standard way to retrieve the WiFi interface or the device WiFi IP address, using the iOS SDK ?
It would be nice if the API is available starting from iOS 11 but I won't be picky.
My best attempt was to use NWPathMonitor (iOS 12+) and monitor network changes corresponding to WiFi interfaces (NWInterface.InterfaceType.wifi) :
- (void) MonitorWifiInterface
{
m_pathMonitor = nw_path_monitor_create_with_type(nw_interface_type_wifi);
nw_path_monitor_set_update_handler(m_pathMonitor, ^(nw_path_t _Nonnull path) {
NSLog(#"[NetInterfaceUtilies] Network path changed");
nw_path_enumerate_interfaces(path, ^ bool (nw_interface_t _Nonnull itf)
{
NSLog(#"[NetInterfaceUtilies] Name : %s , Index : %u", nw_interface_get_name(itf), nw_interface_get_index(itf));
return true; // In order to continue the enumeration
});
});
nw_path_monitor_start(m_pathMonitor);
}
But I am not happy with it for the following reasons :
NWPathMonitor is supposed to be used for monitoring network changes : I haven't managed to get network information whenever I wanted, but only when WiFi has been set on/off.
I only managed to get the network interface name. But I can combine this data with the network interfaces retrieved with getifaddrs() in order to deduce the correct interface and IP : it's a step forward ?
It's "only" available starting from iOS 12.
I am implementing a NEPacketTunnelProvider and loading it from my view controller using:
var vpnManager: NETunnelProviderManager = NETunnelProviderManager()
...
let providerProtocol = NETunnelProviderProtocol()
providerProtocol.providerBundleIdentifier = "AA.BB.CC"
providerProtocol.serverAddress = "<something>"
...
self.vpnManager.localizedDescription = "My app"
self.vpnManager.protocolConfiguration = providerProtocol
self.vpnManager.isEnabled = true
self.vpnManager.connection.startVPNTunnel()
Parts marked with "..." seemed irrelevant.
My understanding (although it's really not clear in the documentation) is that when I do this, and I have a target that was created as type "NetworkExtension" with BundleId AA.BB.CC, that the extension would be loaded and executed properly. So, my understanding is that startTunnel (from NEPacketTunnelProvider) will implicitly be called from the code block above.
I put a NSLog("STARTING TUNNEL!!!!!") right at the top of the startTunnel method, but am not sure where to see that. So far, I have viewed the logs in:
Console
Window > Devices and simulators > View device logs
None of these appear to show the logs from within the extension. The problem is that the extension seems to crash before I can attach to the running process, so I have the feeling I'm just "missing" that log because I can't attach quickly enough.
Short question
How can I attach to a running network extension quickly enough so that I don't miss an NSLog that is run immediately?
The logs from Network extensions do not go to Xcode console. to see the logs from Network extension you have to follow the bellow steps.
Open the console application.
Select your iOS device running the network extension you will see all the logs from your device.
Filter the logs by Network extension target name now you will see the logs only from your network extension.
How can I attach to a running network extension quickly enough?
What I have been doing to solve this problem was, put the thread on sleep right before log statement.
sleep(60)
It will give you enough time to attach the Network Extension process for debug.
I'm displaying RTSP streams from IP cameras. I want to replace this method avcodec_decode_video2 with VideoToolbox framework. I'm kinda new with video data processing so I'm a little lost...
I've tested both solutions from here and here, but I end up with a failure for this method VTDecompressionSessionDecodeFrame.
Error Domain=NSOSStatusErrorDomain Code=-12909 "The operation couldn’t be completed. (OSStatus error -12909.)" - -12909
I suspect this is coming from the session because if I call this VTDecompressionSessionCanAcceptFormatDescription right after creating the session, the result is NO.
Here is how is created my session :
VTDecompressionOutputCallbackRecord callback;
callback.decompressionOutputCallback = decompressionSessionDecodeFrameCallback;
callback.decompressionOutputRefCon = (__bridge void *)self;
NSDictionary *destinationImageBufferAttributes =[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],(id)kCVPixelBufferOpenGLESCompatibilityKey,[NSNumber numberWithInt:kCVPixelFormatType_32RGBA],(id)kCVPixelBufferPixelFormatTypeKey,nil];
OSStatus status = VTDecompressionSessionCreate(kCFAllocatorDefault, _formatDesc, NULL,
(__bridge CFDictionaryRef)destinationImageBufferAttributes,
&callback, &_decompressionSession);
I'm also not sure about the data to use. I have a choice between AVPacket.data, AVCodecContext.extradata, AVPacket.buf->data. Can anyone tell me which one should I use (maybe there is another one) ?
Thx in advance,
PS.: This is my first post ; let me know if it is not correctly presented/explained.
I've succeeded to get one successful status for this method. Turns out that I had indexes issues and the code I pasted had some bugs (at least, it wasn't adapted for my situation, specially for managing NALU types 1 and 5).
I have another issues because all the other calls returns a failure but I think I must post another question.
I am trying to send data between an App and a console app (using theos) on iOS 8.
I have tried:
Application:
CFMessagePortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"), &message_callback, NULL, NULL);
This works fine. NSLog(#"%#", port) returns:
<CFMessagePort 0x17018bef0 [0x198094f50]>{locked = Maybe, valid = Yes, remote = No, name = co.test, source = 0x0, callout = message_callback (0x1000e979c), context = <CFMessagePort context 0x0>}
However when trying to do the same thing on the console app:
CFMessagePortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"),
&message_callback, NULL, NULL);
I always get the error:
*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xc03, name = 'co.test'
Even though I am using the same com.apple.security.application-groups entitlement for both:
<key>com.apple.security.application-groups</key>
<array>
<string>co.test</string>
</array>
Can anyone shed any light - maybe the above is a terrible approach and I am missing an easier way to accomplish my goal?
My goal is to be able to pass a NSDictionary between an app running on SpringBoard and a daemon built with theos.
Note: I have no intention of distributing this app on the app store
Application: .......CFSTR("co.test")
Console App: ... CFSTR("co.test")
You need to append an additional string to the end of your application group identifier.
Apple:
Mach port names must begin with the application group identifier, followed by a period (.), followed by a name of your choosing.
For example, if your application group’s name is Z123456789.com.example.app-group, you might create a Mach port named Z123456789.com.example.app-group.Port_of_Kobe.
CFMessagePort and sandboxing
Another crash seems to occur if you create multiple Message Ports use the same Message Port Name. Perhaps from an app with the same bundle ID or some other situation in which there should only be a single Message Port and one is already running.
I notice it when I run one version of my macOS app from /Applications/, and another via Xcode.
*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xcd07, name = 'XXXYYYZZZZ.MyAppGroupName'
I am working on a iOS application and in this application I have send SMS internally without user involvement. And After googling I found a answer and I am using this code.
xpc_connection_t myconnection;
dispatch_queue_t queue = dispatch_queue_create("com.apple.chatkit.clientcomposeserver.xpc", DISPATCH_QUEUE_CONCURRENT);
myconnection = xpc_connection_create_mach_service("com.apple.chatkit.clientcomposeserver.xpc", queue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);
Now we have the XPC connection myconnection to the service of SMS sending. However, XPC configuration provides for creation of suspended connections —we need to take one more step for the activation.
xpc_connection_set_event_handler(myconnection, ^(xpc_object_t event){
xpc_type_t xtype = xpc_get_type(event);
if(XPC_TYPE_ERROR == xtype)
{
NSLog(#"XPC sandbox connection error: %s\n", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
}
// Always set an event handler. More on this later.
NSLog(#"Received an message event!");
});
xpc_connection_resume(myconnection);
The connection is activated. Right at this moment iOS 6 will display a message in the telephone log that this type of communication is forbidden. Now we need to generate a dictionary similar to xpc_dictionary with the data required for the message sending.
NSArray *receipements = [NSArray arrayWithObjects:#"+7 (90*) 000-00-00", nil];
NSData *ser_rec = [NSPropertyListSerialization dataWithPropertyList:receipements format:200 options:0 error:NULL];
xpc_object_t mydict = xpc_dictionary_create(0, 0, 0);
xpc_dictionary_set_int64(mydict, "message-type", 0);
xpc_dictionary_set_data(mydict, "recipients", [ser_rec bytes], [ser_rec length]);
xpc_dictionary_set_string(mydict, "text", "hello from your application!");
Little is left: send the message to the XPC port and make sure it is delivered.
xpc_connection_send_message(myconnection, mydict);
xpc_connection_send_barrier(myconnection, ^{
NSLog(#"Message has been successfully delievered");
});
But for using this code I have to add xpc.h header file, but xpc.h header is not found. So, suggest what actually I need to do.
You're using XPC in iOS, and the headers aren't going to be there for you by default. I got the /usr/include from https://github.com/realthunder/mac-headers -- it includes the xpc.h and related headers. I took the /xpc subdirectory from that and added only it to my project, because adding the full /usr/include interfered with my existing /usr/include and caused an architecture error on compile.
Even after adding the /xpc subdirectory and including xpc.h, I was unable to get the include paths to work due to nested include problems. Wasted lots of time trying to get the proper solution, then used the kludgy solution of editing xpc.h and base.h so that the nested xpc includes didn't use any path. So, #include <xpc/base.h> was edited to #include "base.h", etc.
That worked, the app builds and runs after that.
the library path its wrong use this ...
#include /usr/include/xpc/xpc.h