-2

这里我对如何将 Infobip SMS 网关集成到 iOS Swift 项目中存在疑问。我是 iOS Swift 的新手,所以我不清楚这个概念。

如何在 Whatsapp 等应用程序中检查注册手机号码的短信接收条件。在这里,我给出了我在项目中尝试过的内容。

var post:NSString = "username=\(self.appDelegate.username)&password=\(self.appDelegate.password)&gsm=\(self.appDelegate.gsm)&text=\(self.appDelegate.text)&recipients=\(self.appDelegate.recipients)&sender=\(self.appDelegate.sender)"

    NSLog("PostData: %@",post);

    var url1:NSURL = NSURL(string: "http://api.infobip.com/api/v3/sendsms/json")!

    var postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!

    var postLength:NSString = String( postData.length )

    var request:NSMutableURLRequest = NSMutableURLRequest(URL: url1)
    request.HTTPMethod = "POST"
    request.HTTPBody = postData
    request.setValue(postLength, forHTTPHeaderField: "Content-Length")
    request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
    request.setValue("application/json", forHTTPHeaderField: "Accept")


    var reponseError: NSError?
    var response: NSURLResponse?

    var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&reponseError)

    if ( urlData != nil ) {
        let res = response as NSHTTPURLResponse!;

        NSLog("Response code: %ld", res.statusCode);

        if (res.statusCode >= 200 && res.statusCode < 300)
        {
            var responseData:NSString  = NSString(data:urlData!, encoding:NSUTF8StringEncoding)!

            NSLog("Response ==> %@", responseData);

            var error: NSError?

            let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary


            let status: NSString? = jsonData.objectForKey("status") as? NSString
            let tmp: NSString? = "success"
            let tmm: NSString? = "already register"

            NSLog("Success: %ld", status!);

            if(status == "success")
            {
                NSLog("Login SUCCESS");

                let VerificationcodeViewController = self.storyboard?.instantiateViewControllerWithIdentifier("verificationcodeViewController") as UIViewController

                self.navigationController?.pushViewController(VerificationcodeViewController, animated: true)
            }else if(status == "already register")
            {
                NSLog("Login failed");
                var alertView:UIAlertView = UIAlertView()
                alertView.title = " Already Exists"
                alertView.message = "Enter a new mail id"
                alertView.delegate = self
                alertView.addButtonWithTitle("OK")
                alertView.show()
            }

            else {

                NSLog("Login failed1");
                var alertView:UIAlertView = UIAlertView()
                alertView.title = " Wrong Email"
                alertView.message = "Invalid Email"
                alertView.delegate = self
                alertView.addButtonWithTitle("OK")
                alertView.show()
            }

        } else {

            NSLog("Login failed2");

        }
    } else {

        NSLog("Login failed3");
    }
4

1 回答 1

1

我相信你需要2FA 库,而不是纯短信发送!

以下是什么是2FA及其工作原理的详细信息。

于 2015-04-21T07:54:01.843 回答