İos üzerinde Objective-C ile bildirim oluşturma
Bildirim Kodunu Kendimize Göre Düzenleme:
Son olarak bildirimler için yetki ekleme:
Bu kodlar ile AppDelegate dosyanızdaki UserNotifications.framework dosyasını içe aktarın:
Daha sonrada bu kodu yazın:
Kod:
[COLOR="DarkOliveGreen"]#import <UserNotifications/UserNotifications.h>[/COLOR]
Kod:
[COLOR="DarkOliveGreen"][CENTER]#import <UserNotifications/UserNotifications.h>
[USER=64682]INTERFACE[/USER] AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
[USER=22515]end[/USER][/CENTER][/COLOR]
Daha sonra IOS sürüm kontrolü ayarlarını düzenleyeceğiz.Bunları yaparken IOS sürümüne göre yapın.Ben burda IOS 10 üzerinden yazacam
Kod:
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
Kod:
[CENTER][COLOR="DarkOliveGreen"]-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self registerForRemoteNotifications];
return YES;
}
- (****)registerForRemoteNotifications {
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
}
else {
// Code for old versions
}
}
[/COLOR][/CENTER]
Bildirim Kodunu Kendimize Göre Düzenleme:
Kod:
[CENTER][COLOR="DarkOliveGreen"]//Sadece uyarı bildirim çağrıldığında.
-(****)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(**** (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(@"User Info : %@",notification.request.content.userInfo);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
//Sizin kendinize göre düzenlediğiniz bildirim.
-(****)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(****(^)())completionHandler{
NSLog(@"User Info : %@",response.notification.request.content.userInfo);
completionHandler();
}[/COLOR][/CENTER]
Son olarak bildirimler için yetki ekleme:
Son düzenleme: