Codesnippets > Inline / 3rd party

[discontinued] How to integrate iCloud support

(1/3) > >>

First at all here is how you can enable iCloud support:

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) ---#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;

--- End code ---

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) ---?IFDEF IPHONE
IMPORT "C" const char* iCloudURL()
LOCAL iCloud$=iCloudURL()
iCloud$=REPLACE$(iCloud$, "file://localhost/private", "")
IF LEN(iCloud$)>3

--- End code ---

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) ---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$
IF si>0
DEPRINT("SaveFile2$: "+si)
LoadStr(SaveFile2$, "all", 1)

--- End code ---

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.

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.

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.

Very nice indeed!  :good:

Small repeated line typo I the last listing BTW.

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.


[0] Message Index

[#] Next page

Go to full version