在我的应用程序中,我正在使用一些网络连接获取数据
我想在 iPhone 的通知栏(状态栏)中显示该数据
那么如何添加当我向下拖动时我可以在 iPhone 的状态栏中看到的数据
我搜索了很多教程,但我没有找到任何好的教程,请帮助我
请告诉我一些想法,我可以在通知或任何好的教程中管理我的数据
请建议任何好的教程,以便我可以在通知栏中管理我的动态数据
谢谢
在我的应用程序中,我正在使用一些网络连接获取数据
我想在 iPhone 的通知栏(状态栏)中显示该数据
那么如何添加当我向下拖动时我可以在 iPhone 的状态栏中看到的数据
我搜索了很多教程,但我没有找到任何好的教程,请帮助我
请告诉我一些想法,我可以在通知或任何好的教程中管理我的数据
请建议任何好的教程,以便我可以在通知栏中管理我的动态数据
谢谢
获取数据后:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = date; // date after 10 sec from now
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = text; // text of you that you have fetched
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
要处理通知的点击:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(@"Recieved Notification %@",localNotif);
}
return YES;
}
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
}
我认为,uilocalnotificatios 已被弃用。现在您可以使用 UNUserNotificationCenter。我们可以向其中添加图像,如下所示:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
[center requestAuthorizationWithOptions:options
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!granted) {
//NSLog(@"Something went wrong");
}
}];
int dayCounter =5;
int minute = 48;
{
NSDateComponents *components = [[NSDateComponents alloc] init];
components.weekday = dayCounter;
dayCounter++;
components.hour = 12;
components.minute = minute;
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];
objNotificationContent.title = [NSString localizedUserNotificationStringForKey:@"Notification!" arguments:nil];
objNotificationContent.body = [NSString localizedUserNotificationStringForKey:@"We made a surprise Edit for You" arguments:nil];
objNotificationContent.sound = [UNNotificationSound defaultSound];
objNotificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
UNNotificationAttachment *attachment = nil;
NSURL* outputURL = [[NSURL alloc] initFileURLWithPath:filePath];
NSError *attachmentError = nil;
attachment = [UNNotificationAttachment attachmentWithIdentifier:@"image"
URL: outputURL
options:nil
error:&attachmentError];
if (attachmentError) {
return;
}
objNotificationContent.attachments=@[attachment];
NSString *identifier = @"UYLLocalNotification";
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
content:objNotificationContent trigger: trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Something went wrong: %@",error);
}
else
{
}
}];