Discussion Forums  >  Uncategorized

Replies: 20    Views: 449

shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
09/27/11 09:34 AM (14 years ago)

Shake for iOS

I have a BT app that is in the iTunes Store: http://itunes.apple.com/us/app/cigar-smoker/id465637692?mt=8 I would like to create a Magic 8-Ball Effect and looking for some suggestions on how to do this. I would like the user to be prompted to shake the phone which will initiate a random Cigar picture and phrase to come up. Thanks for the help in advance.
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
09/27/11 11:50 AM (14 years ago)
Hi. Here you have a link http://miniapps.co.uk/code/. You can make a HTML screen whit this JavaScript.
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/27/11 12:01 PM (14 years ago)
Great idea. I'll check it out. Not sure if I know how to implement this, but I'll give it a shot.
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/27/11 12:34 PM (14 years ago)
Mackimack - Thanks again for the site. I think I understand, but my lack of java skills are hindering me. Would you be able to assit on some code for the random image.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/27/11 06:54 PM (14 years ago)
I'd like to use this to randomly show an image too. If you are willing to share some code, mackimack, would you do it here so I can see as well? Thanks!
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/27/11 06:57 PM (14 years ago)
@basement - I found this and I think it may work for random images. http://www.computerhope.com/j18.htm Let me know how it works for you.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/27/11 07:00 PM (14 years ago)
Thanks. I like the idea of shaking the phone to change the image, will see if I can merge this with the previous link tomorrow!
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 05:55 AM (14 years ago)
I tried what I could find online, but it's not working. Can anyone take a looksee and let me know what I did wrong? http://b143apps.com/test/test.html (there's a syntax error on line 37, so I know I did something wrong, just don't know enough to find out what and fix it!) I'd also like to add an orientation lock on this page. thanks!
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/28/11 05:59 AM (14 years ago)
Just really quick looking at your code, I tried typing in the web address with your pics, and nothing came up. Perhaps double check the web address.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 06:00 AM (14 years ago)
works ok here. I see this when looking i my browser: Shake your iPhone/iPad to see a random image. NOTE: Requires iOS 4.2.1 and above and looking in code view I see the code ok. I'll try pasting here: <!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <meta name=viewport content=initial-scale=1.0, width=device-width, user-scalable=no /> <meta name=apple-mobile-web-app-capable content=yes /> <title>MiniApps - WKShake Plugin</title> <style type=text/css> body { background: #E9E9E9; color: #333; font: 1em/1.3em Helvetica Neue, Helvetica, Arial, Verdana, sans-serif; 16px / 21px */ text-shadow: rgba(255,255,255,0.8) 0 1px 0; text-align: center; } </style> <script type=text/javascript src=WKShake.js></script> </head> <body> <h3>Shake your iPhone/iPad to see a random image.</h3> <p><strong>NOTE:</strong> Requires iOS 4.2.1 and above</p> <script type=text/javascript> window.onload = function() { //create a new instance of WKShake. var myShakeEvent = new WKShake(); //start listening for shake event. //you can also use stop() to stop listening. myShakeEvent.start(); //define a custom method to fire when shake occurs. myShakeEvent.shakeEventDidOccur = function() { //put your own code here etc. (NSArray* theURLArray = [NSArray arrayWithObjects: @http://b143apps.com/test/im/file1.png, @http://b143apps.com/test/im/file2.png, @http://b143apps.com/test/im/file3.png, @http://b143apps.com/test/im/file4.png, @http://b143apps.com/test/im/file5.png, nil]; ... - (IBAction)showImage { NSInteger index = arc4random() % [theURLArray count]; NSString* thisURL = [theURLArray objectAtIndex: count]; theImageView.image= [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString: thisURL]]]; })) { } } }; </script> </body> </html>
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/28/11 06:02 AM (14 years ago)
Where are you pulling your images from, I type http://b143apps.com/test/im/file1.png for instance and get no page found. Maybe I'm missing something.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 06:05 AM (14 years ago)
no, I am missing my brain today! Ok, try now. I missed the file off the filename! Argh. I guess the page should open with a randomly chosen image, and then when you shake it, it changes to another randomly chosen image.
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/28/11 06:09 AM (14 years ago)
Ok, when i see the pic now when i type in the pic url. Good. When i go to your site on my phone I only see the test to shake the phone but it does not work. Do you have the .JS file on your server?
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
09/28/11 06:12 AM (14 years ago)
Hi guys. I have not had time to look at the code yet. but I tested your site basement. it does not work if I shake my phone?
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 06:22 AM (14 years ago)
I know. that's the problem. The original code comes up with an undo message when you shake it: http://b143apps.com/test/index.htm Here are the files in the test folder: im/ (folder) test.html WKShake.js index.html
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/28/11 06:26 AM (14 years ago)
Ok you have the correct file. I may be off on this, but the code for test.html I see an IBaction, not sure if that works in java script. I would just put the java code for a random image, the JS should handle the rest and activate evertime the phone shakes. I think the code I provided from the link above, should work, essentially shaking the phone is refreshing the page and pulling a random pic.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 06:39 AM (14 years ago)
when I use the script you supplied the link to on its own, it works (reloading the page gives you a random image): http://b143apps.com/test/test2.html but when I incorporate it into the shake script, it doesn't (I get a syntax error on line 46) http://b143apps.com/test/test.html If I move the javascript up to just below the </head> the image loads, but won't change when I shake the iphone. If I leave the javascript where the code says it should be, no image shows and I get the syntax error. ------------- <!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <meta name=viewport content=initial-scale=1.0, width=device-width, user-scalable=no /> <meta name=apple-mobile-web-app-capable content=yes /> <title>MiniApps - WKShake Plugin</title> <style type=text/css> body { background: #E9E9E9; color: #333; font: 1em/1.3em Helvetica Neue, Helvetica, Arial, Verdana, sans-serif; 16px / 21px */ text-shadow: rgba(255,255,255,0.8) 0 1px 0; text-align: center; } </style> <script type=text/javascript src=WKShake.js></script> </head> <body> <h3>Shake your iPhone/iPad to see a random image.</h3> <p><strong>NOTE:</strong> Requires iOS 4.2.1 and above</p> <script type=text/javascript> window.onload = function() { //create a new instance of WKShake. var myShakeEvent = new WKShake(); //start listening for shake event. //you can also use stop() to stop listening. myShakeEvent.start(); //define a custom method to fire when shake occurs. myShakeEvent.shakeEventDidOccur = function() { //put your own code here etc. <script type=text/javascript> //Javascript Created by Computerhope http://www.computerhope.com //store the quotations in arrays var images = [], index = 0; images[0] = <a href = 'http://www.b143apps.com'><img src='http://b143apps.com/test/im/file1.png' alt='image 1'></a>; images[1] = <a href = 'http://www.b143apps.com'><img src='http://b143apps.com/test/im/file2.png' alt='image 2'></a>; images[2] = <a href = 'http://www.b143apps.com'><img src='http://b143apps.com/test/im/file3.png' alt='image 3'></a>; images[3] = <a href = 'http://www.b143apps.com'><img src='http://b143apps.com/test/im/file4.png' alt='image 4'></a>; index = Math.floor(Math.random() * images.length); document.write(images[index]); //done </script> </body> </html>
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/28/11 06:43 AM (14 years ago)
I'm not getting any errors but not nothing happens.
 
basement
Aspiring developer
Profile
Posts: 488
Reg: Apr 07, 2011
Ontario
4,880
like
09/28/11 07:00 AM (14 years ago)
the syntax error is highlighted in dreamweaver. With http://b143apps.com/test/test2.html the images load randomly, just need to add the shake protocol to this and it'll be perfect. Adding the shake protocol to it the way it seems it should be added: http://b143apps.com/test/test.html removes the images and nothing is seen other than the heading. **confused**
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
09/29/11 06:57 PM (14 years ago)
I asked something similar awhile back about how to get back to the home screen by shaking the device. works perfectly. here's the thread: http://www.buzztouch.com/forum/thread.php?tid=C075D70763120E5C03C765F&status=&searchInput=shake&sortColumn=FT.dateStampUTC&sortUpDown=DESC¤tPage=1&doViews=1
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
12/02/13 01:37 PM (12 years ago)
For anyone looking for this functionality in a plugin.. https://www.buzztouch.com/plugins/plugin.php?pid=FAD3221726833083625AFA1 Might need a little editing to change things, like a dynamic screen, but the shake methods are there! Cheers! David https://buzztouchmods.com/market
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.