【发布时间】:2010-12-18 05:18:46
【问题描述】:
我们可以在 iPhone 中以编程方式设置锁屏、壁纸和铃声吗?
如果是,那么请告诉我如何设置它们?
【问题讨论】:
-
+1 我在很多应用程序中都看到过。 stackoverflow.com/questions/15024361/…
标签: ios objective-c iphone ios4 iphone-privateapi
我们可以在 iPhone 中以编程方式设置锁屏、壁纸和铃声吗?
如果是,那么请告诉我如何设置它们?
【问题讨论】:
标签: ios objective-c iphone ios4 iphone-privateapi
这一切都可以轻松完成,但会被苹果拒绝。
可以通过更改com.apple.SpringBoard.plist,特别是ringtone 键来更改铃声。
以下代码可用于读取自定义铃声的实际铃声标题(由iTunes同步)。
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;
壁纸可以在以下位置覆盖:
NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
我的一个 Cydia 应用程序中使用了这些示例。他们并没有更多的东西,但这些应该会让你朝着正确的方向前进。
【讨论】:
由于 iOS 的变化,answer by WrightsCS 在某个时候停止工作。不幸的是,如果您希望使用未记录的功能,则必须忍受这一点。
如果您仍然需要这样做,仅适用于非 App Store 应用,此代码适用于 iOS 9.3。不过,它可能会在任何未来的 iOS 版本中停止工作。 (请参阅下面的评论:不再在 iOS 10 中工作)
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];
Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
您需要将私有 API 标头添加到您的项目中。您通常可以通过一些搜索在网上找到这些,for example, here。
在上面的示例中,[SBSUIWallpaperPreviewViewController setWallpaperForLocations:] 使用参数 3 进行调用:3 表示图像应该用于锁定屏幕和主屏幕。 1 表示仅锁定屏幕。 2 表示仅主屏幕。
关于我为什么动态地打开这个框架的解释,请参阅my related answer here。
我没有关于铃声的答案。这确实应该是一个单独的问题:完全不同的 API 在起作用。
【讨论】:
PLStaticWallpaperImageViewController中的类似方法,但也失败了。看起来 iOS 认识到该应用程序正在尝试更改其沙盒之外的某些内容。我还看到PhotoLibrary 中还有另一个 API,但我必须做一些逆向工程来弄清楚它需要的参数是什么。我会在这里及时更新。
如果可以,请使用私有 api
检查PLStaticWallpaperImageViewController
【讨论】: