Jan
31
2012
Recently we had to conduct a performance test on our Push Notification Server software to measure how long it would take to deliver a large number of Push Notifications to the Apple APNS.
Bombarding the Apple APNS with 500,000+ messages might not go down well with Apple, and we didn’t want to risk getting our server IP blocked for any reason.
We created a fake APNS on a separate server that we could point our Push Notification Server to. This would accept the request but do nothing with it. It’s not a 100% accurate test (the Apple APNS would be slightly slower since it processes the data), but it’s good enough to find a benchmark.
We implemented this using Python, which you can find the code for below. To use this, run the script on the server you want to be the fake APNS. Then in your code that connects to the socket, replace the apple url with the one to this fake server.
e.g “ssl://gateway.push.apple.com:2195″ will become “tcp://yourserver.com:2195″
From this test and other tests we performed, we found that we could send between 1,000 to 3,800 Push Notifications a second to the APNS. Not too shabby I think!
import SocketServer
HOST = "0.0.0.0"
PORT = 2195
# this server uses ThreadingMixIn - one thread per connection
# replace with ForkMixIn to spawn a new process per connection
class EchoServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
# no need to override anything - default behavior is just fine
pass
class EchoRequestHandler(SocketServer.StreamRequestHandler):
"""
Handles one connection to the client.
"""
def handle(self):
print "connection from %s" % self.client_address[0]
while True:
line = self.rfile.readline()
if not line: break
print "%s wrote: %s" % (self.client_address[0], line.rstrip())
#self.wfile.write(line)
print "%s disconnected" % self.client_address[0]
# Create the server
server = EchoServer((HOST, PORT), EchoRequestHandler)
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
print "server listening on %s:%s" % server.server_address
server.serve_forever()
no comments
| posted in Code Examples, iPhone, Server
Sep
24
2010
Using the UIImagePickerController with sourceType = UIImagePickerControllerSourceTypeCamera (to use the Camera), I wanted to overlay my own controls on the screen.
This is simple and can be done like this:
imagePickerController.showsCameraControls = NO;
No problem, right? However this leaves a black bar at the bottom, about 50px or so high!
The black bar is due to a difference in size ratio between the camera and the screen. You can fix this by transforming the camera very slightly:
CGAffineTransform transform = CGAffineTransformMakeScale(1.3, 1.3);
imagePickerController.cameraViewTransform = transform;
The result is a full screen camera image! It is ever so slightly bigger but it’s not noticeable unless you put it side by side with a non transformed version.
no comments
| posted in Code Examples, iPhone
Aug
27
2010
Recently I wrote some conditional code to call various methods depending on the version of iOS running on the device. A problem I came across was that because I still called some deprecated methods I was getting warnings during my build. As I treat all warnings as errors I had to find a solution which would compile. #pragma was the answer.
You can use the following line to disable warnings for depreciated calls:
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
And use this to re-enable it:
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
Here’s how I used it:
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
if([super respondsToSelector:@selector(initWithStyle:reuseIdentifier:)])
{
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
[self setupCell];
}
}
else
{
if(self = [super initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier])
{
[self setupCell];
}
}
return self;
}
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
no comments
| posted in Code Examples, iPhone
Dec
2
2009

PageControl Examples
The UIPageControl has no way of changing the colors of the dots. Kind of annoying right? Well I knocked up a simple solution to customising the look of the UIPageControl.
This class allows you to replace the dots with your own UIImages, with the following 2 properties:
@property (nonatomic, readwrite, retain) UIImage* imageNormal;
@property (nonatomic, readwrite, retain) UIImage* imageCurrent;
It works by replacing the UIImage on the UIImageView containing the original dot.
One word of warning, if Apple change the way the UIPageControl works, this code will most likely break (especially if they change the dots so they are no longer UIImageViews!). However I’d say the only reason this would happen, is if they add their own functionality in to customise the look of it, so it’s probably OK.
Here’s the full code, in all it’s glory. Feel free to use how you see fit (I’m releasing this with no restrictions). It’s not very complicated, but I figured it might be useful to someone!
#import <UIKit/UIKit.h>
@interface OMPageControl : UIPageControl {
UIImage* mImageNormal;
UIImage* mImageCurrent;
}
@property (nonatomic, readwrite, retain) UIImage* imageNormal;
@property (nonatomic, readwrite, retain) UIImage* imageCurrent;
@end
#import "OMPageControl.h"
@interface OMPageControl (Private)
- (void) updateDots;
@end
@implementation OMPageControl
@synthesize imageNormal = mImageNormal;
@synthesize imageCurrent = mImageCurrent;
- (void) dealloc
{
[mImageNormal release], mImageNormal = nil;
[mImageCurrent release], mImageCurrent = nil;
[super dealloc];
}
/** override to update dots */
- (void) setCurrentPage:(NSInteger)currentPage
{
[super setCurrentPage:currentPage];
// update dot views
[self updateDots];
}
/** override to update dots */
- (void) updateCurrentPageDisplay
{
[super updateCurrentPageDisplay];
// update dot views
[self updateDots];
}
/** Override setImageNormal */
- (void) setImageNormal:(UIImage*)image
{
[mImageNormal release];
mImageNormal = [image retain];
// update dot views
[self updateDots];
}
/** Override setImageCurrent */
- (void) setImageCurrent:(UIImage*)image
{
[mImageCurrent release];
mImageCurrent = [image retain];
// update dot views
[self updateDots];
}
/** Override to fix when dots are directly clicked */
- (void) endTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event
{
[super endTrackingWithTouch:touch withEvent:event];
[self updateDots];
}
#pragma mark - (Private)
- (void) updateDots
{
if(mImageCurrent || mImageNormal)
{
// Get subviews
NSArray* dotViews = self.subviews;
for(int i = 0; i < dotViews.count; ++i)
{
UIImageView* dot = [dotViews objectAtIndex:i];
// Set image
dot.image = (i == self.currentPage) ? mImageCurrent : mImageNormal;
}
}
}
@end
36 comments
| posted in Code Examples, iPhone