Friday, December 16, 2011

iphone element sizes

Core Elements:
Carrier Status bar - 320x20
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44
Data Input:
UIPickerView - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216
Buttons:
UISegmentedControl - 320x44
UIButton xx37
Fields:
UITextField - xx37
UISwitch 94x27
UISlider - xx23
Indicators:
UIProgressView -xx9
UIActivityIndicatorView - 37x37
UIPageControl - 38x36

Thursday, August 4, 2011

UIEdgeInsets.

Shrinking, Expanding, Edge Insetting
If you need to shrink a CGRect by a certain value horizontally and vertically you could do so by modifying the structure members themselves. But way more elegant is to use the provided convenient macro CGRectInset. Positive values will decrease the size evenly for the new rectangle to be centered in the old one. Negative values by the same token will increase it.
CGRect aRectangle = CGRectMake(0,0, 100, 200);
CGRect smallerRectangle = CGRectInset(aRectangle, 10, 20);
// result origin (10, 20) and size (80, 160)
This method is fine for 80% of use cases, but sometimes you want to apply different insets for each edge. Imagine, if you will that you want, to have a property contentInsets that would specify the distance a view content should have from each border. The structure of choice for this is UIEdgeInsets(top, left, bottom, right), and of course, there is also a matching Make macro available.
Once you have both you can easily apply the insets to your rect to receive the finally content rectangle. The macro for this purpose is UIEdgeInsetsInsetRect, would you have guessed?
CGRect rect = CGRectMake(0, 0, 100, 200);
UIEdgeInsets contentInsets = UIEdgeInsetsMake(10, 20, 30, 40);

CGRect result = UIEdgeInsetsInsetRect(rect, contentInsets);
NSLog(@"x: %f, y: %f, width: %f, height: %f",
result.origin.x, result.origin.y,
result.size.width, result.size.height);
// x: 20.000000, y: 10.000000, width: 40.000000, height: 160.000000
Actually the above NSLog is how I have been inspecting CGRect for the past 2 years. Right after I published the first version of this blog post I was pointed out to me that there is an even more elegant method: NSStringFromCGRect. Wow, a third as much key strokes.
NSLog(@"%@", NSStringFromCGRect(result));
// {{20, 10}, {40, 160}}
Wway more elegant, I’m sure you’ll agree? (Thanks Matt and Thomas But that’s the point of making these write ups. You learn a bit from writing them and you learn a bit more when other pros tell you the mistakes you made.

from: http://www.cocoanetics.com/2010/07/cgrect-tricks/

Wednesday, July 13, 2011

programmatically determine app is running in the iphone simulator?


NSString *model= [[UIDevice currentDevice] model];
NSString *iPhoneSimulator = @”iPhone Simulator”;
if ([model compare:iPhoneSimulator] == NSOrderedSame){
//device is simulator
}

CryptographicException APNS

[CryptographicException: An internal error occurred.
]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
   System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
   System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) +203
   System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password) +80
   System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) +79
   JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File, String p12FilePassword) +224
   JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32 value) +119
   JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean sandbox, String p12File, String p12FilePassword, Int32 connections) +211
   APN.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\iPhone\APN.aspx.cs:51
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
----
use code in NotificationConnection.cs: 

//certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword);
certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

Friday, July 8, 2011

FBConnect using other ViewController



in the YourApp_AppDelegate.h
#import "FBConnect.h"
Facebook *facebook;
@property (nonatomic, retain) Facebook *facebook;
In the YourApp_AppDelegate.m
@synthesize facebook;
Then in your application didFinishLaunchingWithOptions: function:
facebook = [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_API"];
From your viewController.h (any of them),
#import "YourApp_AppDelegate.h"
YourApp_AppDelegate *appDelegate;
And then, in your viewController.m viewDidLoad function:
appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];
Now, anytime you want to refer to your Facebook singleton, just refer to it like:
[appDelegate.facebook authorize:nil delegate:self];

Tuesday, June 28, 2011

Error "405 Method Not Allowed" when performing a PUT on IIS7

To fix this error, go to the root of your site in IIS, find the Modules button and double click it. Scroll down to WebDAV and hit Remove on the right. Back out and open up the WebDAV feature options. Make sure it's disabled (you'll have the option to enable it on the right). You might want to clear out any Authoring settings you have in there as well, just to be sure.

SBJson null

To test if a value parsed by SBJson in a NSDictionary is null  do this:

if ((CFNullRef)[participant valueForKey:kIndex] == kCFNull) {
   // do something
}