Nolex
October 11, 2016, 11:53am
1
Hello!
Problem class NotificationServices:
https://docs.unity3d.com/ScriptReference/iOS.NotificationServices.html
The problem is as follows:
Unable clear badge in iOS 10.
Unable clear text notifications in iOS 10.
Static function “ClearLocalNotifications ” is NOT working!
This terrible code (bad decisions) does not help to clear badge in iOS 10, but in iOS < 10 is working…
LocalNotification setCountNotif = new LocalNotification();
setCountNotif.applicationIconBadgeNumber = -1;
setCountNotif.hasAction = false;
NotificationServices.PresentLocalNotificationNow(setCountNotif);
The problem has been a long time:
RemoteNotification.applicationIconBadgeNumber is read only, which means I cannot change the badge locally. I know I gotta use the server to track the badge number. But the situation is, once I received the push notification and activate the app, I...
Community has found the bad decisions that still have solved this problem.
But now even these solutions do not help!
How to clear the received notification (badge and text)?
Upgrade please this class, there is clearly a problem!
Best,
Nolex
Nolex
October 13, 2016, 4:54pm
2
CancelLocalNotification. Also it does not work on IOS 10:
public static void PushLocalDelete(string key)
{
foreach(LocalNotification ln in NotificationServices.scheduledLocalNotifications)
{
if (ln.userInfo != null)
{
if (ln.userInfo.Contains("k"))
{
string notificationVal = ln.userInfo["k"].ToString();
if (notificationVal == key)
{
NotificationServices.CancelLocalNotification(ln);
}
}
}
}
}
EDIT: I made a mistake. CancelLocalNotification() works fine on iOS 10. But ClearLocalNotifications() does not work 100%.
Nolex
October 14, 2016, 1:53pm
3
The function ClearLocalNotifications() does not want to work in iOS 10!
I had to use an alternative - asset Ultimate IOS Notifications : Local And Push (25$).
I use only one function for clearing text and badges in native xcode:
-(void)clearAllNotification
{
NSLog(@"clearAllNotification");
[self applicationIconBadgeNumber:0];
[UIApplication sharedApplication].scheduledLocalNotifications = [UIApplication sharedApplication].scheduledLocalNotifications;
}
It works well, but a shame that the standard solutions from the Unity Team does not work.
Best,
Nolex.
wdFang
November 3, 2016, 2:56am
4
Nolex:
The function ClearLocalNotifications() does not want to work in iOS 10!
I had to use an alternative - asset Ultimate IOS Notifications : Local And Push (25$).
I use only one function for clearing text and badges in native xcode:
-(void)clearAllNotification
{
NSLog(@"clearAllNotification");
[self applicationIconBadgeNumber:0];
[UIApplication sharedApplication].scheduledLocalNotifications = [UIApplication sharedApplication].scheduledLocalNotifications;
}
It works well, but a shame that the standard solutions from the Unity Team does not work.
Best,
Nolex.
Hello Nolex,I had the same problem as your.did you solved the problem? if you did,can you tell me how did you solved it,thanks a lot.
Nolex
November 3, 2016, 9:52am
5
@wdFang , Hello!
I have not solved that. NotificationServices have bugs.
I use Objective-C function for clearing text and badges in native xcode…
By the way, I found another problem in NotificationServices (warning):
ios, parse-platform
wdFang
November 19, 2016, 7:35am
6
i see,i was also solved it by iOS applicationDelegate ,but it mean i had change it every time when i build a unity.and i was not found the problem you displayed on.what should i pay attention to?
Nolex
November 22, 2016, 6:33am
7
Hi @wdFang ,
I don`t understand your question.
Please clarify.
Thank you for sharing this @Nolex . Where did you put the native xcode? What class in the Xcode project? Thanks!
Nolex
January 16, 2017, 5:45pm
9
@SpiderJones ,
I use this functions from the plug-in Ultimate IOS Notifications .
Code from file Plugins\iOS\Notifications\LocalNotification.mm:
-(void)cancelNotificationById:(NSString*) notificationId
{
NSLog(@"Cancel notification by id: ");
NSLog(@"%@",notificationId);
UILocalNotification* notification = [self getNotificationById: notificationId];
if (notification) {
[self minusApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication]cancelLocalNotification:notification];
}
}
-(void)cancelAllNotification
{
NSLog(@"cancelAllNotification");
[self applicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
-(void)clearAllNotification
{
NSLog(@"clearAllNotification");
[self applicationIconBadgeNumber:0];
[UIApplication sharedApplication].scheduledLocalNotifications = [UIApplication sharedApplication].scheduledLocalNotifications;
}
I can’t share all the plugin files, because it would be rude to the creators.
1 Like
shochet
February 10, 2017, 1:49am
10
This seems like a Unity bug - did you file a report? I could not find anything related in Unity Issue Tracker…
Nolex
February 10, 2017, 8:24am
11
@shochet ,
I did no report. Only this topic.
spav
February 17, 2017, 2:22pm
12
I have the exact same problem with clearing notifications
FYI this issue seems to be fixed in 5.6.0p2
EDIT: Alas, I just tested and I cannot get this to work with 5.6.0p4 and the “original code” of just sending a local notification with negative applicationIconBadgeNumber
EDIT 2: HOWEVER, If I do a ClearLocalNotifications () and ClearRemoteNotifications(), the badge icon disappears. Hooray!
1 Like
I am using Unity 5.6.1f1. This should work, I’m gonna try, but I guess so:
UnityEngine.iOS.LocalNotification setCountNotif = new UnityEngine.iOS.LocalNotification();
setCountNotif.fireDate = System.DateTime.Now;
setCountNotif.applicationIconBadgeNumber = 0;
setCountNotif.hasAction = false;
NotificationServices.ScheduleLocalNotification( setCountNotif );
Nolex:
The function ClearLocalNotifications() does not want to work in iOS 10!
I had to use an alternative - asset Ultimate IOS Notifications : Local And Push (25$).
I use only one function for clearing text and badges in native xcode:
-(void)clearAllNotification
{
NSLog(@"clearAllNotification");
[self applicationIconBadgeNumber:0];
[UIApplication sharedApplication].scheduledLocalNotifications = [UIApplication sharedApplication].scheduledLocalNotifications;
}
It works well, but a shame that the standard solutions from the Unity Team does not work.
Best,
Nolex.
Where did you put the native xcode? What class in the Xcode project? @Nolex
Nolex
July 26, 2017, 8:52am
17
You need a create two files in Unity like this:
/Plugins/iOS/LocalNotification.mm
/Plugins/iOS/LocalNotificationObj.h
See docs: https://docs.unity3d.com/Manual/PluginsForIOS.html