先去 developer 開啟 app-id 的推播
更新 provisioning,不然會有 找不到應用程式ID或授權的錯誤
程式內
開啟後執行
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
}
使用者開啟時就會出現註冊推播警告視窗,下面這各是申請更多權限
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
若使用者不同意,執行(並於每次開機後執行?)
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err{
若使用者同意後,執行(並於每次開機後執行)
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
以下是接收 push 訊息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
沒有留言:
張貼留言