私のアプリでは、ネットワーク接続を使用してデータを取得しています
そのデータを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];
通知の onclick を処理するには:
- (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);
}
uilocalnotifications は非推奨だと思います。これで、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
{
}
}];