c# - iOS open page from local notification -
i have local notification firing specified time in os10 using unusernotificationcenter. i'm trying figure out how open specific page in app when user taps on local notification.
anyone how i'm new programming ios in c# , i'm sure not uncommon of thing do.
undelegate _delegate; public override uiwindow window { get; set; } public override bool finishedlaunching(uiapplication application, nsdictionary launchoptions) { unusernotificationcenter center = unusernotificationcenter.current; _delegate = new undelegate(); center.delegate = _delegate; center.requestauthorization(unauthorizationoptions.alert, (bool a, nserror error) => { }); center.getnotificationsettings((unnotificationsettings setting) => {}); registernotification(); return true; } public void registernotification() { unmutablenotificationcontent content = new unmutablenotificationcontent(); content.body = "body"; content.title = "title"; content.sound = unnotificationsound.default; nsdatecomponents components = new nsdatecomponents(); components.weekday = 2; components.hour = 8; uncalendarnotificationtrigger trigger = uncalendarnotificationtrigger.createtrigger(components, true); unnotificationrequest request = unnotificationrequest.fromidentifier("abc", content, trigger); unusernotificationcenter.current.addnotificationrequest(request, (nserror error) => { }); } public class undelegate : unusernotificationcenterdelegate { public override void willpresentnotification(unusernotificationcenter center, unnotification notification, action<unnotificationpresentationoptions> completionhandler) { completionhandler(unnotificationpresentationoptions.sound | unnotificationpresentationoptions.alert); } public override void didreceivenotificationresponse(unusernotificationcenter center, unnotificationresponse response, action completionhandler) { appdelegate app = (appdelegate)uiapplication.sharedapplication.delegate; app.window.rootviewcontroller.presentviewcontroller(new viewcontroller1(), true, null); } } unusernotificationcenter.current
get singleton instance of unusernotificationcenter
delegate
receive events unusernotificationcenter
willpresentnotification: called deliver notification application running in foreground. if want show notification in foreground, refer code , display sound , alert content.
didreceivenotificationresponse :called after user selects action notification app. when yo tap notification , enter app, function called. open specific page in first post.
requestauthorization
requests notifcation authorization specified options, , processes result of request.requesting authorization required of apps support delivery of notifications. first time app requests authorization, user alerted , given opportunity deny or grant authorization.
getnotificationsettings
returns notification settings object app, processing before returned.
unmutablenotificationcontent
system-generated object contains parts of notification, including text, sound, badge , launch images, attachments, , on. shown in notification.
uncalendarnotificationtrigger
triggers delivery of notification @ specified day or time, either once or repeatedly. send notification @ 8:00 on monday in code.
unnotificationrequest
contains content , trigger notification developer requests unusernotificationcenter..
addnotificationrequest
adds local notification specified request, specified completionhandler.
there still many functions , classes don't mentioned . e.g,
unnotificationattachment(audio, video, or images displayed notifications.) unnotificationaction (an action can performed in response notification.) unnotificationcategory (implements group of actions , options comprise category of notifications.)
but requirement can meet code. more information
Comments
Post a Comment