0
votes

I need to migrate an old app writen in Objective-C to Swift. This app uses IBM solution Silverpop for push notifications.

I am having some troubles during my migration with the Silverpop solution. The framework is written in Objective-C and when I follow the documentation or sample on GitHub (there is difference between doc and sample..) I cannot get the app to work.

The App crashes in main.swift that the documentation asked me to create with:

import Foundation
import UIKit

UIApplicationMain(CommandLine.argc, nil, nil, "MCEAppDelegate")

On launch the app crashes with:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)

Documentation : https://developer.ibm.com/customer-engagement/tutorials/getting-started-mobile-app-messaging-ios-apps/

Sample : https://github.com/ibm-mobile-push/ios/tree/master/samples/Swift%20Automatic%20Sample/SwiftSample

my MceConfig.json

{
    "baseUrl": "https://api.ibm.xtify.com/3.0/",
    "appKey": {
        "dev":"xxxx",
        "prod":"xxxx"
    },
    "appDelegateClass": "AppDelegate",
    "autoInitializeFlag": true,
    "sessionTimeout": 20,
    "metricTimeInterval": 180,
    "loglevel": "verbose",
    "logfile": false
}

Any help will be appreciated!

1
What does the console say when it crashes?EmilioPelaez
Nothing at all except the EXC_BAD_ACCESS .. I saw that this problem could be related to Objective-C bad memory access. But I don't know how to fix it because it's not my code but the IBM framework code.Emmanuel Loisance
According to the doc, you need so many setups. Have you done it properly? Please show your MceConfig.json (exclude appKey of course).OOPer
In UIApplicationMain, the first argument is the count of command line arguments that were passed to the function. The second argument is supposed to be a list of those arguments. In this case if CommandLine.argc is greater than zero then the second argument should not be nil. Could that be the case? What happens if you replace CommandLine.argc with 0?Scott Thompson
@ScottThompson black screen with 0, and there is the same main.swift content in the github sample.Emmanuel Loisance

1 Answers

0
votes

Your MceConfig.json is not following the doc and the note in the sample code.

Setting up the sample app that is included in the Mobile App Messaging SDK for iOS.

  1. Swift requires your class to be in a namespace. For this reason, if you are using the Swift Sample App, update the “appDelegateClass” value to “SwiftSample.AppDelegate”.

MceConfig.json in the sample code:

"Please note: if you are using a Swift based Application Delegate you must include the product name and class name in AppDelegateClass, for example": "SwiftSample.AppDelegate",
"appDelegateClass": "AppDelegate",

Try changing the line in your MceConfig.json From:

"appDelegateClass": "AppDelegate",

To:

"appDelegateClass": "YourAppProductName.AppDelegate",

(Replace YourAppProductName to the actual product name of your app.)