Facebook's SDK does not provide the delegate function to show the progress during uploading the data to Facebook, e.g. photo. Therefore, user has to create it by adding the following functions into FBRequest.h and FBRequest.m as well as your ViewController.
In FBRequest.h, add the below function under FBRequestDelegate protocol:
- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;
In FBRequest.m, add the below function:
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
if ([_delegate respondsToSelector:@selector(request:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
[_delegate request:self didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
} }
In your ViewController, add the below function to implement the delegate function:
- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
NSLog(@"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite); }
Right now, your ViewController can receive the feedback from FBRequest when the data is being uploaded to Facebook.
Showing posts with label iPhone SDK. Show all posts
Showing posts with label iPhone SDK. Show all posts
Wednesday, September 12, 2012
Tuesday, July 3, 2012
Base64 encode/decode method
//put it on the top of xxx.m
{
// encode method
// decode method
****************************************************
static char base64EncodingTable[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
- (void)testBase64{
NSString *testStr = @"000000";
NSString *encodedStr = [self base64StringFromData:testStr];
NSLog(@"%@", encodedStr);
NSData *data = [self base64DataFromString:encodedStr];
NSString decodedStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"decoded string is %@ for %@", decodedStr, testStr);
}
// encode method
-(NSString *) base64StringFromData:(NSString *)str
{
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
int length = str.length;
unsigned long ixtext, lentext;
long ctremaining;
unsigned char input[3], output[4];
short i, charsonline = 0, ctcopy;
const unsigned char *raw;
NSMutableString *result;
lentext = [data length];
if (lentext < 1)
return @"";
result = [NSMutableString stringWithCapacity: lentext];
raw = [data bytes];
ixtext = 0;
while (true) {
ctremaining = lentext - ixtext;
if (ctremaining <= 0)
break;
for (i = 0; i < 3; i++) {
unsigned long ix = ixtext + i;
if (ix < lentext)
input[i] = raw[ix];
else
input[i] = 0;
}
output[0] = (input[0] & 0xFC) >> 2;
output[1] = ((input[0] & 0x03) << 4) | ((input[1] & 0xF0) >> 4);
output[2] = ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6);
output[3] = input[2] & 0x3F;
ctcopy = 4;
switch (ctremaining) {
case 1:
ctcopy = 2;
break;
case 2:
ctcopy = 3;
break;
}
for (i = 0; i < ctcopy; i++)
[result appendString: [NSString stringWithFormat: @"%c", base64EncodingTable[output[i]]]];
for (i = ctcopy; i < 4; i++)
[result appendString: @"="];
ixtext += 3;
charsonline += 4;
if ((length > 0) && (charsonline >= length))
charsonline = 0;
}
return result;
}
// decode method
- (NSData *)base64DataFromString: (NSString *)string
{
unsigned long ixtext, lentext;
unsigned char ch, inbuf[4], outbuf[3];
short i, ixinbuf;
Boolean flignore, flendtext = false;
const unsigned char *tempcstring;
NSMutableData *theData;
if (string == nil)
{
return [NSData data];
}
ixtext = 0;
tempcstring = (const unsigned char *)[string UTF8String];
lentext = [string length];
theData = [NSMutableData dataWithCapacity: lentext];
ixinbuf = 0;
while (true)
{
if (ixtext >= lentext)
{
break;
}
ch = tempcstring [ixtext++];
flignore = false;
if ((ch >= 'A') && (ch <= 'Z'))
{
ch = ch - 'A';
}
else if ((ch >= 'a') && (ch <= 'z'))
{
ch = ch - 'a' + 26;
}
else if ((ch >= '0') && (ch <= '9'))
{
ch = ch - '0' + 52;
}
else if (ch == '+')
{
ch = 62;
}
else if (ch == '=')
{
flendtext = true;
}
else if (ch == '/')
{
ch = 63;
}
else
{
flignore = true;
}
if (!flignore)
{
short ctcharsinbuf = 3;
Boolean flbreak = false;
if (flendtext)
{
if (ixinbuf == 0)
{
break;
}
if ((ixinbuf == 1) || (ixinbuf == 2))
{
ctcharsinbuf = 1;
}
else
{
ctcharsinbuf = 2;
}
ixinbuf = 3;
flbreak = true;
}
inbuf [ixinbuf++] = ch;
if (ixinbuf == 4)
{
ixinbuf = 0;
outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4);
outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2);
outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F);
for (i = 0; i < ctcharsinbuf; i++)
{
[theData appendBytes: &outbuf[i] length: 1];
}
}
if (flbreak)
{
break;
}
}
}
return theData;
}
****************************************************
Output in console:
Decoded string is MDAwMDAw for testStr 000000;
Tuesday, June 26, 2012
php: generates Token with random string
The following code generate the random string with certain length to the client. It can be used to create the token and send to client's apps.
<?php
<?php
// generate random string
function random_gen($length)
{
$random= "";
srand((double)microtime()*1000000);
$char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$char_list .= "abcdefghijklmnopqrstuvwxyz";
$char_list .= "1234567890";
// Add the special characters to $char_list if needed
for($i = 0; $i < $length; $i++)
{
$random .= substr($char_list,(rand()%(strlen($char_list))), 1);
}
return $random;
}
$random_string = random_gen(30); //This will return a random 30 character string
echo "New Token: ".$random_string;
?>
Monday, June 25, 2012
Distribute beta App over the air
Now it is not necessary to send ipa file and distribution profile to beta tester for Apps testing. There is a distribution OTA method, the apps can be uploaded to server and let tester to install it from server.
1. to create a provisioning distribution profile for Ad Hoc build with the selected iDevices (devices' UDID are registered in the portal).
2. in Xcode, associate this provisioning distribution profile with your build. In the Code Signing section choose the new Provisioning Profile.
3. Build and Archive.
4. Click on the Share button, and choose Distribute for Enterprise – fill in the URL to the location where you plan to host the application.
5. Upload ipa, plist and icon files to the server you typed in step 4.
6. Build the HTML to let iDevice to access and install the app.
1. to create a provisioning distribution profile for Ad Hoc build with the selected iDevices (devices' UDID are registered in the portal).
2. in Xcode, associate this provisioning distribution profile with your build. In the Code Signing section choose the new Provisioning Profile.
3. Build and Archive.
4. Click on the Share button, and choose Distribute for Enterprise – fill in the URL to the location where you plan to host the application.
5. Upload ipa, plist and icon files to the server you typed in step 4.
6. Build the HTML to let iDevice to access and install the app.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>OTA Test App</title>
</head>
<body>
<br><font size = "20">You are invited to test new app.</font></br>
<br><<font size="15"><a href="itms-services://?action=download-manifest&url=http://www.yourwebsite.com">Tap Here to Install the Application</a></font>
</br>
</body> </html>
You may refer to the below link.
http://mobiledevelopertips.com/xcode/distribute-ad-hoc-applications-over-the-air-ota.html
You may refer to the below link.
http://mobiledevelopertips.com/xcode/distribute-ad-hoc-applications-over-the-air-ota.html
Labels:
Ad hoc,
distribution,
iPhone SDK,
over the air
Sunday, June 17, 2012
Label with dynamic height
The below code creates the dynamic height to fit for the inputed text
-(void)createDynamicHeight
{
-(void)createDynamicHeight
{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 300, 40)];
label.backgroundColor = [UIColor blackColor];
[self.view addSubview:label];
NSString *text = @"This is label with dynamic height";
label.text = text;
label.lineBreakMode = UILineBreakModeWordWrap;
// resize the height to fit the content
CGSize newLabelSize = [text sizeWithFont:label.font
constrainedToSize:label.frame.size
lineBreakMode:UILineBreakModeWordWrap];
CGRect newFrame = instructions.frame;
if (newLabelSize.height > 40) {
newFrame.size.height = newLabelSize.height;
} else {
newFrame.size.height = 40
}
label.frame = newFrame;
label.numberOfLines = 0;
NSLog(@"Label height is %f", label.frame.size.height);
}
Thursday, June 14, 2012
Error: more than max 5 filtered album trying to register, this will fail
Per the subject, the following code may help to solve it.
I tried in my project, it seems work.
I tried in my project, it seems work.
- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self setModalInPopover:YES];}
Tuesday, June 12, 2012
Limit the number of characters in UITextView
#define MAX_LENGTH 50
// UITextView delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSLog(@"type %d char", myTextView.text.length);
if (myTextView.text.length >= MAX_LENGTH && range.length == 0)
{
NSLog(@"max length is reached");
return NO; // return NO to not change text
}
}
Tuesday, June 5, 2012
Limit the number of lines in UITextView
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
// limit the number of lines in textview
NSString* newText = [mytextView.text stringByReplacingCharactersInRange:range withString:text];
// pretend there's more vertical space to get that extra line to check on
CGSize tallerSize = CGSizeMake(mytextView.frame.size.width-15, mytextView.frame.size.height*2);
CGSize newSize = [newText sizeWithFont:mytextView.font constrainedToSize:tallerSize lineBreakMode:UILineBreakModeWordWrap];
if (newSize.height > mytextView.frame.size.height)
{
NSLog(@"two lines are full");
return NO;
}
// dismiss keyboard and send comment
if([text isEqualToString:@"\n"]) {
[mytextView resignFirstResponder];
return NO;
}
return YES;
}
Tuesday, May 15, 2012
Hide StatusBar, TabBar, NavigationBar
1. To hide the status bar:
[[UIApplication shareApplication] setStatusBarHidden:YES];
2. To hide the navigation bar:
self.navigationController.navigationBarHidden = YES;
3. To hide the tab bar:
MyController *myController = [[MyController alloc] init ];
myController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
[[UIApplication shareApplication] setStatusBarHidden:YES];
2. To hide the navigation bar:
self.navigationController.navigationBarHidden = YES;
3. To hide the tab bar:
MyController *myController = [[MyController alloc] init ];
myController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
Labels:
iPhone SDK,
statusBar,
UINavigationBar,
UITabbar
Subscribe to:
Posts (Atom)