[英]Remove user push notifications iOS on Parse
您将如何使用解析将用户从接收推送通知中删除? 例如,如果用户转到其设置(在应用程序内)并决定关闭推送通知...
我以为删除他们的“全局”频道可以解决问题,但用户似乎仍然可以使用它们。 并考虑一下,如果确实可行,他们仍然可以将推送发送到与用户关联的其他渠道。 无论如何,对此有什么解决方案?
我尝试了以下两种方法:
currentInstallation.channels = @[ @"global" ]; //enable
currentInstallation.channels = @[]; //disable
和
[currentInstallation addUniqueObject:@"global" forKey:@"channels"]; //enable
[currentInstallation removeObject:@"global" forKey:@"channels"]; //disable
然后,我尝试为“所有人”和仅与“全局”频道匹配的用户发送“通过解析” Web UI。 运气不好,用户仍然收到了它。
我几乎遵循了Parse iOS Push设置教程。 这是我的实现外观:
-(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];
}
你可以通过以下方法尝试
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.channels = [NSArray array];
[currentInstallation saveEventually];
如何处理pasrse,app是appdelegate对象,uuidDT是在应用程序委托方法中存储在字符串formate中的设备令牌。
-(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];
}
}
下面将如何将设备令牌转换为字符串,请在appdelegate的didRegisterForRemoteNotificationsWithDeviceToken中输入此代码
- (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];
}
和它的工作正常..可能这不是正确的方法。 但无论如何它的工作.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.