我用了下面的推-呼-斯威夫特密码,但它崩溃了。

        if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")))
        {
            application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
        }
        else //iOS7
        {
            application.registerForRemoteNotificationTypes( UIRemoteNotificationType.Badge |
                UIRemoteNotificationType.Sound |
                UIRemoteNotificationType.Alert )
        }

     var pushManager:PushNotificationManager  = PushNotificationManager.pushManager();
    pushManager.delegate = self;

    // handling push on app start
    PushNotificationManager.pushManager().handlePushReceived(launchOptions);

    // make sure we count app open in Pushwoosh stats
    PushNotificationManager.pushManager().sendAppOpen();

    // register for push notifications!
    PushNotificationManager.pushManager().registerForPushNotifications();

    UIApplication.sharedApplication().applicationIconBadgeNumber = 1;
    UIApplication.sharedApplication().applicationIconBadgeNumber = 0;

这是截图:
错误:EXE_BAD_INSTRUCTION对于var pushManager:PushNotificationManager = PushNotificationManager.pushManager()

最佳答案

除非你从the documentation开始遵循这些重要步骤:
将Pushwoosh.framework添加到项目中。
将-ObjC标志添加到项目中的链接器标志。
在Info.plist中,使用Pushwoosh Application ID字符串值添加以下键Pushwoosh\u APPID
…那么很可能您的问题是PushNotificationManager.pushManager()返回nil,这将在您尝试将结果分配给非可选值时导致运行时错误。

关于iphone - Pushwoosh:Swift代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27543006/

10-09 02:34