Friday, June 10, 2016

Blackberry get IP Address

    String ip = new String("");

    try {
        int cni = RadioInfo.getCurrentNetworkIndex();
        int apnId = cni + 1;
        byte[] ipaddr = RadioInfo.getIPAddress(apnId);
        for (int i = 0; i < ipaddr.length; i++) {
        int temp = (ipaddr[i] & 0xff);
        if (i < 3) {
            ip = ip.concat("" + temp + ".");
        } else {
            ip = ip.concat("" + temp);
        }
        }
        System.out.println("ipaddress " + ip);
    } catch (Exception e) {
        ip = null;
    }

Blackberry Get User Address from Lattitude and Longitude

  getLocationFromGoogleMaps(43.4631,-80.5207);

  private static void getLocationFromGoogleMaps(double _lattitude, double _longitude) {

    String fullAddress = "";
    HttpConnection conn = null;
    InputStream in = null;
    ByteArrayOutputStream out = null;
    try {
        String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + _lattitude + "," + _longitude;
        conn = (HttpConnection) Connector.open(url, Connector.READ);
        conn.setRequestMethod(HttpConnection.GET);
        int code = conn.getResponseCode();
        if (code == HttpConnection.HTTP_OK) {
        in = conn.openInputStream();
        out = new ByteArrayOutputStream();
        byte[] buffer = new byte[in.available()];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer);
        }
        out.flush();
        String response = new String(out.toByteArray());
        JSONObject resObject = new JSONObject(response);
        JSONArray result = resObject.getJSONArray("results");

        if (result.length() > 0) {
            JSONObject dict = result.getJSONObject(0);
            System.out.println("**Resp :**" + dict.getString("formatted_address"));
            fullAddress = dict.getString("formatted_address");
            Dialog.alert(fullAddress);
        } else {
           //error
        }

        }
    } catch (Exception e) {
        Dialog.alert(e.getMessage());
       }

    }

Friday, February 26, 2016

IOS LinkedIn Integration

 Add the linkedin sdk(this). Then on login button click, use the following code.
Dont forget to add the linkedin app id on info.plist file.

  [LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil]
                                         state:@"some state"
                        showGoToAppStoreDialog:YES
                                  successBlock:^(NSString *returnState) {
                                     
                                      NSLog(@"%s","success called!");
                                      LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
                                      NSLog(@"value=%@ isvalid=%@",[session value],[session isValid] ? @"YES" : @"NO");
                                      NSMutableString *text = [[NSMutableString alloc] initWithString:[session.accessToken description]];
                                      [text appendString:[NSString stringWithFormat:@",state=\"%@\"",returnState]];
                                      NSLog(@"Response label text %@",text);
                                     // NSString *session1 = text;
                                      self.lastError = nil;
                                      // retain cycle here?
                                   
                                      [[LISDKAPIHelper sharedInstance] apiRequest:@"https://www.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,email-address,formatted-name,picture-url)"
                                                                           method:@"GET"
                                                                             body:[@"" dataUsingEncoding:NSUTF8StringEncoding]
                                                                          success:^(LISDKAPIResponse *response) {
                                   NSLog(@"success called %@", response.data);
                                                                             
                                     
                                    NSError *jsonError;
                                    NSData *objectData = [response.data dataUsingEncoding:NSUTF8StringEncoding];
                                    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
                                                                                                                                   options:NSJSONReadingMutableContainers
                                                                                                                                     error:&jsonError];

                                                                             
                                                                             
                                                                          }
                                                                            error:^(LISDKAPIError *apiError) {
                                                                                NSLog(@"error called %@", apiError.description);
                                                                               
                                                                               
                                                                            }];
                                     
                                  }
                                    errorBlock:^(NSError *error) {
                                        NSLog(@"%s %@","error called! ", [error description]);
                                        self.lastError = error;
                                      
                                    }
     ];
    NSLog(@"%s","sync pressed3");

Monday, November 17, 2014

IOS checking string contains Uppercase, Lowercase and Digits

NSCharacterSet *lowerCaseChars = [NSCharacterSet characterSetWithCharactersInSt
ring:@"abcdefghijklmnopqrstuvwxyz"];
    
    NSCharacterSet *upperCaseChars = [NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLKMNOPQRSTUVWXYZ"];
    
    NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    
    if ([tx1.text rangeOfCharacterFromSet:lowerCaseChars].location == NSNotFound) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"no small"
                                                        message:tx1.text
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }else if([tx1.text rangeOfCharacterFromSet:upperCaseChars].location == NSNotFound) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"no cap"
                                                        message:tx1.text
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        
    }else if([tx1.text rangeOfCharacterFromSet:numbers].location == NSNotFound) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"no num"
                                                        message:tx1.text
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        
    }else{
      
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"yes......"
                                                            message:tx1.text
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
            
       
    }