iOS Users
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 3
- Joined: Thu Oct 11, 2012 10:32 pm
iOS Users
I am very new to LiveCode and iOS. I am wondering if someone would consider posting an example of how to manage users in iOS. Specifically, create a user, manage data associated with that user, and then delete the user when no longer needed. I have reviewed the files and folder entries in the dictionary, but am just not putting it together.
Re: iOS Users
Hello shartfield,
Try these commands...

Best,
~ Ender Nafi
Try these commands...

Best,
~ Ender Nafi
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
Re: iOS Users
And here is a very simple implementation of that 8 commands.
Hope it helps...
Best,
~ Ender Nafi
Hope it helps...
Best,
~ Ender Nafi
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
Re: iOS Users
Hi shartfield,
as you can see, this is a VERY lively forum, so you better look here more often
But first of all, please tell us if you really mean USERS (iOS is a single user OS)
or ENTRIES in the current users "Contacts" (Address Book)
Or if you want to provide a way to let more than one user use your app on the
same device, which is surely possible!
Best
Klaus
as you can see, this is a VERY lively forum, so you better look here more often

But first of all, please tell us if you really mean USERS (iOS is a single user OS)
or ENTRIES in the current users "Contacts" (Address Book)

Or if you want to provide a way to let more than one user use your app on the
same device, which is surely possible!
Best
Klaus
Re: iOS Users
Did I misunderstood shartfield's question?
Well, sorry then
~ Ender Nafi
Well, sorry then

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
-
- Posts: 3
- Joined: Thu Oct 11, 2012 10:32 pm
Re: iOS Users
Thanks for all of your responses. This is what I am asking…. Imagine you have a game on a single iPad and you want to be able to allow several people to play it, and save the game state for each person. Only one person plays at a time, but any of the “users” can pick up where they left off to continue playing. How would you create each of the users? I think saving the game state will be easy – just write to a data file, right? But then how would you associate each preference file to a user?
Re: iOS Users
Hi shartfield,
AHA
On the first card of your app you should provide a list (field) for all users and a button to create a new user.
User clicks his name (forcing unique name is mandatory!) and you create a folder with this name in
-> specialfolderpath("documents")
and save the highscore etc. in that folder.
Use a global variable of a custom property to store like this:
Then save your stuff like this:
Hint: To delete a folder you first have to delete its contents = all files, before you can delete that folder
Well, that's it basically
Best
Klaus
AHA

On the first card of your app you should provide a list (field) for all users and a button to create a new user.
User clicks his name (forcing unique name is mandatory!) and you create a folder with this name in
-> specialfolderpath("documents")
and save the highscore etc. in that folder.
Use a global variable of a custom property to store like this:
Code: Select all
...
put specialfolderpath("documents") & "/" & the_selected_user_name_in_user_list & "/" into tCurrentUserFolder
if there is not a folder tCurrentUserFolder then
create folder tCurrentUserFolder
end if
set the cCurrentUserFolder of this stack to tCurrentUserFolder
...
Code: Select all
...
put the cCurrentUserFolder of this stack into tCurrentUserFolder
put tHighScore into url("file:" & tCurrentUserFolder & "highscore")
## And/or whatever you need to store for a user...
...
Well, that's it basically

