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/
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()
也可以使用第三方的伺服器:
http://urbanairship.com/