ios - iPhone how to access the notification center programmatically -
as per apple guide:
if application icon tapped on device running ios, application calls same method, furnishes no information notification . if application icon clicked on computer running
as far have known, seems not able detect notification when application icon tapped.
so tried retrieve notification center programmatically seems impossible.
is impossible retrieve notification center programmatically?
what want detecting whether notifications received or not when application in background.
is impossible retrieve notification center programmatically?
no, it's not possible public api.
your app agnostic current state of notification center, 2 decoupled entities.
anyway, noted adamg, in ios 7 can implement
application:didreceiveremotenotification:fetchcompletionhandler:
which, according documentation, called regardless of state of app (so when it's not running or in background).
in order use it, have support remote-notification
background mode. here's how:
in xcode 5 , later, declare background modes app supports capabilities tab of project settings. enabling background modes option adds uibackgroundmodes key app’s info.plist file. selecting 1 or more checkboxes adds corresponding background mode values key.
now, while still cannot programmatically access notification center, can track notifications come.
an mocked implementation go follows:
- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult))completionhandler { // hey got notification! // have 30 seconds whatever like... // ...and have call completion handler completionhandler(uibackgroundfetchresultnodata); }
Comments
Post a Comment