Skip to content

Commit 8a41799

Browse files
committed
增加基于日期的通知推送
1 parent 3ff1f92 commit 8a41799

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

Plugins/CS/Notification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class Notification
88

99
[DllImport("__Internal")] static extern void Notification_Initialize();
1010
[DllImport("__Internal")] static extern void Notification_PushNotification(string msg, string title, string identifier, int delay, bool repeats);
11-
[DllImport("__Internal")] static extern void Notification_PushNotification_Date(string msg, string title, string identifier, string date, ulong units, bool repeats);
11+
[DllImport("__Internal")] static extern void Notification_PushNotification_Date(string msg, string title, string identifier, long year, long month, long day, long hour, long minute, long second, ulong units, bool repeats);
1212
[DllImport("__Internal")] static extern void Notification_RemovePendingNotifications(string identifier);
1313
[DllImport("__Internal")] static extern void Notification_RemoveAllPendingNotifications();
1414

@@ -47,7 +47,7 @@ public static void PushNotification(string msg, string title, string identifier,
4747
public static void PushNotification(string msg, string title, string identifier, NSDateComponents dateComp, bool repeats)
4848
{
4949
Notification_PushNotification_Date(msg, title, identifier,
50-
dateComp.date.ToString("yyyy-MM-dd HH:mm:ss"),
50+
dateComp.date.Year, dateComp.date.Month, dateComp.date.Day, dateComp.date.Hour, dateComp.date.Minute, dateComp.date.Second,
5151
(ulong)dateComp.components,
5252
repeats);
5353
}

Plugins/Native/Headers/Notification.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ extern "C"
3131
delay:(NSInteger)delay
3232
repeats:repeats];
3333
}
34-
void Notification_PushNotification_Date(const char *msg, const char *title, const char *identifier, const char *date, NSCalendarUnit units, bool repeats)
34+
void Notification_PushNotification_Date(const char *msg, const char *title, const char *identifier, long year, long month, long day, long hour, long minute, long second, NSCalendarUnit units, bool repeats)
3535
{
3636

37-
38-
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
39-
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
40-
NSDate *nsDate = [formatter dateFromString:[NSString stringWithUTF8String:date ?: ""]];
37+
NSDate *nsDate = DateFromLong(year, month, day, hour, minute, second);
4138
NSDateComponents *components = [[NSCalendar currentCalendar] components:units fromDate:nsDate];
4239

4340

Plugins/Native/Utils.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ static void LOG(NSString* log){
2222
return newString;
2323
}
2424

25+
static NSDate* DateFromLong(long year, long month, long day, long hour, long minute, long second)
26+
{
27+
NSDateComponents *components = [[NSDateComponents alloc] init];
28+
components.year = year;
29+
components.month = month;
30+
components.day = day;
31+
components.hour = hour;
32+
components.minute = minute;
33+
components.second = second;
34+
NSCalendar *calendar = [NSCalendar currentCalendar];
35+
NSDate *date = [calendar dateFromComponents:components];
36+
return date;
37+
}
38+
39+
2540
typedef void (*SaveImageToAlbumCallback)(bool);
2641
typedef void (*ShareCloseCallback)();
2742
typedef void (*FileSavedCallback)(bool);

0 commit comments

Comments
 (0)