iOS - Push Message

Aşağıdaki yöntem AppDelagate'nin didFinishLaunchingWithOptions yönteminde APNS sistemine uygulama kaydı için kullanılmalıdır:

Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert| UIUserNotificationTypeBadge| UIUserNotificationTypeSound) categories:nil];
        [application registerUserNotificationSettings:settings];
    } else {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }
}

 


Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	if #available(iOS 8.0, *) {
        let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        UIApplication.shared.registerUserNotificationSettings(settings)
        UIApplication.shared.registerForRemoteNotifications()
    } else {
        UIApplication.shared.registerForRemoteNotifications(matching: ([.badge, .sound, .alert]))
    }
}


Kullanıcılara push mesaj göndermek için RMC sunucularının Token alması gerekir. Bu customEvent yöntemini başarmak için OM.sys.AppID ve OM.sys.TokenID parametrelerini iletmek gerekir. OM.sys.AppID parametresinin değerini öğrenmek için RMC destek ekibiyle iletişime geçiniz. APNS tarafından üretilen token değeri OM.sys.TokenID anahtarının değeri olacaktır.

Objective-C
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *tokenString = [[[deviceToken description] stringByTrimmingCharactersInSet:
                              [NSCharacterSet characterSetWithCharactersInString:@"<>"]]
                             stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:tokenString forKey:@"OM.sys.TokenID"];
    [dic setObject:@"AppID" forKey:@"OM.sys.AppID"];
    [[Visilabs callAPI] customEvent:@"RegisterToken" withProperties:dic];
}
Swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let deviceTokenString : String = deviceToken.map{ String(format: "%02x", $0) }.joined().replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "");  
        var properties = [String:String]()
        properties["OM.sys.TokenID"] = deviceTokenString
        properties["OM.sys.AppID"] = "AppID"
        Visilabs.callAPI().customEvent(@"RegisterToken", withProperties: dic)
    }



Ana Başlık: iOS - SDK


Copyright 2020 Related Digital