RSS

Monthly Archives: May 2012

iPhone upload image to server through web service

iPhone upload image to server through web service

iPhone:

NSString *serverUrl = @"http://192.168.1.101/learn/yii_test/index.php/api/uploadimage";
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:serverUrl]];
[request setData:UIImagePNGRepresentation(self.imageView.image) withFileName:@"avatar.png" andContentType:@"image/png"  forKey:@"image"];
[request setRequestMethod:@"POST"];

request.delegate = self;
[request startAsynchronous];

Web Service (here I am using php-yii framework)

$result = array();
$image = new Image;

try
{
    $uploadDir = 'uploads/';
    $file = basename($_FILES['image']['name']);
    $uploadFile = $uploadDir.$file;       

    if ( move_uploaded_file($_FILES['image']['tmp_name'], $uploadFile) ) 
    {
        $image->path = $uploadFile;
        if ( $image->save() ) 
        {
            $result['status'] = 'OK';
            $result['message'] = '';
        }
        else
        {
            $result['status'] = 'Error';
            $result['message'] = 'Cannot save image';
            $result['files'] = $_FILES;
        }
    }
    else
    {
        $result['status'] = 'Error';
        $result['message'] = 'Error saving image '.$uploadFile;
    }
}
catch ( Exception $ex )
{
    $result['status'] = 'Error';
    $result['message'] = $ex->getMessage();
}

echo CJSON::encode($result);
Yii:app()->end();

Notes:

  1. There must be a directory ‘uploads/’ on the server
  2. The directory path is relative to the root of the web site
  3. The directory must be writable.
Advertisements
 
Leave a comment

Posted by on May 24, 2012 in iPhone

 

Tags: , ,

Adjust view content when keyboard is shown

Adjust view content when keyboard is shown

Step 1. Create a KeyboardDisplayProtocol (KeyboardDisplayProtocol.h):

#import <Foundation/Foundation.h>

@protocol KeyboardDisplayProtocol <NSObject>

- (void)registerForKeyboardNotifications;
- (void)unregisterForKeyboardNotifications;
- (void)keyboardWasShown:(NSNotification *)aNotification;
- (void)keyboardWillBeHidden:(NSNotification *)aNotification;

@end

Step 2. Declare your ViewController to extend the protocol. Add an ivar to track the textfield user has clicked. (MyViewController.h)

@interface MyViewController : UIViewController <KeyboardDisplayProtocol>
{
    UITextField                 *m_activeField;
}

Step 3. Implement the protocol methods in MyViewController.m

#pragma mark -
#pragma mark KeyboardDisplay Delegate
- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)unregisterForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardWasShown:(NSNotification *)aNotification
{
    NSDictionary *info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    self.profileTableView.contentInset = contentInsets;
    self.profileTableView.scrollIndicatorInsets = contentInsets;

    CGRect aRect = self.profileTableView.frame;
    aRect.size.height -= kbSize.height;

    CGPoint fieldOrigin = m_activeField.frame.origin;

    fieldOrigin = CGPointMake([[m_activeField superview] superview].frame.origin.x + fieldOrigin.x, [[m_activeField superview] superview].frame.origin.y + fieldOrigin.y);

    if ( !CGRectContainsPoint(aRect, fieldOrigin) ) 
    {
        CGPoint scrollPoint = CGPointMake(0.0, fieldOrigin.y - kbSize.height + 2 * m_activeField.frame.size.height); 
        [scrollView setContentOffset:scrollPoint animated:YES];
    }
}

- (void)keyboardWillBeHidden:(NSNotification *)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}
You might need to customize the code base on your view hirarchy.
The two places you might need to change:
1. Replace "scrollView" with your view which is going to be scrolled
2. Replace "[[m_activeField superview] superview].frame.origin.x" with something you can calculate the clicked textfield y position in your view.

Step 4. Register and unregister keyboard events

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self registerForKeyboardNotifications];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    [self unregisterForKeyboardNotifications];
}

That’s it! Try it out!

Back

 
Leave a comment

Posted by on May 24, 2012 in iPhone

 

Tags: , ,

Adjust view content when keyboard is shown

