push notification 使用:
参考资源:
http://tiny4cocoa.com/thread-1406-1-1.html
http://bbs.ldci.com.cn/read.php?tid-19971.html
http://www.cocoachina.com/bbs/read.php?tid-3770-keyword-apns.html
http://code.google.com/p/apns-python-wrapper/
http://urbanairship.com/docs/getting_started_ios_push.html
客户端:
程序上的准备:device token 需要传给provider
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
application.applicationIconBadgeNumber = 0; //程序开启,设置UIRemoteNotificationTypeBadge标识为0
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
}
必须有App ID, 且已经打开notification功能。provision必须重新建立(在 App打开notification功能后)。删除原有的provision,导入新的。
服务器上的准备:
利用这个库,可以简单的构建一个服务器:
http://code.google.com/p/apns-python-wrapper/
测试代码如下:
#!/usr/bin/env python
from APNSWrapper import *
import binascii
deviceToken = binascii.unhexlify('12f53d1bf554d0a01bd7c4f233a668e5878d99f229a76338fd7477f7f381c371');
wrapper = APNSNotificationWrapper('ck.pem', True)
message = APNSNotification()
message.token(deviceToken)
message.alert("Very simple alert")
message.badge(5)
message.sound()
wrapper.append(message)
wrapper.notify()
也可以使用第三方的服务器: