Author Topic: [discontinued] How to integrate iCloud support  (Read 9419 times)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
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.
« Last Edit: 2014-Sep-05 by Moru »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1622
  • Particle Hawk
    • View Profile
Re: How to integrate iCloud support
« Reply #1 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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
Re: How to integrate iCloud support
« Reply #2 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.
« Last Edit: 2012-Nov-01 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2795
    • View Profile
Re: How to integrate iCloud support
« Reply #3 on: 2012-Nov-01 »
Very nice indeed!  :good:

Small repeated line typo I the last listing BTW.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
Re: How to integrate iCloud support
« Reply #4 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
Re: How to integrate iCloud support
« Reply #5 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
Re: How to integrate iCloud support
« Reply #6 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
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.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4078
    • View Profile
    • Space Fractal
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

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: [discontinued] How to integrate iCloud support
« Reply #10 on: 2014-Sep-08 »
Locked :)
I came. I saw. I played.