Step 1. Create a KeyboardDisplayProtocol (KeyboardDisplayProtocol.h):

#import <Foundation/Foundation.h>

@protocol KeyboardDisplayProtocol <NSObject>

– (void)registerForKeyboardNotifications;
– (void)unregisterForKeyboardNotifications;
– (void)keyboardWasShown:(NSNotification *)aNotification;
– (void)keyboardWillBeHidden:(NSNotification *)aNotification;

@end

Step 2. Declare your ViewController to extend the protocol. Add an ivar to track the textfield user has clicked. (MyViewController.h)

@interface MyViewController : UIViewController <KeyboardDisplayProtocol>
{
UITextField *m_activeField;
}

Step 3. Implement the protocol methods in MyViewController.m

#pragma mark –
#pragma mark KeyboardDisplay Delegate
– (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}

– (void)unregisterForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

– (void)keyboardWasShown:(NSNotification *)aNotification
{
NSDictionary *info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.profileTableView.contentInset = contentInsets;
self.profileTableView.scrollIndicatorInsets = contentInsets;

CGRect aRect = self.profileTableView.frame;
aRect.size.height -= kbSize.height;

CGPoint fieldOrigin = m_activeField.frame.origin;

fieldOrigin = CGPointMake([[m_activeField superview] superview].frame.origin.x + fieldOrigin.x, [[m_activeField superview] superview].frame.origin.y + fieldOrigin.y);

if ( !CGRectContainsPoint(aRect, fieldOrigin) )
{
CGPoint scrollPoint = CGPointMake(0.0, fieldOrigin.y – kbSize.height + 2 * m_activeField.frame.size.height);
[scrollView setContentOffset:scrollPoint animated:YES];
}
}

– (void)keyboardWillBeHidden:(NSNotification *)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}

Note: You might need to customize the code base on your view hirarchy.
The two places you might need to change:
1. Replace “scrollView” with your view which is going to be scrolled
2. Replace “[[m_activeField superview] superview].frame.origin.x” with something you can calculate the clicked textfield y position in your view.

Step 4. Register and unregister keyboard events

– (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[self registerForKeyboardNotifications];
}

– (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

[self unregisterForKeyboardNotifications];
}

That’s it! Try it out!

 
Leave a comment

Posted by on May 17, 2012 in iPhone, Uncategorized

 

Tags:

iOS App Review Sites – 167 Sites To Promote iPhone And iPad Apps | iPhone, iOS 5, iPad SDK Development Tutorial and Programming Tips

 

iOS App Review Sites – 167 Sites To Promote iPhone And iPad Apps | iPhone, iOS 5, iPad SDK Development Tutorial and Programming Tips: ” Advertise      Submit      Contact ManiacDev.Com iPhone, iOS, iPad SDK Development Tutorial and Programming Tips iOS 5 Tutorial Xcode Storyboard Tutorial Open Source Apps Tutorials

iOS App Review Sites – 167 Sites To Promote iPhone And iPad Apps

Welcome to another update to the iPhone and iPad app review sites listing in iOS development about three years ago, I made the first posting of the iPhone app review sites list, and it’s been over a year since the last update. Since I’ve recently seen a resurgence in traffic to the older lists about two weeks ago I decided to begin the long process of putting together a new list.

With the first list all but a handful of review sites barely had any traffic at all – things have definitely changed, and there are many review sites with enough traffic to significantly effect your bottom line.

The best way to use this list is to look for sites that have reviewed apps similar to yours. As far as the traffic rankings go sites with an Alexa rat”

 

(Via .)

 
Leave a comment

Posted by on May 17, 2012 in Uncategorized

 

找拍档就像是找结婚对象:寻找优秀联合创始人的几个建议

找拍档就像是找结婚对象:寻找优秀联合创始人的几个建议: “

找个优秀的联合创始人就像中彩票一样难得,一旦你找到了,就有了走进婚姻殿堂的味道。婚姻是否美满又决定了公司的前途和命运。对联合创始人的选择不可不慎,只有对的联合创始人才能与你互补,补充你的薄弱环节。

