NSOutput Stream Write operation failing via polling and run loop scheduling in background mode iOS 6

421 views Asked by At

I have an app which uses the external accesssory framework. I have followed the example provided by Apple by the name EADemo. I am writing to the output stream via the polling mechanism and it works fine ntil iOS 5. When I am testing with iOS 6 and wait for the HasSpaceAvailable it always returns a NO. From the discussions here http://discussions.apple.com/message/21161460#21161460 I tried changing the current run loop to main run loop, but still I had no success.

I am posting some of my code to give an idea:

    [[mSession inputStream] setDelegate:self];
    [[mSession inputStream] scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [[mSession inputStream] open];

    // get the output stream from session object and schedule it in the run loop
    // to get the events on the stream

    [[mSession outputStream] setDelegate:self];
    [[mSession outputStream] scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [[mSession outputStream] open];
    status  = YES;

The write method which I am using from the EADemo code.

    while (([[mSession outputStream] hasSpaceAvailable]) && ([mWriteData length] > 0))
    {
        bytesWritten = [[mSession outputStream] write:[mWriteData bytes] maxLength:[mWriteData length]];
        if (bytesWritten == -1)
        {

            break;
        }
        else if (bytesWritten > 0)
        {
            NSString *str = [NSString stringWithFormat:@"Successfully written : %d bytes",bytesWritten];


            [mWriteData replaceBytesInRange:NSMakeRange(0, bytesWritten) withBytes:NULL length:0];
        }

        else if(bytesWritten == 0)
        {
            NSString* streamStatus = [NSString stringWithFormat:@"STREAM CAPACITY REACHED"];

        }

    }

}

else
{

    bytesWritten = -1;

}

I have to support the data transfer in both the foreground and the background. I see the data transfer happening in the foreground but it fails in the background. I see the app working fine until iOS 5but when I am trying to test on iOS 6 devices it fails.Does any one have a solution for this?

0

There are 0 answers