如何使用CloudKit查询调节条件? [英] How to condition segues using CloudKit query?

查看:47
本文介绍了如何使用CloudKit查询调节条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个由CloudKit备份的登录页面。
我想知道如果登录名具有特定值时如何创建条件序列,然后根据该值将用户定向到View Controller

I created a login page backed up by CloudKit. I want to know how to create a conditioned segue if the login has a certain value, and then direct the user to a View Controller based on that value

详细来说,我想连接三个Segues:

In details, I have three Segues I want to connect:


登录id segue: LoginSuccessSegue

人员标签栏ID segue: idStaffTabBar

staff tab bar id segue:idStaffTabBar

学生标签栏ID segue: idStudentTabBar

student tab bar id segue:idStudentTabBar

第一笔$
LoginSuccessSegue
登录视图控制器具有显示序列ID LoginSuccessSegue连接到职员选项卡栏控制器和学生选项卡栏

First Segue LoginSuccessSegue: the sign in view controller has a show segue id LoginSuccessSegue the connects to staff tab bar controller and student tab bar controller.

第二次Segue
idStaffTabBar :之后的
queryProfileType()执行后,它将在列表中查找配置文件类型,以检查用户配置文件是否为教师值或其他值。然后,如果是这样, LoginSuccessSegue将通过使用 segue idStaffTabBar`

Second Segue idStaffTabBar: After queryProfileType() is executed, it will look for the profile type in a list to check if the user profile is a teacher value or something else. Then if that is true "LoginSuccessSegue" will automatically take the user to staff tab bar controller, "StaffBookedVC.self" by usingits segueidStaffTabBar `

第三次
idStudentTabBar :如果用户不是老师,则按
,然后按通过使用idStudentTabBar或

Third Segue idStudentTabBar: if the user is not a teacher then after pressing the sign in button redirect to student tab bar controller, "stdBookingVC.self" by using idStudentTabBar or


将登录按钮重定向到学生标签栏控制器 stdBookingVC.self

How can I achieve an automatic conditional sign in in multiple views suing segues and cloud kit query?

这是登录按钮的代码:

@IBAction func btnSignInTapped(sender: UIButton)
{
    let userEmailAddress = userEmailAddressTextField.text
    let userPassword = userPasswordTextField.text


    if(userEmailAddress!.isEmpty || userPassword!.isEmpty)
    {
        notifyUser("Empty fields", message: "all fields are required")
    }
    print("fetching is in progress")

    queryProfileType()

    print("\nfetching had stopped")
}//end of signInbtn

func queryProfileType()
{
    queryCredentials()

    print("\nProfile Query starting")
    //execute query
    let organizers = ["Teacher || Youtuber || Instagrammer || "]
    let predicate = NSPredicate(format: "ProfileType = '\(organizers)' ")
    print("\nThis is the predicate\n\(predicate)")
    let query = CKQuery(recordType: "RegisteredAccounts", predicate: predicate)
    publicDatabase!.performQuery(query, inZoneWithID: nil) { results, error in
        if (error != nil)
        {
            print(error)
        }else
            {

                if (results! == organizers)
                {
                    self.performSegueWithIdentifier("idStaffTabBar", sender: StaffBookedVC.self)
                }else{
                    self.performSegueWithIdentifier("idStudentTabBar", sender: stdBookingVC.self)

                }
                print("\(results)\nthese are the printed results")
            }

        }
    let firstFetch = CKFetchRecordsOperation()
    let secondFetch = CKFetchRecordsOperation()
    secondFetch.addDependency(firstFetch)

    let queue = NSOperationQueue()
    queue.addOperations([firstFetch, secondFetch], waitUntilFinished: false)
}

这是情节提要剧集的图片故事板

here is a picture of the storyboard segues Storyboard

如果您的答案将包含以下方法,请向我展示一些示例:
shouldPerformSegueWithIdentifier和prepareForSegue

if your answer will contain these methods, please show me some examples: shouldPerformSegueWithIdentifier and prepareForSegue

这对我也不起作用

self.presentViewController(SignInNavigationVCTabBars, animated: true,
                { results, error in

                if (results! == organizers)
                {
                    self.performSegueWithIdentifier("idStaffTabBar", sender: StaffUITABbarVC.self)

                }else{
                    self.performSegueWithIdentifier("idStudentTabBar", sender: StdUITABbarVC.self)

                }
            }

`

推荐答案

这是答案


我没想到valueforkey会拥有全部
我能看到什么?永远不要停止尝试

I did not expect valueforkey would have it all what can I see? never stop trying



 //log in function
func queryCredentials()
{
    print("*********\nQueryCredentials starting")

    // System indicator
    let spinningActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
    spinningActivity.labelText = "Signing in"
    spinningActivity.detailsLabelText = "Please wait"


    // querying predicate in cloud kit to check via email and password property
    let predicate = NSPredicate(format: "Email = %@", userEmailAddressTextField.text!)
    let query = CKQuery(recordType: "RegisteredAccounts", predicate: predicate)
    publicDatabase?.performQuery(query, inZoneWithID: nil,
        completionHandler: ({results, error in

            if (error != nil)
            {
                dispatch_async(dispatch_get_main_queue())
                    {
                    // if the user is not signed, display this error
                    self.notifyUser("Cloud Access Error",
                        message: "to fix this error Sign in you icloud \n go to settings\nthen sign in icloud account\n error code:\(error!.localizedDescription)")
                    }
            }else
            {
                if (results!.count > 0)
                {
                    // the results after success case of the query
                    let record = results![0] as! CKRecord

                    // read from the result to navigate via profiletype attribute
                    let proftype = record.valueForKey("ProfileType") as! String

                    switch proftype
                    {
                    case("Teacher"):
                        self.staffView()
                        break;

                    case("Manager"):
                        self.staffView()
                        break;

                    case("Student"):
                        // stdView() is a student coded segue as a function to navigate to student view
                        self.stdView()
                        break;

                    case("Worker"):
                        self.stdView()
                        break;

                    default:
                        break;

                    }
                    self.currentRecord = record

                    dispatch_async(dispatch_get_main_queue())
                        {
                        // if credentials are correct, display you are logged in
                        self.userPasswordTextField!.text =
                            record.objectForKey("Password") as! String
                        self.notifyUser("Welcome", message: "You are loogedin")

                        }
                }else
                {
                    dispatch_async(dispatch_get_main_queue())
                        {
                        self.notifyUser("No Match Found",
                            message: "No record matching")
                        }
                }
            }

        }))
    // hiding indicator
    spinningActivity.hide(true)
}

这篇关于如何使用CloudKit查询调节条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