標籤:cat thunder number ati 次數 oid repeat return 意圖
本地推送:
UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { NSDate *now=[NSDate new]; notification.fireDate=[now dateByAddingTimeInterval:60];//60秒後通知 notification.repeatInterval=0;//迴圈次數 notification.timeZone=[NSTimeZone defaultTimeZone]; notification.applicationIconBadgeNumber=1; //應用的紅色數字 notification.soundName= UILocalNotificationDefaultSoundName;//聲音 [email protected]"通知內容";//提示資訊 彈出提示框 notification.alertAction = @"開啟"; //提示框button //notification.hasAction = NO; //是否顯示額外的button。為no時alertAction消失 // NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; //notification.userInfo = infoDict; //加入額外的資訊 [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }
推送過後。假設應用處於後台狀態,可實現代理方法來進行想要的操作
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{}
假設應用已退出。這時候要在以下的方法中來取出推送並處理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UILocalNotification * push=[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];//取出推送對象 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
遠程推送的大致流程例如以下:
1.使用appId注冊推送服務
2.獲得推送用的token
3.app上傳token到自己的server
4.自己的server將推送資訊和token發送給apns
5.apns進行推送
:
[iOS 進階] iOS遠程推送與本地推送大致流程