2015-03-09 2 views
0

Как вы удалите пользователя от получения push-уведомлений с использованием синтаксического анализа? Например, если пользователь переходит к своим настройкам (в приложении) и решает отключить push-уведомления ...Удалить оповещения пользователя push iOS на Parse

Я думал, что удаление их «глобального» канала сделало бы трюк, но пользователь, похоже, все еще будет получить их. И подумайте об этом, если это сработает, они все равно смогут получить толки, отправленные на другие каналы, с которыми был связан пользователь. Во всяком случае, каково решение этого?

Я пробовал эти два подхода:

currentInstallation.channels = @[ @"global" ]; //enable 

currentInstallation.channels = @[]; //disable 

И

[currentInstallation addUniqueObject:@"global" forKey:@"channels"]; //enable 

[currentInstallation removeObject:@"global" forKey:@"channels"]; //disable 

Я тогда попытался отправки протолкнуть разбирает веб-интерфейс и для «всех» и только те, совпадающие с " глобальный "канал. Не повезло, пользователь все равно получил его.

Я в значительной степени последовал за инструкцией по настройке iOS Push. Это как мой implementaion выглядит:

-(void)displayPushAuthRequest{ 
    UIApplication *app = [UIApplication sharedApplication]; 
    if([app respondsToSelector:@selector(registerUserNotificationSettings:)] && [app respondsToSelector:@selector(registerForRemoteNotifications)]){ 
     //ios 8 
     UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | 
                 UIUserNotificationTypeBadge | 
                 UIUserNotificationTypeSound); 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes 
                       categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 
    { 
     //ios 7 
     UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; 

    } 

} 


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    // Save the settings locally (first time) 
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"didRegisterForRemoteNotifications"]; 
    [[NSUserDefaults standardUserDefaults]synchronize]; 

    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:deviceToken]; 
    currentInstallation.channels = @[ @"global" ]; 
    [currentInstallation saveInBackground]; 

} 
+0

Как вы подписываете пользователей на push-уведомления в didRegister? Кроме того, что-то принципиально неверно, если вы устанавливаете конкретный канал в консоли, но он все равно посылает им, то есть где-то фундаментальная ошибка. Кроме того, вы сохраняете 'removeObject: forKey:'? это не в вашем примере, поэтому я должен был спросить – soulshined

ответ

1

Вы можете попробовать на следующий подход

PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
currentInstallation.channels = [NSArray array]; 
[currentInstallation saveEventually]; 
+0

не работает. Я редактировал свое оригинальное сообщение, чтобы показать, что я пробовал до сих пор – royherma

0

Как я делаю с pasrse есть приложение AppDelegate объект, uuidDT является маркер устройства хранится в строке формиата в приложении делегата.

-(IBAction)notificationTapped:(UISwitch*)sender;

{ 

PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 

if (sender.isOn) 
{ 
    if ([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
    { 
     // iOS 8 Notifications 
      [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
     [currentInstallation setDeviceToken:app.uuidDT]; 
     [currentInstallation saveInBackground]; 
    } 
} 
else 
{ 
    [[UIApplication sharedApplication] unregisterForRemoteNotifications]; 
     [currentInstallation setDeviceToken:@""]; 
    [currentInstallation saveInBackground]; 
} 

} 

, как вы будете конвертировать маркер устройства в строку ниже ввести этот код в didRegisterForRemoteNotificationsWithDeviceToken в AppDelegate

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    NSString * deviceTokenString = [[[[deviceToken description]stringByReplacingOccurrencesOfString: @"<" withString: @""]stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    self.uuidDT=deviceTokenString; 

    [currentInstallation setDeviceToken:uuidDT]; 

    [currentInstallation saveInBackground]; 



} 

и его работает нормально .. может это не правильный путь. но каким-либо образом его работая .....

Смежные вопросы