Turkcell Push Notification with Swift

Swift port of Obj C version. You can fork the project from https://github.com/selimanac/Turkcell-Swift-PushNotification

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let  userNotificationTypes: UIUserNotificationType = (.Alert | .Badge | .Sound)
        let settings:TCellNotificationSettings = TCellNotificationSettings(appId: "YOUR APP ID", secretKey: "YOUR SECRET KEY")
        let man:TCellNotificationManager = TCellNotificationManager.sharedInstance()
        man.notificationSettings = settings

        let userNotificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)

        UIApplication.sharedApplication().registerUserNotificationSettings(userNotificationSettings)
        UIApplication.sharedApplication().registerForRemoteNotifications()

        return true
    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        println("Notification Received")
    }

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        var token:NSString = deviceToken.description.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<>"))
        token = token.stringByReplacingOccurrencesOfString(" ", withString: "")

        println("Device Token: \(token)")

        TCellNotificationManager.sharedInstance().setNotificationDeviceTokenWithData(deviceToken)

        TCellNotificationManager.sharedInstance().registerDeviceWithCustomID("", genericParam: "genericParamTest", completionHandler: { (obj:AnyObject!) -> Void in

            if(obj.isKindOfClass(TCellRegistrationResult)){
                let result:TCellRegistrationResult =  obj as TCellRegistrationResult

                if(result.isSuccessfull){

                    println("Device is registered to push server.")
                } else {
                    println("Err: \(result.error.localizedDescription), Status Code: \(result.resultCode)")
                }

            }

        })

    }

    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        let str:NSString = NSString(format: "Error: ", error)
        println(str)
    }

}

Selim Anaç

Selim Anaç

More than 20 years of working experience at digital products as games/advergames, mobile & desktop apps and online software production. Multi-discipline software developer, team leader. A video game addict.