Alter keyboard appearance in native, phonegap/Cordova built iOS App

Loading...

Alter keyboard appearance in native, phonegap/Cordova built iOS App

I want to change the background color of all the keyboards appearing in my Phonegap/Cordova built native iOS App as shown below:

I have googled this thoroughly of course and found mainly 2 relevant answers. The answerer here says that Objective-C code can be added to the PhoneGap project's AppDelegate.m file as shown on this page. I've located the AppDelegate.m file but can't seem to figure out how to set the keyboard appearance to that of UIKeyboardAppearanceAlert on all textfields. Code example provided by the answerer:
 mytextfield.keyboardAppearance = UIKeyboardAppearanceAlert;

Writing an app based on cordova, I can't distinguish any textfield IDs to connect to the above example. Is there a file in Xcode / Cordova in which all the textfield IDs are listed, or even better: 
Is there a way in which I can set the keyboard appearance to dark through UIKeyboardAppearanceAlert or similar approaches, that applies to all textfields and is compatible with Cordova?
Thanks 

Solutions/Answers:

Answer 1:

After sharing this question widely on various social media, more extensive and thorough research, asking friends and aquaintances, etc I can only come to the conclusion that this cannot be done using phonegap and cordova. I would love for anyone to prove me long. For the time being however, this is what I shall conclude.

Answer 2:

As far as I know you can’t do that with Cordova without major hacks, which probably won’t be appreciated by Apple. But not sure.

Answer 3:

There is no way to apply it to ALL text fields in your app without going through your code and manually setting the style of each uitextfields keyboard to the dark one.

EDIT 2: Unfortunately, it doesn’t look like there’s any possible way to do this without tapping into the Phonegap framework. And It doesn’t look like this is possible without “hacking” into it as mentioned above.

EDIT:
There doesn’t seem to be any HTML element for the input tag (from Apple’s Mobile Safari or Phonegap) that you can set to make the appearance into a alert. So (if possible) do a search for UITextField *.

Like in this image...

And right under the line that should look somewhat like this:

UITextField *field = [[UITextField alloc] init...];

Add this line

field.keyboardAppearance = UIKeyboardAppearanceAlert; // just like in your example...

If you do this for all the UITextField results then all your keyboards will look like the picture in your description.

Our Awesome Free Tools

References

Loading...

How to send NSString through socket using NSOutputStream

Loading...

How to send NSString through socket using NSOutputStream

I have to create a chat app for iOS using socket programming and my IP address is 192.168.0.57:9300.
I have used Raywenderlich socket programming example,receiving data working properly but sending not working ,there are no any error or crash.
My code are as follows.
code  for opening streams  
- (void) initNetworkCommunication {

    CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.0.57", 9300, &readStream, &writeStream);

    inputStream = (NSInputStream *)readStream;
    outputStream = (NSOutputStream *)writeStream;
    [inputStream setDelegate:self];
    [outputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];
    [outputStream open];    
}

code for sending data
- (IBAction)sendMessage:(id)sender
{
        NSString *response  = @"lets start chat";
        NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
        [outputStream write:[data bytes] maxLength:[data length]]; 
}

Delegates 
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {

    NSLog(@"stream event %i", streamEvent);

    switch (streamEvent) {

        case NSStreamEventOpenCompleted:
            NSLog(@"Stream opened");
            break;
        case NSStreamEventHasBytesAvailable:

            if (theStream == inputStream) {

                uint8_t buffer[1024];
                int len;

                while ([inputStream hasBytesAvailable]) {
                    len = [inputStream read:buffer maxLength:sizeof(buffer)];
                    if (len > 0) {

                        NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];

                        if (nil != output) {

                            NSLog(@"\nreciving data------%@,buffer);

                            [self messageReceived:output];

                        }
                    }
                }
            }
            break;


        case NSStreamEventErrorOccurred:

            NSLog(@"Can not connect to the host!");
            break;

        case NSStreamEventEndEncountered:

            [theStream close];
            [theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [theStream release];
            theStream = nil;

            break;
        default:
            NSLog(@"Unknown event");
    }

}
Message sending
    - (void) messageReceived:(NSString *)message {

        [self.messages addObject:message];
        [self.tView reloadData];
        NSIndexPath *topIndexPath = [NSIndexPath indexPathForRow:messages.count-1 
                                                       inSection:0];
        [self.tView scrollToRowAtIndexPath:topIndexPath 
                          atScrollPosition:UITableViewScrollPositionMiddle 
                                  animated:YES];

    }

please provide me suggestion.

Solutions/Answers:

Answer 1:

You should add the “\n” at the end of your response like this:

- (IBAction)sendMessage:(id)sender
{
        NSString *response  = @"lets start chat\n";
        ////your code
}

This work for me, but my problem is that I cannot receive data using the function (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent

Answer 2:

I had similar problem. Got it solved by appending new-line and line-feed character in string.

- (IBAction)sendMessage:(id)sender {

        NSString *response  = @"lets start chat\r\n\r\n";
        NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
        [outputStream write:[data bytes] maxLength:[data length]]; 
}

Answer 3:

I found writing a separate thread solved this issue for me.
Makes sense as one shouldn’t really do network ops on the main thread.
Here is my code:

dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^(void) {
    NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
    NSInteger len = [outputStream write:[data bytes] maxLength:[data length]];
    NSLog(@"Len = %ld", len);
});

Another point to note is that the NSStreamEventOpenCompleted event is called twice. Once when each of the input and output streams are opened. So one needs to be careful not to write to the output stream prior to its event.

Our Awesome Free Tools

References

Loading...