GLBasic forum

Codesnippets => Inline / 3rd party => Topic started by: spacefractal on 2012-Oct-30

Title: [discontinued] How to integrate iCloud support
Post by: spacefractal on 2012-Oct-30
First at all here is how you can enable iCloud support:
http://www.raywenderlich.com/6015/beginning-icloud-in-ios-5-tutorial-part-1

Howover I did got wawe of Entitlements issues,  but finally I got fixed that too. Here is the final Entitlements content I used, putted in maually in noteblok:

Code (glbasic) Select

#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSBundle.h>
#import <string.h>

char iString[512]="";

const char* iCloudURL()
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *bundleID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
NSLog(@"bundleID is: %@", bundleID);
NSString *appID = [NSString stringWithFormat:@"N3L62N3PZ4.%@", bundleID];
NSLog(@"appID is: %@", appID);
NSURL *testCloudURL = [fileManager URLForUbiquityContainerIdentifier:appID];
    if (testCloudURL==NULL)
        return iString;
NSString *myURL = [testCloudURL absoluteString];
    NSLog(@"testCloudURL is: %@", myURL);
    strcpy(iString, [myURL UTF8String]);
   
   
    return iString;
}



This will either return null or a url. The url is actuelly just a folder pointer , so there require no networking uploading and such. iOS doing that its self in a thread.

in GlBasic, you can check iCloud test doing something like this:

Code (glbasic) Select

?IFDEF IPHONE
IMPORT "C" const char* iCloudURL()
LOCAL iCloud$=iCloudURL()
iCloud$=REPLACE$(iCloud$, "file://localhost/private", "")
iCloud$=URLDECODE$(iCloud$);
IF LEN(iCloud$)>3
CLOUDFILE$=iCloud$+"Save.ini"
ENDIF
?ENDIF


Howover remember you can NOT access files directly from the iClould folder. If you doing that, then GlBasic will crash out by a GLB Error 3. But you can do a COPYFILE from AppData file to your iCloud folder before use, something like this for saving:

Code (glbasic) Select

FUNCTION LoadCloudStr: File$
DEPRINT("LoadCloudStr: "+File$)
LOCAL SaveFile2$=REPLACE$(SaveFile$, "save.ini", "save2.ini")
LOCAL SaveFile2$=REPLACE$(SaveFile$, "Save.ini", "Save2.ini")
COPYFILE File$, SaveFile2$
LOCAL si=GETFILESIZE(SaveFile2$)
IF si>0
DEPRINT("SaveFile2$: "+si)
LoadStr(SaveFile2$, "all", 1)
ENDIF
ENDFUNCTION


A Example for iCloud use:
I use iCloud for sync the game by the scoring and stars progress between devices. Its checking if the scoring and stars got is higher on the cloud file and then eventuelly update it. Also I read the cloud file when exiting a level, before sync back again to avoid eventeully confict.

Another example could been updating savegame from a light to paid version of the game. YES, using iCloud will been possible to share data between app if user have enabled iCloud.

This is extractly why I looked Dropbox, but I still do that in later day. Howover I did got iCloud working first.

PS. TEAMID and APPID is NOT the same. Remember to replace those with your own of course.
Title: Re: How to integrate iCloud support
Post by: Hemlos on 2012-Oct-31
Sticky! :good:
Accessing the apple icloud is always a bonus.
Seems very powerful, though i can not test this atm.

Note 'Codesnippets' may not be the final destination for this thread.
Perhaps it might belong in networking, inlines, or somewhere else.
Title: Re: How to integrate iCloud support
Post by: spacefractal on 2012-Nov-01
Fell free to move to inline/third party forum and sticky there.

I just want to see dropbox and/or iCloud support for more games to sync progress. It's very nice to see game play on my iPhone and later countinue on iPad without required to start over again.
Title: Re: How to integrate iCloud support
Post by: bigsofty on 2012-Nov-01
Very nice indeed!  :good:

Small repeated line typo I the last listing BTW.
Title: Re: How to integrate iCloud support
Post by: spacefractal on 2013-Aug-30
today (yes long time ago im posted in thist thread), im fixed red warnings, which might happens in a newer xcode (missing IMPORT commands). So im hope this iCoud still works and hope people use this to save thier game.
Title: Re: How to integrate iCloud support
Post by: spacefractal on 2014-Sep-05
This sticky thread is old and is no longer work due file permission bugs in ios7. So I'm dedicated this to been out and hence the thread can been unsticky.

Instead I'm later create a new thread when I'm looking how the key value database work, which seen more easier.
Title: Re: How to integrate iCloud support
Post by: spacefractal on 2014-Sep-05
this thread can now been locked. That due im will soon later this week give source code how to get iCloud to work again.

Its is no longer possible to use files, but im found a way to get and put strings to iCloud instead. Its only contains 4 functions and is straight away. So im will create a new thread about that and how to get that to work. Its also pretty more simple when code signing first works.

So im wont support iCloud Files anymore.
Title: Re: [discontinued] How to integrate iCloud support
Post by: Moru on 2014-Sep-05
I don't like locking threads but I changed the name. You can also edit your first post and write that this no longer works/isn't supported.
Title: Re: [discontinued] How to integrate iCloud support
Post by: spacefractal on 2014-Sep-05
im got the new iCloud system working using Get() and Put() Strings. So im will just create a new thread later this or next week. That why.

Actuelly its is much easier supporting iCloud this way, even there impose some limits (number of keys and size of them). Its should not been a issue with games like those we create.

The hard part is get the code signing to work. When that is working, rest is straight away.
Title: Re: [discontinued] How to integrate iCloud support
Post by: spacefractal on 2014-Sep-08
Now im want this thread safe to been lock now, because im wont want users to wrote in this thread at all with old code. The reason is this one works much better and easier by using keystore instead of files:
http://www.glbasic.com/forum/index.php?topic=10017.0

Title: Re: [discontinued] How to integrate iCloud support
Post by: Ian Price on 2014-Sep-08
Locked :)