Skip to content

Commit

Permalink
[watchinsta] update to run on watchOS 3 (still watchOS 1-style app)
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed Sep 9, 2016
1 parent db22592 commit f528590
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 25 deletions.
12 changes: 10 additions & 2 deletions WatchInsta/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
WatchInsta (WatchKit)
WatchInsta (watchOS 1-style app)
==========

**Requires ClientID and RedirectUrl from [instagram.com/developer](https://www.instagram.com/developer/) added to the `Constants.cs` file.**

A simple Apple Watch Kit demo that:

* Logs into Instagram using OAuth (in the iPhone app), you must do this *before* running the watch app!
Expand All @@ -12,7 +14,7 @@ A simple Apple Watch Kit demo that:

This sample requires the following:

* [Xamarin Watch Kit preview](http://developer.xamarin.com/guides/ios/watch/).
* [Xamarin watchOS Support](http://developer.xamarin.com/guides/ios/watch/).

* [Xamarin.Auth component](http://components.xamarin.com/view/xamarin.auth) for OAuth support.

Expand All @@ -29,4 +31,10 @@ Using **App Groups** requires configuration in the [Apple iOS Provisioning site]
This is just a demonstration... a fully fledged Instagram integration would no doubt require more
robust image updating code, and a better first-run experience :)

##UPDATED watchOS 3

Updated to run on latest Instagram API and watchOS 3. Nnote that it is still build as a watchOS 1-style app with the Extension running on the iPhone.

![screenshot](Screenshots/watchinsta-OS3.png "watchOS 3")

*watch screenshots use [Bezel](http://infinitapps.com/bezel/) courtesy of [infinitapps](http://infinitapps.com/)* :)
Binary file added WatchInsta/Screenshots/watchinsta-OS3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions WatchInsta/WatchInsta/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
namespace WatchInsta
{
public static class InstagramConstants
{
// Find your Instagram API Client ID here
// https://www.instagram.com/developer/clients/manage/
// and Redirect URL in the "Security" tab
//
public static string ClientId = "YOU_NEED_YOUR_INSTAGRAM_DEV_CLIENTID_HERE";
public static string RedirectUrl = "http://conceptdevelopment.net/";
}
}
2 changes: 1 addition & 1 deletion WatchInsta/WatchInsta/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>WatchInsta</string>
<key>CFBundleIdentifier</key>
<string>com.conceptdevelopment.watchinsta</string>
<string>co.conceptdev.watchinsta</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
Expand Down
3 changes: 2 additions & 1 deletion WatchInsta/WatchInsta/WatchInsta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<HintPath>..\Components\xamarin.social-1.1.6\lib\ios-unified\Xamarin.Social.iOS.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -148,6 +148,7 @@
<DependentUpon>WatchInstaViewController.cs</DependentUpon>
</Compile>
<Compile Include="InstagramJson.cs" />
<Compile Include="Constants.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
16 changes: 7 additions & 9 deletions WatchInsta/WatchInsta/WatchInstaViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override void ViewDidAppear (bool animated)

var request = new OAuth2Request (
"GET",
new Uri ("https://api.instagram.com/v1/users/self/feed?access_token=" + token)
new Uri ("https://api.instagram.com/v1/users/self/media/recent/?access_token=" + token)
, null
, acct);//eventArgs.Account);

Expand All @@ -76,7 +76,7 @@ public override void ViewDidAppear (bool animated)
Console.WriteLine ("Error: " + t.Exception.InnerException.Message);
else {
string json = t.Result.GetResponseText ();
Console.WriteLine (json);
Console.WriteLine ("json: " + json);

var root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject> (json);

Expand Down Expand Up @@ -114,7 +114,7 @@ public override void ViewDidAppear (bool animated)
inst = root.data[i];
thumb = inst.images.thumbnail;
url = new Uri(thumb.url);
Console.WriteLine(inst.caption.text);
Console.WriteLine(inst.caption?.text);
Console.WriteLine(inst.images.thumbnail.url);

webClient.DownloadDataAsync(url);
Expand All @@ -140,10 +140,10 @@ public override void ViewDidAppear (bool animated)
// http://instagram.com/developer/clients/manage/
//
var auth = new OAuth2Authenticator (
clientId: "YOU_NEED_YOUR_INSTAGRAM_DEV_CLIENTID_HERE",
clientId: InstagramConstants.ClientId,
scope: "basic",
authorizeUrl: new Uri ("https://api.instagram.com/oauth/authorize/"),
redirectUrl: new Uri ("http://your-redirect-url.net/"));
redirectUrl: new Uri (InstagramConstants.RedirectUrl));

auth.Completed += (sender, eventArgs) => {
// We presented the UI, so it's up to us to dimiss it on iOS.
Expand All @@ -161,17 +161,15 @@ public override void ViewDidAppear (bool animated)





var request = new OAuth2Request ("GET",
new Uri ("https://api.instagram.com/v1/users/self/feed?access_token=" + token)
new Uri ("https://api.instagram.com/v1/users/self/media/recent/?access_token=" + token)
, null, acct);//eventArgs.Account);
request.GetResponseAsync ().ContinueWith (t => {
if (t.IsFaulted)
Console.WriteLine ("Error: " + t.Exception.InnerException.Message);
else {
string json = t.Result.GetResponseText ();
Console.WriteLine (json);
Console.WriteLine ("auth'd json: " + json);
}
});
} else {
Expand Down
6 changes: 3 additions & 3 deletions WatchInsta/WatchInsta/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="xamarinios10" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="xamarinios10" />
</packages>
8 changes: 4 additions & 4 deletions WatchInsta/WatchInstaExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>WatchInstaExtension</string>
<string>co.conceptdev.WatchInstaExtension</string>
<key>CFBundleIdentifier</key>
<string>com.conceptdevelopment.watchinsta.watchkitextension</string>
<string>co.conceptdev.watchinsta.watchkitextension</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.your-company.WatchInstaExtension</string>
<string>co.conceptdev.WatchInstaExtension</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
Expand All @@ -25,7 +25,7 @@
<key>NSExtensionAttributes</key>
<dict>
<key>WKAppBundleIdentifier</key>
<string>com.conceptdevelopment.watchinsta.watchkitapp</string>
<string>co.conceptdev.watchinsta.watchkitapp</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.watchkit</string>
Expand Down
2 changes: 1 addition & 1 deletion WatchInsta/WatchInstaExtension/InterfaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void WillActivate ()
image1.SetImage (image);
}

Console.WriteLine ("image should be loaded by now, attmept cache");
Console.WriteLine ("'" +lastImageFilename+"' image should be loaded by now, attmept cache");


var device = WKInterfaceDevice.CurrentDevice;
Expand Down
8 changes: 4 additions & 4 deletions WatchInsta/WatchInstaUI/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIdentifier</key>
<string>com.conceptdevelopment.watchinsta.watchkitapp</string>
<string>co.conceptdev.watchinsta.watchkitapp</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.your-company.WatchInstaUI</string>
<string>WatchInstaUI</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
Expand All @@ -24,13 +24,13 @@
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>WKCompanionAppBundleIdentifier</key>
<string>com.your-company.WatchInstaUI</string>
<string>co.conceptdev.watchinsta</string>
<key>WKWatchKitApp</key>
<true/>
<key>MinimumOSVersion</key>
<string>8.2</string>
<key>CFBundleDisplayName</key>
<string>Insta</string>
<string>WatchInstaUI</string>
<key>XSAppIconAssets</key>
<string>Images.xcassets/AppIcons.appiconset</string>
</dict>
Expand Down

0 comments on commit f528590

Please sign in to comment.