许多人都有一个创业梦,他们滔滔不绝说起来的时候仿佛就跟真的一样。但当他们真的要面临牺牲现有生活方式的选择的时候,他们的腔调就变得不一样了。这样,有创业念头的人里面就有90%出局了。

找到对的联合创始人并非易事,但也有可行性,至少要比中彩票的机会更大。

优秀联合创始人的好处

有了优秀的联合创始人,你们就可以交流想法,技术上互帮互助,情感上相互支持,也更有机会进入像Y Combinator那样的孵化器。而大多数孵化器也因为上述原因更希望接受有两位以上创始人的创业公司。

“成功的只有单一创始人的创业公司凤毛麟角,它们也因此而知名。”- Paul Graham (Y Combinator)

1. 排除商务人士

尤其是那些口才过人的。他们在创业后期加入大有裨益,但并不适宜在创业早期就把他们拉进来——这个阶段你所要做的是打造一款优秀的产品,而优秀的产品自身就有自我推销的能力。如果你是一位真正的创业者,你同样还会知道如何推销它。

我还发现这些商务人士有烧钱的倾向,他们会为不必要的“业务拓展工作”而产生不必要的花费(这或许是因为他们想趁早证明自己的价值)。在我看来,能证明其价值的最好的办法是:学些技术上的东西,从旁增加价值。如果我要一位商务型联合创始人(business co-founder)的话,我希望他一定要能在产品开发上面提供实实在在的协助。而一旦他们在技术上有了更深的了解,也就更能理解为何一些修补和改变会花上数个小时(而不像想当然那样简单)。

2. 排除交不出成果的人

有些人在以前能够交出成果,但并不代表他现在也行。有些人的履历特别牛逼,但他却连最小可行产品也无法交付。

能交出成果是如此重要,再怎么强调也不为过。这一点就能把你和竞争对手区分开来,也能给你领先者的优势。看看Facebook的工程流程吧,这也是他们之所以优秀的原因:在不破坏原有用户体验的情况下,他们每天都会有小的修改,每周有大的改动。没人喜欢空等,现在就开始交付成果吧。

3. 排除不能沟通的人

无论你的工作是在现场还是远程,从理解对方到表达期望,沟通都是成功的关键所在。如果不能良好沟通或理解对方,曲解的期望就会导致争吵,安排模糊的任务就会导致交不出成果或交出错误的产品/功能,最终生意也会毁于一旦。

沟通没有任何借口可言,也有许多免费的沟通工具可供选择,比如meetings.io, yammer, skype等等不胜枚举,还有更常见的电话、邮件和面对面会议,利用好这些工具。假如没有完成沟通,你也就无法交付正确的结果。

4. 排除让你担忧恐慌的人

没错,这(担忧恐慌)就是我每次面对那些自称能力过人但却无法带来实在价值的联合创始人的切实感受。我从中获得的教训是:“遇到问题一定要行动起来,比起行动,人们会对不作为后悔更甚。”

当你等着某人从松懈的状态中奋起的话,估计你会十分痛苦。如果你恰好就有这样的拍档成天在你周围晃悠,请立刻行动起来,马上摆脱他(没有改观的话)。

5. 回答几个问题

在你把你的精力和时间交给潜在的联合创始人之前,请回答下面的问题:

1. 在执行力和及时交付成果上面,他们没有一些案例?注意,这指的是在当前环境下的近段时间的项目,而不是较久以前的项目。

2. 他们能否良好沟通?一个简单的测试办法就是看看他们如何当面或通过邮件向你陈述或沟通某事。你是否觉得不能从中清楚了解到项目的进展,或不明白他所传达的信息?

3. 在你不擅长的领域,他们是否有较专业的知识?答案是肯定的话,就让他在该领域做一个小项目,看看他的功力如何。

4. 做个测试,看看他有没有创始人的价值(这里有一个)。但请不要只看这个测试就下结论,这个测试不过是让你的脑子动起来而已。

via theroadtosiliconvalley

除非注明,本站文章均为原创或编译,转载请注明: 文章来自36氪

 

(Via 36氪.)

 
Leave a comment

Posted by on May 8, 2012 in Entrepreneurship