Pages

Wednesday, May 29, 2013

Accept buddy request in xmpp client


You will receive the subscription in function didReceivePresence.


- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)
 presence {

    // a buddy went offline/online

    NSString *presenceType = [presence type];            // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];

    if (![presenceFromUser isEqualToString:myUsername]) {

        if ([presenceType isEqualToString:@"available"]) {

            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:
@"%@@%@" , presenceFromUser, kHostName]];
               NSLog(@"presence user is %@",presenceFromUser);

        } 

        else if  ([presenceType isEqualToString:@"unavailable"]) {

            [_chatDelegate buddyWentOffline:[NSString stringWithFormat:
@"%@@%@" , presenceFromUser, kHostName]];
            NSLog(@"presence user is invisible %@",presenceFromUser);

        }
        else if  ([presenceType isEqualToString:@"subscribe"]) {

        NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
        [presence addAttributeWithName:@"type" stringValue:@"subscribed"];
        [presence addAttributeWithName:@"to" stringValue:[presence fromStr]];
        [presence addAttributeWithName:@"from" stringValue:@"you@host"];
        [[self xmppStream] sendElement:presence];

        }

    }
}

How to blinking the text of UITextview

CABasicAnimation *basic=[CABasicAnimation animationWithKeyPath:@"transform"];
[basic setToValue:[NSValue valueWithCATransform3D:CATransform3DMakeScale (1.25, 1.25, 1.25)]];
[basic setAutoreverses:YES];
[basic setRepeatCount:MAXFLOAT];
[basic setDuration:0.25];
[self.imgVArrow.layer addAnimation:basic forKey:@"transform"];

How to get Screen Shot of current ViewController



    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData * data = UIImagePNGRepresentation(image);
    [data writeToFile:@"foo.png" atomically:YES];