0

Is it possible to update a view immediately after getting user permissions?

For example, I have a tableViewCell that asks the user if they would like to enable push notifications. If the user presses yes, it opens up the apple system prompt to enable Push notifications.

My question is, is there a way to update the cell right after the user presses "yes"?

Right now, it just goes back to the tableView, and the user has to manually refresh the tableView to make the "enableNotifications" cell go away (i have it checking to see if push notifications have been enabled), but I would like to automate this process right after the user taps yes on Apple's system dialog

Jeezy
  • 1
  • 1

4 Answers4

0

call tableView.reloadData() in the alert closure, or if you have a reference to the cell index you can update just that cell tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)

Haligen
  • 231
  • 1
  • 7
0

in iOS8 above, you can handle each action of UIAlertViewController

let alertController = UIAlertController(title: "UIAlertController", message: "Do you want to receive notification?", preferredStyle: .Alert)
    let ok = UIAlertAction(title: "Yes", style: .Default, handler: { (action) -> Void in
        print("Yes Button Pressed")
        // do any action here

    })
    let cancel = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in
        print("Cancel Button Pressed")
    }
    alertController.addAction(ok)
    alertController.addAction(cancel)

but below iOS8, should use UIAlertViewDelegate

xmhafiz
  • 3,482
  • 1
  • 18
  • 26
  • I'll double check, but I don't think we are using our own prompt, I believe we are using a delegate method provided by Apple that checks for Push Notifications. So I don't actually know if there is a way to change the functionality of the yes/cancel on their UIAlert – Jeezy Jun 16 '16 at 03:17
  • sorry, i my mistake, thought it is your custom setting for push, but it is the apple push notification native prompt. you can refer here http://stackoverflow.com/questions/25111644/detect-allow-notifications-is-on-off-for-ios8/25197833#25197833 – xmhafiz Jun 16 '16 at 03:32
0

Simply change your data in that you are assigning to cell in the function which is trigger when user touches yes button on any alert after this just call this function.

[tableView reloadData]; //Objc

OR

tableView.reloadData() //Swift
Syed Qamar Abbas
  • 3,637
  • 1
  • 28
  • 52
0

I am not sure about this but you can try this.

In Appdelegate.m class you can define two methods for Push notification are

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
// Call you code to update tableview for that ViewController.
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
// Show alert to user that you denied
 }

In addition, You can check programatically that user has given permission for push or not based on that you can manage you code and UI.

Not sure about this but hope this might help you.

Ajay Gabani
  • 1,168
  • 22
  • 38