Remove push from notificationcenter after app has been opened - apple-push-notifications

When I send out a PUSH notification to my app, it stays in the notification center in iOS 5.
How can I remove the notification from the notification center from within the app?

Clearing the badge clears the notifications from the notification center.
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Clear application badge when app launches
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
This only works if the number changes. So to make it work in case badge is already zero, set it to some value and clear it again after a delay.
- (void)applicationWillEnterForeground:(UIApplication *)application {
if([[UIApplication sharedApplication] applicationIconBadgeNumber] == 0)
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Clear application badge when app launches
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Doesn't work if you set and clear in the same method.

It is not possible to remove the notification from the notification center from within the app because in iOS5, notifications properties are displayed by apps, in :
Settings -> Notifications -> The app -> Notification Center (YES/NO).

Related

ios 8 Push notification not opening app from background (Pushkit)

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
viewcontroller2 *historyVC = [storyboard instantiateViewControllerWithIdentifier: #"second"];
self.window.rootViewController = historyVC;
[self.window makeKeyAndVisible];
}
My app not opening from background to foreground but as per apple doc they said app will be come foreground.
The following method
- pushRegistry:didUpdatePushCredentials:forType:
is invoked when push notification is received.
until and unless user launches the app, we cant open the app.
when u open app. make preferences to show your respective view controller.
Using push kit, newer your app will get open automatically. that would not come to foreground from background or terminated state.
Your app will only gets active in background mode for some 30 seconds and you would be able to do rest of work whichever is needed. ( For example setting some values in Database etc )

Handoff not working from native app to website

My devices:
iPad Mini (latest), iOS 8 dp5.
Macbook Air, Yosemite dp5.
I have Handoff working between the two above devices. Safari, Mail, Messages, Calendar, etc. all handoff with no problems.
I can even handoff between my website on the Air and my native app on the iPad.
What I can't do yet is go from my native app on the iPad to my website in Safari on my Air.
For the first view controller that loads in my native app, I have this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:#"com.myApp.iphone.staging.webbrowsing"];
webHandoff.webpageURL = [NSURL URLWithString:#"http://staging.myApp.com"];
[webHandoff becomeCurrent];
}
In my app's Info.plist file, I have this:
<key>NSUserActivityTypes</key>
<array>
<string>com.myApp.iphone.staging.webbrowsing</string>
</array>
Am I missing something or do I have something configured incorrectly?
Thanks for any help!
I made two significant changes to my code:
1) configure/destroy and set the NSUserActivity object in viewDidAppear/disappear as opposed to viewDidLoad:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:#"com.myApp.iphone.staging.web-browsing"];
webHandoff.webpageURL = self.handoffWebpageURL;
[self setUserActivity:webHandoff];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.userActivity invalidate];
}
2) Since UIViewController is a subclass of UIResponder and UIResponders have a userActivity property, instead of calling [webHandoff becomeCurrent] I simply called [self setUserActivity:webHandoff];
Not sure why moving it out of viewDidLoad had any impact, and not sure why I need to set it to the viewController's instance of NSUserActivity, but the changes above give me a solid and reliable handoff experience throughout my entire app.

How to prevent setting of [NSApp dockTile] badgeLabel value that is set not by my code?

I have a push notifications with badge, sounds and alerts enabled.
If the program is not running - everything is fine. But when the program is running - I need to block all sounds, alerts and badges that are not generated by program, because I have a live connection to my server and receiving all events before APNS sends notifications to my mac device.
I've found the way to hide alerts, but I couldn't find any way to take over control on dockTile's icon badge.
if i do this:
-(void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[NSApp dockTile] setBadgeLabel:nil];
}
nothing is happened, the badge that is set by APNS still persists. I tried to KVO on badgeLabel or dockTileNumber property as shown here, but observeValueForKeyPath:ofObject:change:context: is never called. How do APNS sets the badgeLabel? Maybe I am doing something wrong and there is a correct way to disable alerts/sounds/badges when the program is running?
Since i did not found any solutions to do it correctly, i will accept my workaround:
-(void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[application dockTile].badgeLabel = #" ";
[application dockTile].badgeLabel = #"";
}
Alerts may be disabled via NSUserNotificationCenterDelegate delegate method userNotificationCenter:shouldPresentNotification::
-(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
//apple push notification alert will contain userInfo with aps payload, so disable here
if (notification.userInfo[#"aps"])
return NO;
return YES;
}
I haven't found any ways to disable sounds.

App won't open after clicking on remote notification'

I have a Problem with remote notifications and OSx 10.8.
I enabled the remote push notifications successful. They also were delivered to my system, but when I try to click one nothing happens.
Also for this app update I had to enable sandboxing!
The Mac-Console log:
29.08.12 11:03:50,600 usernoted[194]: Cannot find originating application to launch for event action. file://localhost/Users/clueckler/Library/Developer/Xcode/DerivedData/mysms_OSX_Client-bcaianxrdhpztmdcnsrgzqdtqmvi/Build/Products/Debug/mysms_test.app/ is not the same app as the one that sent the original notification.
29.08.12 11:03:50,600 usernoted[194]: Error finding application com.mysms.osx.client.test.
I thought it was a problem of the AdHoc-Test or something. So I tried to submit it to the AppStore with success!
But the same problem appears with the AppStore Version (now I removed it from store ...)
Is there a solution for this problem?
EDIT (Code Information):
- (void)awakeFromNib {
// Register app for remote notification
[[NSApplication sharedApplication] registerForRemoteNotificationTypes:(NSRemoteNotificationTypeBadge | NSRemoteNotificationTypeSound | NSRemoteNotificationTypeAlert)];
}
- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//Post token to server
}

Push Notifications - registerForRemoteNotification FAILED

I tried to get my app ready for Push Notifications, I insert the following code in the app delegate but when I running the App on my Device (iPhone 3Gs - iOS 5.1.1) the app start's normal but whiteout the "Push Alert" how asks the user to allowed notifications!!!
Can someone help??
Best regards from Germany!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
// Override point for customization after application launch.
return YES;
}
you have to create a new appID in the iOS Provisioning Portal (without a wild-card character) like
com.yourcompanyname.yourappname
and enable push notifications for this app id.
Then create a new provisioning profile which you use to build your app. It should work then!
Be sure to change you bundle id in your project settings too.
Hope this helps.

Resources