2016-06-23 14 views
0

私は、プッシュ通知のボタンを表示するためにthis tutorialに従った。
登録通知didFinishLaunchingWithOptionsに登録してボタンを登録します。
しかし、ほとんどの場合、ボタンなしで簡単な通知を表示する必要があります。さまざまな通知のボタンを表示/非表示にする方法は?対話型プッシュ通知 - 非表示/表示ボタン

+0

notification.category = "値" アクト:

そして通知をスケジュールします。 without without notification.category = "value"通常のローカル通知として動作します。 –

答えて

2

私はこれがあなたに役立つことを願っています。

 
Parameter Description. 
    userInfo --> dictionary value for user needs. 
    title --> notitification Title. 
    fireDate --> trigger notification date and time. 
    Interactive -> pass flag to set Interactive or normal notification. 
-(void)setLocalnotfication:(NSDictionary *)userInfo title:(NSString *)title date:(NSDate *)fireDate Interactive : (BOOL)flag { 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.fireDate = fireDate; 
    notification.alertBody = title; 
    notification.timeZone = [NSTimeZone defaultTimeZone]; 
    notification.soundName = UILocalNotificationDefaultSoundName; 
    if(flag) notification.category = @"Category name"; 
    if([userInfo isKindOfClass:[NSDictionary class]]) notification.userInfo = userInfo; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

} 

私はそれを作成するには、このコードを使用しています。

、あなたがUIUserNotificationSettings更新する必要がありますなしボタンでインタラクティブな通知の別の種類を追加するための

func setLocalnotfication(userInfo: [NSObject : AnyObject], title: String, date fireDate: NSDate, Interactive flag: Bool) { 
    var notification: UILocalNotification = UILocalNotification() 
    notification.fireDate = fireDate 
    notification.alertBody = title 
    notification.timeZone = NSTimeZone.defaultTimeZone() 
    notification.soundName = UILocalNotificationDefaultSoundName 
    if flag { 
    notification.category = NCI 
    } 
    if (userInfo is NSDictionary.self) { 
    notification.userInfo = userInfo 
    } 
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 
} 

Refer the Website

3

より迅速。

いずれかのボタンのない新しい通知カテゴリUIMutableUserNotificationCategory作成:既存のUIUserNotificationSettingsにこの新しいカテゴリを追加し、その後

UIMutableUserNotificationCategory *newNotificationCategory = [[UIMutableUserNotificationCategory alloc] init]; 
newNotificationCategory.identifier = @"no_button_id"; 

を:

NSMutableArray *arrNewCategories = [NSMutableArray new]; 
    UIUserNotificationSettings *oldSettings = [[UIApplication sharedApplication]currentUserNotificationSettings]; 
    for (UIMutableUserNotificationCategory *oldCategory in oldSettings.categories) 
    { 
     if (![oldCategory.identifier isEqualToString:newNotificationCategory.identifier]) 
      [arrNewCategories addObject:oldCategory]; 
    } 
    [arrNewCategories addObject:newNotificationCategory]; 

    UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 
    UIUserNotificationSettings *newSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:[NSSet setWithArray:arrNewCategories]]; 

    [[UIApplication sharedApplication] registerUserNotificationSettings:newSettings]; 

だけnewNotificationCategoryの識別子があなたと一致することを確認してくださいあなたがボタンを必要としないUILocalNotificationのカテゴリ。インタラクティブ通知として

UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:afireDate]; 
localNotification.alertBody = @"alert body text"; 
localNotification.category = @"no_button_id"; // Same as category identifier 
localNotification.timeZone = [NSTimeZone systemTimeZone]; 
localNotification.soundName = SOUND_FILE; 
localNotification.repeatInterval = 0; 
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; 
+0

これは正しい方法です!ありがとう兄貴 – iTSangar

関連する問題