result = MakeServerConnection("gateway.sandbox.push.apple.com", 2195, &socket, &peer);
result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 30);
#pragma mark -
#pragma mark pushnotification
// Report the notification payload when launched by alert
- (void) launchNotification: (NSNotification *) notification
{
[self performSelector:@selector(showString:) withObject:[[notification userInfo] description] afterDelay:1.0f];
}
// Handle an actual notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *status = [NSString stringWithFormat:@"Notification received:\n%@",[userInfo description]];
[self showString:status];
CFShow([userInfo description]);
}
// Provide a user explanation for when the registration fails
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSString *status = [NSString stringWithFormat:@"%@\nRegistration failed.\n\nError: %@", pushStatus(), [error localizedDescription]];
[self showString:status];
NSLog(@"Error in registration. Error: %@", error);
}
// Retrieve the device token
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSString *results = [NSString stringWithFormat:@"Badge: %@, Alert:%@, Sound: %@",
(rntypes & UIRemoteNotificationTypeBadge) ? @"Yes" : @"No",
(rntypes & UIRemoteNotificationTypeAlert) ? @"Yes" : @"No",
(rntypes & UIRemoteNotificationTypeSound) ? @"Yes" : @"No"];
NSString *status = [NSString stringWithFormat:@"%@\nRegistration succeeded.\n\nDevice Token: %@\n%@", pushStatus(), deviceToken, results];
[self showString:status];
NSLog(@"deviceToken: %@", deviceToken);
}
- (void) showString: (NSString *) aString
{
UITextView *tv = (UITextView *)[[[UIApplication sharedApplication] keyWindow] viewWithTag:TEXTVIEWTAG];
tv.text = aString;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//viewController = [[MDLibViewController alloc] initWithNibName:@"MDLibViewController" bundle:nil];
viewController = [[MDLibViewController alloc] init];
viewController.managedObjectContext = self.managedObjectContext;
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
//[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(proeareForUser) userInfo:nil repeats:NO];
// Listen for remote notification launches
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(launchNotification:) name:@"UIApplicationDidFinishLaunchingNotification" object:nil];
}

听说只要是越狱iPhone就无法支持Push Notification功能了,请博主鉴定。
如果用att卡激活就可以push