1. 程式人生 > >iOS適配的相關內容的整理

iOS適配的相關內容的整理

2.
/**
    訊息推送
 **/
- (void) msgPush
{
    //推送的形式:標記,聲音,提示
    if (IS_IOS8) {
        //1.建立訊息上面要新增的動作(按鈕的形式顯示出來)
        UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
        action.identifier = @"action";//按鈕的標示
        [email protected]"Accept";//按鈕的標題
        action.activationMode = UIUserNotificationActivationModeForeground;//當點選的時候啟動程式
        //    action.authenticationRequired = YES;
        //    action.destructive = YES;
        
        UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];
        action2.identifier = @"action2";
        
[email protected]
"Reject"; action2.activationMode = UIUserNotificationActivationModeBackground;//當點選的時候不啟動程式,在後臺處理 action.authenticationRequired = YES;//需要解鎖才能處理,如果action.activationMode = UIUserNotificationActivationModeForeground;則這個屬性被忽略; action.destructive = YES; //2.建立動作(按鈕)的類別集合 UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys.identifier = @"alert";//這組動作的唯一標示,推送通知的時候也是根據這個來區分 [categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)]; //3.建立UIUserNotificationSettings,並設定訊息的顯示類型別 UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIRemoteNotificationTypeSound) categories:[NSSet setWithObjects:categorys, nil]]; [[UIApplication sharedApplication] registerUserNotificationSettings:notiSettings]; }else{ [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert]; } }