Month: April 2015

[QA]How to sort NSArray in 3 ways

Compare method

1
2
3
4
5
6
- (NSComparisonResult)compare:(Person *)otherObject {
    return [self.birthDate compare:otherObject.birthDate];
}
 
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];

NSSortDescriptor

1
2
3
4
5
6
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"birthDate"
                                              ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];

Blocks

1
2
3
4
5
6
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
    NSDate *first = [(Person*)a birthDate];
    NSDate *second = [(Person*)b birthDate];
    return [first compare:second];
}];
Tags : ,

XMPP commons

get server version

<iq type="get" to="test2@ynjan.com/cs101" id="aabea">
<query xmlns="jabber:iq:version"/>
</iq>
<iq from="test2@ynjan.com/cs101" type="result" to="test2@ynjan.com/cs101" id="aabea">
<query xmlns="jabber:iq:version">
<name>Tigase</name>
<version>7.0.1-b3810/2cf8a210 (2015-03-25/17:34:46)</version>
<os>Mac OS X-x86_64-10.9.5, Java HotSpot(TM) 64-Bit Server VM-24.75-b04-Oracle Corporation</os>
</query>
</iq>

set my vcard

<iq type="set" id="aabfa">
<vCard xmlns="vcard-temp"> 
<NICKNAME>test2 nick</NICKNAME> 
</vCard>
</iq>
<iq type="result" id="aabfa" to="test2@ynjan.com/cs101"/>

get vcard

<iq type="get" to="test1@ynjan.com" id="aac1a">
<vCard xmlns="vcard-temp"/> 
</iq>
<iq from="test1@rd.connexionone.com" type="result" to="test2@rd.connexionone.com/rd" id="aac1a"> 
<vCard xmlns="vcard-temp"> 
<NICKNAME>test1 nick</NICKNAME> 
</vCard> 
</iq>
Tags :

[QA]How to get mimeType of file in a Android

    public static String getMimeType(String url) {
        String type = "*/*";
        String extension = MimeTypeMap.getFileExtensionFromUrl(url);
        if (extension != null) {
            MimeTypeMap mime = MimeTypeMap.getSingleton();
            type = mime.getMimeTypeFromExtension(extension.toLowerCase());
        }
        return type;
    }

XMPP Roster

xmpp roster SD

 

  1. Add Roster
    1. Add Roster
      <iq type="set" id="aadba">
       <query xmlns="jabber:iq:roster">
        <item jid="b@ynjan.com"/>
       </query>
      </iq>
    2. Subscribe
      <presence type="subscribe" to="b@ynjan.com">
       <nick xmlns="http://jabber.org/protocol/nick">_b_</nick>
      </presence>
    3. Subscribed
      <presence type="subscribed" to="a@ynjan.com" from="b@ynjan.com">
      </presence>
  2. Remove Roster
    <iq type="set" id="aadda">
    <query xmlns="jabber:iq:roster">
    <item subscription="remove" jid="b@ynjan.com"/>
    </query>
    </iq>
Tags : ,