Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从iPhone发送udp广播。仅在调试器模式下工作。安装相同IPA时不工作_Ios_Networking_Broadcast_Gcdasyncudpsocket - Fatal编程技术网

Ios 从iPhone发送udp广播。仅在调试器模式下工作。安装相同IPA时不工作

Ios 从iPhone发送udp广播。仅在调试器模式下工作。安装相同IPA时不工作,ios,networking,broadcast,gcdasyncudpsocket,Ios,Networking,Broadcast,Gcdasyncudpsocket,使用GCDAsyncudpSocket从广播地址发送udp数据包和侦听数据。 当我在mac OS X Yosmite(Xcode->device ipad air 8.2)的调试器模式下运行应用程序时,它工作正常。在设备中安装IPA时,它不工作 以下是我使用过的代码: ****发送**** GCDAsyncUdpSocket * udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch

使用GCDAsyncudpSocket从广播地址发送udp数据包和侦听数据。
当我在mac OS X Yosmite(Xcode->device ipad air 8.2)的调试器模式下运行应用程序时,它工作正常。在设备中安装IPA时,它不工作

以下是我使用过的代码: ****发送****

 GCDAsyncUdpSocket * udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
    NSError *error = nil;

NSTimeInterval timeout= 1;
// Send the broadcast request, ie "Any upnp devices out there?"
char request[35];
request[0] = (Byte) 0xAA;
request[1] = (Byte) 0xAA;
request[sizeof(request)-2] = (Byte)0x55;
request[sizeof(request)-1] = (Byte)0x55;

NSData *data = [NSData dataWithBytes:request length:sizeof(request)];
UInt16 port=2918;
NSLog(@"begin scan");
if (![udpSocket bindToPort:port error:&error])
{
    NSLog(@"Error binding: %@", error);
    return;
}
if (![udpSocket beginReceiving:&error])
{
     NSLog(@"Error receiving: %@", error);
    return;
}
if (![udpSocket enableBroadcast:YES error:&error]) {
    NSLog(@"Error enableBroadcast: %@",error);
    return;
}
[udpSocket enableBroadcast:YES error: &error];
    [udpSocket setIPv4Enabled:YES];
    [udpSocket setIPv6Enabled:NO];
[udpSocket sendData :data toHost:[self getBroadcastAdress] port:port withTimeout:timeout tag:0];
接收:

- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
      fromAddress:(NSData *)address withFilterContext:(id)filterContext
{
    NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSString *host = nil;
    uint16_t port = 0;
    [GCDAsyncUdpSocket getHost:&host port:&port fromAddress:address];
    if(![host containsString:deviceIPAddress])
//    if ([host rangeOfString:deviceIPAddress].location == NSNotFound)
    {
            {
                if(![discoveredIPAddress contains Object:[[host componentsSeparatedByString:@":"] last Object]])
                    [discoveredIPAddress add Object:[[host componentsSeparatedByString:@":"] last Object]];
                N Slog(@"Printer IP: %@", discoveredIPAddress);

            }

}
}

请立即给予帮助。谢谢

在发布模式下有什么问题?在发布模式下有什么问题?