Apple Push Notification ADHOC测试

| 2 Comments | No TrackBacks
1 需要PushMebaby 原代码,简单的demo 程序
2 参考其他文档做就可以了
  唯一不有问题的是PushMebaby 没有针对ADHoc 做调整,需要调整的代码
dev 环境

result = MakeServerConnection("gateway.sandbox.push.apple.com", 2195, &socket, &peer);

result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 30);


ADHOC

result = MakeServerConnection("gateway.push.apple.com", 2195, &socket, &peer);

result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 22);


这这个地方要注意DomainName 长度变了,是22不是30。在这个地方上浪费时间了,反复生成cert 文件好几次。

上图

epad_push_notification.png

后面是app delegate class 需要增加的代码

#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 sharedApplicationkeyWindow] 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];


}

No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/300

2 Comments

听说只要是越狱iPhone就无法支持Push Notification功能了,请博主鉴定。

如果用att卡激活就可以push

Leave a comment