Best
Klaus
-
- Posts: 3
- Joined: Thu Oct 11, 2012 10:32 pm
Re: iOS Users
Thank you very much! This is very helpful.
Re: iOS Users
I have been playing around with this topic am hoping someone will be willing to take a look at the sample stack I have attached. I have broken it down into 5 steps to help me think it through better. I am certain there is a better way to accomplish this. Also, I really am not understanding the custom properties - I can see the changes in the property inspector but how are they referencing to the user? Are the custom properties a global variable that has to be declared in each script?
Create User - Creates a new user; Checks to make sure the new user doesn't exist, Creates the user folder
Delete User - Deletes the user
Save User - Saves user data
Open User Data - Switches to display the current user data
Change User - Changes the user by switching the folder
Delete User - I can delete the user in the display field but the folders and file(s) aren't deleting
Thanks in advance for your help.
Create User - Creates a new user; Checks to make sure the new user doesn't exist, Creates the user folder
Delete User - Deletes the user
Save User - Saves user data
Open User Data - Switches to display the current user data
Change User - Changes the user by switching the folder
Delete User - I can delete the user in the display field but the folders and file(s) aren't deleting
Thanks in advance for your help.
- Attachments
-
- User Management.livecode.zip
- (2.82 KiB) Downloaded 288 times
Re: iOS Users
Just had time to look at one of your scripts (create user) follows is some commented replacement code.
For your usercheck you can do it with 2 lines. (as indicated in script below)
set the wholematches to true (will force a check of the whole line. Whole line must match or its a non-match)
then lineoffset
get lineoffset(valueToLookFor,linesToCheckAgainst)
if it > 0 then a match was found, the user already exists.
As always I am sure there are cleaner ways to do this. If so, others will most likely chime in. (Will look at it more tomorrow probably after I crash for a while)
For your usercheck you can do it with 2 lines. (as indicated in script below)
set the wholematches to true (will force a check of the whole line. Whole line must match or its a non-match)
then lineoffset
get lineoffset(valueToLookFor,linesToCheckAgainst)
if it > 0 then a match was found, the user already exists.
As always I am sure there are cleaner ways to do this. If so, others will most likely chime in. (Will look at it more tomorrow probably after I crash for a while)
Code: Select all
on mouseUp
set the wholematches to true -- used to force lineoffset below to match only whole lines
Ask "Create New User"
if it is not empty then -- if it is empty nothing is done. Outermost if.
put it into sNewUser -- otherwise dump the value into sNewUser. Doesn't really need to be a scriptlocal, its a single use var
if lineoffset(sNewUser,field "field") > 0 then -- check lineoffset to see if user already exists
answer error merge("User [[sNewUser]] already exists!") -- if lineoffset is > 0 there was a match, show the error
exit mouseup -- and exit the mouseup doing nothing further
else -- if the user is new, add it to the field, make sure the last line is hilited
adduser sNewUser -- could put the adduser routine inline here. Either works.
get createUserDir(sNewUser) -- called as a function passing the username variable.
if it is not "true" then answer error "There was an error: " & it -- checks for error returned by createUserDir
end if
end if
end mouseUp
command adduser pUser
put the number of lines of field "Field" into tLineCount
put pUser into line tLineCount + 1 of card field "Field"
set the hilitedlines of field "field" to (tLineCount + 1) -- make sure the last line added is hilited
end adduser
function createUserDir pUser
put specialfolderpath("documents") & "/" & pUser & "/" into tCurrentUserFolder
if there is not a folder tCurrentUserFolder then
create folder tCurrentUserFolder
if the result is not empty then return the result --if the command returns some unknown error, return it
return true -- otherwise return true
else
return "Folder already exists!" -- return custom error if folder is already there.
end if
end createUserDir
Re: iOS Users
Just noticed a few issues with the delete user. First, you "put the files" into a variable so that you can iterate through them and delete, but you don't set the defaultfolder to point to the right place, so you're risking deletion of all kinds of files in a potentially unspecified location.
Then your repeat loop repeats with x = 1 to the number of lines..
and you delete file x. In this case x contains a number not the name of a file.
You would have to do "delete file (line x of myVariable) to get it to work that way. That way (line x of my variable) evaluates to a file name.
Its probably easier to use a repeat for each type of loop in this case.
However, make DARN sure you're deleting from the right place.
Follows is an adjusted (but untested) script for the user deletion button.
Then your repeat loop repeats with x = 1 to the number of lines..
and you delete file x. In this case x contains a number not the name of a file.
You would have to do "delete file (line x of myVariable) to get it to work that way. That way (line x of my variable) evaluates to a file name.
Its probably easier to use a repeat for each type of loop in this case.
Code: Select all
repeat for each line tLIne in myVariable
delete file tLine
end repeat
Follows is an adjusted (but untested) script for the user deletion button.
Code: Select all
on mouseUp
put the hilitedLine of fld "Field" into lineToDelete
put the selectedText of field "Field" into userToDelete
if userToDelete is not empty
then
answer "Delete" && userTodelete & "?" with "Yes" or "No"
if it is "Yes" then
deleteUser userToDelete
delete line lineToDelete of fld "Field"
end if
end if
end mouseUp
on deleteUser pUser
put the defaultfolder into tOldFolder -- save the current default folder
put specialfolderpath("documents") & "/" & pUser & "/" into tCurrentUserFolder
if there is a folder tCurrentUserFolder then
set the defaultfolder to tCurrentUserFolder -- point to the right place!
put the files into tFileList -- get the file list from the defaultfolder set from above.
repeat for each line tLine in tFileList
delete file tLine
end repeat
set the defaultfolder to tOldFolder -- revert to wherever we were pointing before
delete folder tCurrentUserFolder -- delete the user folder
put "" into field "FieldData"
end if
end deleteUser