ios - UILocalNotification to open detail view controller for a specific item -
i'd set alerts specific items , have uilocalnotification
open specific item table view controller , display details. in other words, when notification appears i'd able tap on "show item" , instead of showing list of items i'd see details of specific item.
for work need store information on specific item (title, index, etc.) how can this? store title of item in uilocalnotification.userinfo
?
to add information
objective c
localnotification.userinfo =@{@"title":title,@"index":index};
swift
var userinfo = [string:string]() userinfo["title"] = title userinfo["index"] = index notification.userinfo = userinfo
to information when notification arrive
objective c
- (void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification { nslog(@“title = %@”,notification.userinfo[@"title"]); nslog(@“index = %@”,notification.userinfo[@"index"]); }
swift
func application(application: uiapplication!, didreceivelocalnotification notification: uilocalnotification!) { println(notification.userinfo?["title"]) println(notification.userinfo?["index"]) }
********edit********
passing "title" , "index" notification's userinfo table view controller
objective c
- (void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification { [[nsnotificationcenter defaultcenter] postnotificationname:@"booknotification" object:notification.userinfo] // or update table view data source }
swift
func application(application: uiapplication!, didreceivelocalnotification notification: uilocalnotification!) { nsnotificationcenter.defaultcenter().postnotificationname("booknotification", object:notification.userinfo) // or update table view data source }
in table view controller
add observer in when notification arrive "title" , "index" update table view controller
datasource
, reload tableview
inside table view controller
objective c
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(receivebooknotification:) name:@"booknotification" object:nil]; - (void) receivetestnotification:(nsnotification *) notification { nsstring *title = notification.userinfo[@"title"]; nsstring *title = notification.userinfo[@"index"]; // update data source , reload }
swift
nsnotificationcenter.defaultcenter().addobserver(self, selector: "receivebooknotification:", name:"booknotification", object: nil) func receivetestnotification(notification: nsnotification) { let title = notification.userinfo?["title"] let index = notification.userinfo?["index"] // update data source , reload }
Comments
Post a Comment